-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_expected.py
executable file
·134 lines (121 loc) · 2.99 KB
/
plot_expected.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
import argparse
import lib.parse_matrix as pm
from plotly.io import write_image
import plotly.graph_objs as go
parser = argparse.ArgumentParser(
description = 'Plot distance regressions'
)
parser.add_argument('-i', required = True, help = 'Input expected values')
parser.add_argument('-p', required = True, help = 'Output figure prefix')
args = parser.parse_args()
expected = pm.matrix_to_diagonal(
pm.import_sparse_matrix(args.i, diagonal = True)
)
resolution = str(expected['resolution'] // 1000) + 'k'
comments = '<br>'.join(expected['comments'])
for chromosome, bins in expected['bins'].items():
entries = expected['entries']
if not type(entries[chromosome][0]) == list:
entries[chromosome] = [entries[chromosome]]
max_x = (len(entries[chromosome][0]) + 2) * expected['resolution']
max_y = (max([v for e in entries[chromosome] for v in e]) * 16)/15
layout = go.Layout(
margin = go.layout.Margin(
l = 150,
r = 300,
b = 2200,
t = 150
),
showlegend = False,
annotations = [
dict(
text = 'resolution: ' + resolution + '<br>'
+ 'chromosome: ' + chromosome + '<br>' + comments,
font = dict(
family = 'Open Sans Condensed',
size = 27
),
align = 'left',
showarrow = False,
x = 0,
y = 0,
yshift = -100,
xanchor = 'left',
yanchor = 'top',
),
dict(
text = 'Genomic distance',
font = dict(
family = 'Open Sans Condensed',
size = 27
),
align = 'left',
showarrow = False,
x = max_x,
y = 0,
xref = 'x',
yref = 'y',
xshift = 20,
xanchor = 'left',
yanchor = 'bottom',
),
dict(
text = 'Expected<br>interaction proportion',
font = dict(
family = 'Open Sans Condensed',
size = 27
),
align = 'center',
showarrow = False,
x = 0,
y = max_y,
xref = 'x',
yref = 'y',
yshift = 20,
xanchor = 'center',
yanchor = 'bottom',
)
],
xaxis = dict(
domain = [0, 0],
range = [0, max_x],
ticklen = 8,
tickfont = dict(
family = 'Open Sans Condensed',
size = 19
),
),
yaxis = dict(
domain = [0, 0],
range = [0, max_y],
ticklen = 8,
tickfont = dict(
family = 'Open Sans Condensed',
size = 19
),
)
)
data = [
go.Scatter(
x = [
i * expected['resolution']
for i in range(0, len(entries[chromosome][0]))
],
y = e,
mode = 'lines',
line = dict(
width = 2,
color = 'rgb(190, 20, 60)'
),
xaxis = 'x',
yaxis = 'y',
) for e in entries[chromosome]
]
figure = go.Figure(data = data, layout = layout)
write_image(
figure,
args.p + '_' + resolution + '_chr' + chromosome + '.png',
width = 2480,
height = 3508
)