Last active
August 29, 2015 14:00
-
-
Save daler/11400223 to your computer and use it in GitHub Desktop.
infer GTF genes, for biostars #99287
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
import gffutils | |
# Import the GTF file into a sqlite3 database. | |
# This only ever has to be done once. | |
db = gffutils.create_db("example.gtf", dbfn='example.gtf.db') | |
# In other scripts, you can connect to the database like this: | |
db = gffutils.FeatureDB('example.gtf.db') | |
# Note that gene and transcript have been inferred | |
print list(db.featuretypes()) | |
# ['CDS', 'exon', 'gene', 'start_codon', 'stop_codon', 'transcript'] | |
# Here's how to write genes out to file | |
with open('example_genes.gtf', 'w') as fout: | |
for gene in db.features_of_type('gene'): | |
fout.write(str(gene) + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment