forked from theiagen/public_health_viral_genomics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep_json.py
executable file
·31 lines (28 loc) · 1.05 KB
/
prep_json.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
#!/usr/bin/env python3
import sys
def reformat(inputfile):
with open(inputfile, 'r') as infile:
sample_dict = {}
for line in infile:
columns = line.strip().split()
samplename = columns[0]
deidentified = columns[1]
collection = columns[2]
leftread = columns[3]
rightread = columns[4]
# json_line = f'{"left":{"{samplename}","{deidentified}","{collection}}","right":{"left": "{leftread}", "right": "{rightread}"}}'
json_line = ' {"left": ["' + samplename + '","' + deidentified + '","' + collection +'"],\n "right": {\n "left": "' + leftread + '",\n "right": "' + rightread + '"}}'
sample_dict[samplename] = json_line
outfile = open('input_samples.json', 'w')
outstring = '{"refbased_viral_assembly.inputSamples": [\n'
for samplename,sampleinfo in sample_dict.items():
# print(f'{sampleinfo},')
# outfile.write(f'{sampleinfo},\n')
outstring += f'{sampleinfo},\n'
outstring = outstring[:-2]
outstring += '\n ]\n}'
outfile.write(outstring)
infile.close()
outfile.close()
infile = sys.argv[1]
reformat(infile)