Skip to content

Commit 8adf9bc

Browse files
JbJb
Jb
authored and
Jb
committed
Added python script
1 parent 23ba652 commit 8adf9bc

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,6 @@ dmypy.json
121121

122122
# Pyre type checker
123123
.pyre/
124+
125+
# OSX stuff
126+
*.DS_Store

volcano_plot/volcano_plot.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
3+
### Script to produce volcano plots in plotly
4+
5+
import numpy as np
6+
import pandas as pd
7+
import plotly.graph_objects as go
8+
9+
#define significant fc and p-val thresholds
10+
p_thresh = 0.001
11+
fc_thresh = 3
12+
13+
#helper function to assign color based on significance
14+
def is_significant(fc, p_val):
15+
if p_val < p_thresh:
16+
if fc > fc_thresh:
17+
return 'red'
18+
if fc < -1*fc_thresh:
19+
return 'blue'
20+
return 'gray'
21+
22+
23+
24+
if __name__ == '__main__':
25+
26+
#import data
27+
df = pd.read_csv("volcano_data.txt", sep="\t")
28+
29+
#assign colour based on significance
30+
color = df.apply(lambda x: is_significant(x["logFC"],x['adj.P.Val']), axis= 1)
31+
32+
#draw plot
33+
data=go.Scatter(
34+
x= df['logFC'],
35+
y= -1*np.log10(df['adj.P.Val']),
36+
text= df['SYMBOL'],
37+
hoverinfo='text',
38+
mode='markers',
39+
marker=dict(
40+
color=color)
41+
)
42+
43+
shapes=[
44+
# Line Horizontal
45+
go.layout.Shape(
46+
type="line",
47+
xref="paper",
48+
x0=0,
49+
y0=-1*np.log10(p_thresh),
50+
x1=1,
51+
y1=-1*np.log10(p_thresh),
52+
line=dict(
53+
color="gray",
54+
width=1,
55+
dash="dash")
56+
),
57+
# Line Vertical
58+
go.layout.Shape(
59+
type="line",
60+
yref="paper",
61+
x0=-1*fc_thresh,
62+
y0=0,
63+
x1=-1*fc_thresh,
64+
y1=1,
65+
line=dict(
66+
color="gray",
67+
width=1,
68+
dash="dash"
69+
)
70+
),
71+
# Line Vertical
72+
go.layout.Shape(
73+
type="line",
74+
yref="paper",
75+
x0=fc_thresh,
76+
y0=0,
77+
x1=fc_thresh,
78+
y1=1,
79+
line=dict(
80+
color="gray",
81+
width=1,
82+
dash="dash"
83+
)
84+
)]
85+
86+
layout= go.Layout(title="Volcano plot",
87+
xaxis = dict(title= "Log2(fold change)",
88+
range= [-1*max(abs(df['logFC'])), max(abs(df['logFC']))]),
89+
yaxis = dict(title= "-Log10(adj. p-value)"),
90+
shapes = shapes,
91+
paper_bgcolor='rgba(0,0,0,0)',
92+
plot_bgcolor='rgba(0,0,0,0)'
93+
)
94+
95+
fig = go.Figure(data=data, layout= layout)
96+
fig.show(renderer="browser")

0 commit comments

Comments
 (0)