-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvisualize.py
More file actions
81 lines (42 loc) · 1.45 KB
/
visualize.py
File metadata and controls
81 lines (42 loc) · 1.45 KB
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
import os ,sys
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def slice(bedfile,name, score_file):
if not os.path.exists(name):
os.mkdir(name)
coords = []
with open(bedfile,'r') as infile:
lines = infile.readlines()
for l in lines:
fields = l.split()
info = (fields[1],fields[2],fields[4],fields[5])
coords.append(info)
scores =[]
with open(score_file,'r') as infile:
scores = infile.readlines()
for el in coords:
print(el)
start = int(el[0])
end = int(el[1])
mid1 = int(el[2])
mid2 = int(el[3])
bounds =[start,mid1,mid2,end-1]
print(bounds)
slice =name+"/"+el[0]+"-"+el[1]+".png"
curr = scores[start:end]
x = [int(l.split(',')[0]) for l in curr]
y = [int(l.split(',')[1]) for l in curr]
d = {"idx":x, "score":y}
df = pd.DataFrame(d,index = d["idx"])
graph = df.plot(x = "idx", y = "score")
#f,ax = plt.subplots(1)
graph.plot(bounds,[0.0]*len(bounds),"rv")
fig = graph.get_figure()
#plt.plot( bounds, marker = "v", markerfacecolor ="r")
fig.savefig(slice)
if __name__ == "__main__":
chrom = sys.argv[1]
output_dir = sys.argv[2]
score_file = sys.argv[3]
slice(chrom,output_dir,score_file)