-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
executable file
·45 lines (34 loc) · 1.32 KB
/
display.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
#! /usr/bin/env python
import sys
import argparse
import csv
import json
import pprint
dccs = ["KFDRC", "SPARC", "ERCC_DCC", "HMP", "4DN_DCIC", "GTEx", "IDG", "LINCS", "MW", "GlyGen", "HuBMAP"]
def main():
p = argparse.ArgumentParser()
p.add_argument('input_json', help='output of c2m2_cv_usage.py')
p.add_argument('-o', '--output-file', required=True, help='output CSV')
args = p.parse_args()
with open(args.input_json, "rt") as fp:
data = json.load(fp)
output_fp = open(args.output_file, "w", newline="")
csv_w = csv.writer(output_fp)
header = ["rownum", "format_type", "label", "record_type"] + dccs
csv_w.writerow(header)
# unpack the input JSON
n = 0
for record_type, all_dcc_dict in data.items():
for format_type, dcc_matches in all_dcc_dict.items():
label = dcc_matches['_name']
row = [ n + 1, format_type, label, record_type ]
# add all of the DCC avlues for num_biosamples
for dcc_name in dccs:
dcc_values = dcc_matches.get(dcc_name,{})
num_biosamples = dcc_values.get("num_biosamples", 0)
row.append(num_biosamples)
csv_w.writerow(row)
n += 1
print(f"Wrote {n} rows.", file=sys.stderr)
if __name__ == '__main__':
sys.exit(main())