[Biopython] Needs some NCBI recommendation

Michiel de Hoon mjldehoon at yahoo.com
Sun Jan 3 14:44:04 UTC 2010


--- On Sun, 1/3/10, lueck at ipk-gatersleben.de <lueck at ipk-gatersleben.de> wrote:
> In addition I want to ask, whether it's reasonable to use
> the efecth in a simple for statement
> 
> id_list = ["19304878", "18606172"]
> for i in id_list:
>    handle = Entrez.efetch(db="nucleotide", id=i, rettype="fasta")
>    print handle.read()
> 
> since I need only the raw GenBank or FASTA files?

The following needs only one call to efetch:

>>> from Bio import Entrez
>>> Entrez.email = "lueck at ipk-gatersleben.de"
>>> from Bio import SeqIO
>>> handle = Entrez.efetch(db='nucleotide', id="19304878,18606172", rettype='fasta')
>>> records = SeqIO.parse(handle, 'fasta')
>>> for record in records:
...     words = record.id.split("|")
...     i = words[1]
...     output = open(i+".fa", 'w')
...     SeqIO.write([record], output, 'fasta')
...     output.close()


--Michiel


      




More information about the Biopython mailing list