Created
October 24, 2024 04:34
-
-
Save alexpreynolds/8e48a969dd17ee6c340b5e3d8e6813d8 to your computer and use it in GitHub Desktop.
Convert Gencode GFF3 to GeneSearch widget JSON
This file contains 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 | |
import sys | |
import json | |
genes = [] | |
for line in sys.stdin: | |
elems = line.rstrip().split('\t') | |
chromosome = elems[0] | |
start = int(elems[3]) | |
end = int(elems[4]) | |
length = end - start | |
md = elems[8].split(';') | |
hgnc = list(filter(lambda x: x.startswith('gene_name='), md))[0].split('=')[1] | |
type = list(filter(lambda x: x.startswith('gene_type='), md))[0].split('=')[1] | |
posneg = elems[6] | |
gene = { | |
'chromosome': chromosome, | |
'start': start, | |
'end': end, | |
'length': length, | |
'hgnc': hgnc, | |
'type': type, | |
'posneg': posneg | |
} | |
genes.append(gene) | |
sys.stdout.write(json.dumps(genes, separators=(',', ':'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From text GFF3:
Or from compressed records:
Or from the web: