This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I print and write the strain /isolate/voucher number of a SeqRecord objec in biopython?

I would like to print and write (in fasta) the strain /isolate/voucher number of multiple DNA sequences parsed in biopython (and also organism name and sequence). However, although this information (strain/isolate/voucher) is within feature-qualifiers (genbank format), this information is not extracted with atributes annotation and features of a seqrecord object.

Does anyone know how can I do this?

I'm a newbie with python, so any tip would be very helpful.

Thanks

below there is part of a gb file as an example.

[...]
FEATURES             Location/Qualifiers
     source          1..841
                     /organism="Amauroderma calcitum"
                     /mol_type="genomic DNA"
                     /**isolate**="FLOR50931"
                     /db_xref="taxon:1774182"
                     /country="Brazil"
                     /collection_date="07-Jan-2013"
                     /collected_by="D.H. Costa-Rezende"
     rRNA            <1..>841
                     /product="large subunit ribosomal RNA"
[...]
biopython dna number strain sequence

Please provide your current code used for parsing.

Hi Sej Thanks for your reply. The code is below:

from Bio import SeqIO
import sys
print(sys.argv[0])
arquivodeentrada = sys.argv[1]
arquivodesaida = sys.argv[2]

sequences=SeqIO.parse(arquivodeentrada,'genbank')

f=open(arquivodesaida,'w')

for seq in sequences:
    acesso=seq.name
    gensp=seq.annotations['organism'].split(' ')
    sequencia=seq.seq
    f.write(str('>'+gensp[0]+'_'+gensp[1]+'_'+acesso+'\n'))
    print(gensp[0]+'_'+gensp[1]+'_'+acesso)
    f.write(str(sequencia+'\n'))
    print(sequencia)

f.close()

1 answer

The isolate is a qualifier of the source feature that you can access like so:

from Bio import SeqIO
from pprint import pprint

# Read genbank file
for rec in SeqIO.parse("genome.gb", "genbank"):
    source = rec.features[0]
    pprint(source.qualifiers)

will print:

OrderedDict([('organism', ['Amauroderma calcitum']),
             ('mol_type', ['genomic DNA']),
             ('isolate', ['FLOR 50931']),
             ('db_xref', ['taxon:1774182']),
             ('country', ['Brazil']),
             ('collection_date', ['07-Jan-2013']),
             ('collected_by', ['D.H. Costa-Rezende'])])

alternatively, IMHO, the simplest way to get this info is with bio

bio fetch KU315207 | bio json > data.json

now you have a json file that can be immediately materialized in your program, no GenBank parsing needed anymore

Thank you very much for your help Istvan! First option worked fine for me.

Log in to answer this question.