[BioPython] Getting the location from a Genbank record

Sebastian Bassi sbassi at gmail.com
Sun Sep 2 23:25:22 EDT 2007


I can get the "location" of the genes I want, but I have them in a
"print mode" (calling __str__), but I don't see how to get the start
and end position in a way I could use to slice the seq. There are
private attributes _start and _end but I don't know if using them if
the "right" way to do it.

from Bio import SeqIO
mr = SeqIO.parse(open("MTtabaco.gbk"), "genbank").next()
targets=(['cox2'],['atp6'],['atp9'],['cob'])
for x in mr.features:
        if x.qualifiers.get('gene') in targets:
            print x.location
            #print mr.seq

Get the slice I am looking for:

>>> mr.seq[x.location._start.position:x.location._end.position]
Seq('ATGAATGTTATAACTCCTAATTCTTTGGTAGCGGACCTCTTTGATAGTTCGACCCTTATCCCCCGTCTAACTCAACTATTCGACTGTACGGCTATTGTGATTGCGAGAGAAAGGAGGGATGGCGCCTTCCTTTACCATCTGGCGGTTGAAAACAAAAGTGCTTCCAGGTACACGGCTGTTAGGCTCATCCAAGGCGTATTTACGGAAGTAGCAGGGAACTTGACCGTCAAGTTTGAAAAAAGCTGGCCAAGCCTGTGTCACTTTCTTACGTCAGGAGAAAGGGAGATCAAAGAAGTATGGGGCCGATACGCGAAGGATCAAATCATAGAGATAGCGGATCTTAAGAGGCGGAAGAAAAGGAACCTCGGCGACCCAGAGATCGCGGAGTCCGCGCCCGTGCCGAAAGTGAAGAAGCTTTCCTCTCCTTTCAGTCGAGCATGCCCGCCCTTTAGCACTTCCCTTCCCGAAGTGGGAGTAGGAGAAAGGAAAGCGCACTCGATCAATTACCATGCCGTGTCGTAA',
IUPACAmbiguousDNA())



-- 
Bioinformatics news: http://www.bioinformatica.info
Lriser: http://www.linspire.com/lraiser_success.php?serial=318


More information about the BioPython mailing list