Created
September 14, 2017 15:17
-
-
Save ewels/3233339ae9726695f691c2273bdcfd2f to your computer and use it in GitHub Desktop.
Convert Nextflow Trace text file to JSON format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Convert Nextflow text file to JSON format | |
import json | |
headers = [] | |
data = {'trace': []} | |
with open ('NGI-RNAseq_trace.txt') as fh: | |
for l in fh: | |
s = l.split("\t") | |
if len(headers) == 0: | |
headers = s | |
else: | |
d = {} | |
for i, v in enumerate(s): | |
try: | |
d[headers[i]] = float(v) | |
except ValueError: | |
d[headers[i]] = v | |
data['trace'].append(d) | |
print(json.dumps(data, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment