-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-civicpy-data.py
53 lines (50 loc) · 1.69 KB
/
get-civicpy-data.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
from civicpy import civic
import sys
annotated_mps = list()
molecular_profiles = civic.get_all_molecular_profiles(include_status=["accepted", "submitted"])
for n, mp in enumerate(molecular_profiles):
# if n > 10:
# break
ev_counts = {
"accepted": 0,
"submitted": 0
}
for ev in mp.evidence_items:
if ev.status in {"accepted", "submitted"}:
ev_counts[ev.status] += 1
is_and = False
# print(gq_mp)
for parsed_name in mp.parsed_name:
if parsed_name.type == 'molecular_profile_text_segment':
if parsed_name.text == 'OR':
is_and = False
elif parsed_name.text == 'AND':
is_and = True
else:
print('Unrecognized token text: ' + parsed_name.text, file=sys.stderr)
break
if is_and:
continue
for variant in mp.variants:
chrom = None
start = None
ref = None
alt = None
coordinates = variant.coordinates
# molecular_profile_id = variant.single_variant_molecular_profile
chrom, start, ref, alt = coordinates.chromosome, coordinates.start, coordinates.reference_bases, coordinates.variant_bases
if not (ref and alt):
continue
annotated_mps.append({
"chrom": chrom,
"start": start,
"ref": ref,
"alt": alt,
"mp_id": mp.id,
"variant_ids": mp.variant_ids,
"molecular_profile_score": mp.molecular_profile_score,
"num_acc_eids": ev_counts["accepted"],
"num_sub_eids": ev_counts["submitted"],
})
import json
print(json.dumps(annotated_mps, indent=4))