Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ewels
Created September 14, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewels/3233339ae9726695f691c2273bdcfd2f to your computer and use it in GitHub Desktop.
Save ewels/3233339ae9726695f691c2273bdcfd2f to your computer and use it in GitHub Desktop.
Convert Nextflow Trace text file to JSON format
#!/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