-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_metadata_table.py
33 lines (30 loc) · 1.18 KB
/
write_metadata_table.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
import argparse
import csv
import glob
from Records import ProteinRecord
def write_metadata_summary(records, table_out):
with open(table_out, 'w') as handle:
writer = csv.writer(handle)
header = ["accession","database","protein_name","enzyme_type","organism_name","organism_category","reviewed"]
writer.writerow(header)
for record in records:
row = []
for attribute in header:
value = getattr(record, attribute)
row.append(value)
writer.writerow(row)
def main(json_dir,table_out):
json_files = glob.glob(json_dir+"/*.json")
records=[]
for json_file in json_files:
record = ProteinRecord.from_json(json_file)
records.append(record)
write_metadata_summary(records, table_out)
if __name__ == "__main__":
#Argument parsing
parser = argparse.ArgumentParser()
parser.add_argument("json_dir", type=str, help="Path to directory with json files")
parser.add_argument("table_out", type=str, help="Path to output table in .csv format")
args = parser.parse_args()
#Run the main script
main(args.json_dir, args.table_out)