-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircles.py
68 lines (61 loc) · 2.18 KB
/
circles.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
from math import log
from matplotlib import pyplot
def get_circle(chromosome):
circle = Gcircle()
N = len(chromosome)
circle.add_garc(Garc(arc_id="chromosome", size=N, interspace=0, linewidth=0, facecolor="#ffffffff"))
circle.set_garcs()
return circle
def add_inserts(circle, inserts, rmin, rmax, colour):
circle.scatterplot(
"chromosome",
data = [i.sstrand for i in inserts],
positions = [i.sstart for i in inserts],
markersize=20,
rlim=(-1, 1),
facecolor=colour,
raxis_range=(rmin, rmax),
markershape="X"
)
return circle
def add_rna_seq(circle, chromosome, genes, rmin, rmax):
v, p, w = [], [], []
for gene in genes:
try:
g, t, _ = chromosome[gene.qualifiers["locus_tag"][0]]
v.append(log(t + 1) * gene.location.strand)
p.append(g.location.start)
w.append(g.location.end - g.location.start)
except KeyError:
pass
circle.barplot("chromosome", data=v, positions=p, width=w, base_value=0, raxis_range=(rmin, rmax))
return circle
def add_heatmap(circle, data, rmin, rmax):
resolution = 5000
n = len(data)
positions = [i * resolution for i in range(n)]
circle.heatmap(
"chromosome",
data=data,
positions=positions,
width=resolution,
raxis_range=(rmin, rmax),
vmin=min(data),
vmax=max(data),
cmap=pyplot.cm.viridis
)
return circle
def add_hic_ref(circle, chromosome, reference):
matrix = chromosome.hic
temps = numpy.log2(numpy.add(matrix[reference, :], 1))
temps[reference] = 1.0
n = len(temps)
positions = [i * 5000 for i in range(0, n)]
circle.heatmap("chromosome", data=temps, positions=positions, width=5000, raxis_range=(700, 750), vmin=min(temps), vmax=max(temps), cmap=pyplot.cm.viridis)
return circle
def add_hic(circle, chromosome):
temps = chromosome.openness
n = len(temps)
positions = [i * 5000 for i in range(0, n)]
circle.heatmap("chromosome", data=temps, positions=positions, width=5000, raxis_range=(700, 750), vmin=min(temps), vmax=max(temps), cmap=pyplot.cm.viridis)
return circle