Skip to content

Instantly share code, notes, and snippets.

@aofarrel
Created May 11, 2023 03:08
Show Gist options
  • Select an option

  • Save aofarrel/6206913f620e8a1ebea17f3ec0d3d087 to your computer and use it in GitHub Desktop.

Select an option

Save aofarrel/6206913f620e8a1ebea17f3ec0d3d087 to your computer and use it in GitHub Desktop.
import os
import json
lazy_array_of_strings_to_write = []
for file in os.listdir("rand12344"):
if file.endswith(".json"):
sample = file.rstrip("._to_Ref.H37Rv.bam.results.json")
with open(f"rand12344/{file}") as thisjson:
data = json.load(thisjson)
strain = data["sublin"]
lazy_array_of_strings_to_write.append(f"{sample}\t{strain}\n")
with open("strains_from_jsons.tsv", "w") as outfile:
for thingy in lazy_array_of_strings_to_write:
outfile.write(thingy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment