Skip to content

Instantly share code, notes, and snippets.

@jsstevenson
Last active March 3, 2025 14:47
Show Gist options
  • Select an option

  • Save jsstevenson/c7df4acae54b47a1f356c072cc23b1d0 to your computer and use it in GitHub Desktop.

Select an option

Save jsstevenson/c7df4acae54b47a1f356c072cc23b1d0 to your computer and use it in GitHub Desktop.

get DictReader for interactions TSV:

import csv
with open("~/Downloads/interactions.tsv") as f:
    next(f)  # skip header rows
    next(f)
    lines = list(csv.DictReader(f, delimiter="\t"))

get unique gene concept IDs:

gene_ids = {line['gene_concept_id'] for line in lines}
gene_ids = gene_ids - {''}  # drop null case

get # of unique gene concept IDs:

print(len(gene_ids))
#  5026

save to file:

with open("gene_concept_ids.txt", "w") as f:
    for gene_id in gene_ids:
        f.write(gene_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment