-
Notifications
You must be signed in to change notification settings - Fork 7
/
create_hu_report_map.py
executable file
·136 lines (107 loc) · 3.58 KB
/
create_hu_report_map.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
135
136
#!/usr/bin/python
import json
import sys
import os
import subprocess as sp
import csv
suff_a = []
insuff_a = []
suff = {}
insuff = {}
#fp = open("out-data/ge-suff.tsv")
#k=0
#for line in fp:
# line = line.strip()
# suff_a.append(line)
# suff[line] = k
# k+=1
#fp.close
with open("out-data/ge-suff.tsv") as fp:
r = csv.reader(fp, delimiter="\t")
for row in r:
str_id = row[0].strip()
json_line = row[1].strip()
suff_a.append(json_line)
suff[json_line] = str_id
#fp = open("out-data/ge-insuff.tsv")
#k=0
#for line in fp:
# line = line.strip()
# insuff_a.append(line)
# insuff[line] = k
# k += 1
#fp.close()
with open("out-data/ge-insuff.tsv") as fp:
r = csv.reader(fp, delimiter="\t")
for row in r:
str_id = row[0].strip()
json_line = row[1].strip()
insuff_a.append(json_line.strip())
insuff[json_line] = str_id
suff_ofp_raw = open("out-data/ge-suff-hu-map.tsv", "w")
insuff_ofp_raw = open("out-data/ge-insuff-hu-map.tsv", "w")
#hu_rep_ofp_raw = open("out-data/human-report-map.tsv", "w")
suff_ofp = csv.writer(suff_ofp_raw, delimiter="\t", lineterminator="\n")
insuff_ofp = csv.writer(insuff_ofp_raw, delimiter="\t", lineterminator="\n")
#hu_rep_ofp = csv.writer(hu_rep_ofp_raw, delimiter="\t", lineterminator="\n")
hu_rep_map = {}
hu_rep_ind = 0
#suff_ofp.write("human_id\tlocator\tcsvlist\n")
#insuff_ofp.write("human_id\tlocator\tcsvlist\n")
#suff_ofp.write("human_report_id\tcsvlist\n")
#insuff_ofp.write("human_report_id\tcsvlist\n")
#hu_rep_ofp.write("id\thuman_id\tlocator\n")
INCLUDE_HEADER=False
if INCLUDE_HEADER:
suff_ofp.writerow(["human_report_id", "csvlist"])
insuff_ofp.writerow(["human_report_id","csvlist"])
#hu_rep_ofp.writerow(["id","human_id","locator"])
fp = open("json_reports.list")
for line in fp:
line = line.strip()
print line
z = line.split('/')
#zz = z[2].split('-')
t = z[2].split(':')
uploaded_data_id = t[0]
# hu_rep_key = z[1] + "\t" + zz[1]
# cur_rep_ind = -1
# if hu_rep_key not in hu_rep_map:
# cur_rep_ind = hu_rep_ind
# hu_rep_map[hu_rep_key] = hu_rep_ind
# #hu_rep_ofp.write(str(hu_rep_ind) + "\t" + str(hu_rep_key) + "\n")
# hu_rep_ofp.writerow([str(hu_rep_ind), str(z[1]), str(zz[1])])
# hu_rep_ind+=1
# else:
# cur_rep_ind = hu_rep_map[hu_rep_key]
suff_list=[]
insuff_list=[]
line = line.strip()
p = sp.Popen("jq -c '.variants.suff[] | [ .variant_impact, .allele_freq, .autoscore, .clinical, .evidence, .name , .suff_eval, .variant_impact, .zygosity, .expect_effect ]' " + line + " 2> /dev/null", shell=True, stdout=sp.PIPE)
for c in iter(p.stdout.readline, ''):
c = c.strip()
if c in suff:
suff_list.append( str(suff[c]) )
else:
print "ERROR", c, "not found"
sys.exit()
p = sp.Popen("jq -c '.variants.insuff[] | [ .variant_impact, .allele_freq, .autoscore, .clinical, .evidence, .name , .suff_eval, .variant_impact, .zygosity, .expect_effect ]' " + line + " 2> /dev/null", shell=True, stdout=sp.PIPE)
for c in iter(p.stdout.readline, ''):
c = c.strip()
if c in insuff:
insuff_list.append( str(insuff[c]) )
else:
print "ERROR", c, "not found"
sys.exit()
for ind in suff_list:
#suff_ofp.write( str(cur_rep_ind) + "\t" + str(ind) + "\n" )
#suff_ofp.writerow([str(cur_rep_ind), str(ind)])
suff_ofp.writerow([str(uploaded_data_id), str(ind)])
for ind in insuff_list:
#insuff_ofp.write( str(cur_rep_ind) + "\t" + str(ind) + "\n" )
#insuff_ofp.writerow([str(cur_rep_ind), str(ind)])
insuff_ofp.writerow([str(uploaded_data_id), str(ind)])
fp.close()
suff_ofp_raw.close()
insuff_ofp_raw.close()
#hu_rep_ofp_raw.close()