This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Get Collections Of Reads From Genbank

I have found some reads that I want to download.

They begin at http://www.ncbi.nlm.nih.gov/nuccore/DQ569913 and end at http://www.ncbi.nlm.nih.gov/nuccore/DQ601958

I could get them one by one, but as there are 32000 of them it seems a tad time consuming. Does anyone know how to download the sequences DQ569913 to 601958 automatically?

Thanks

genbank

search biostars.org for EUtilities / EFetch .

1 answer

This sloppy Biopython code does the trick:

# -*- coding: utf-8 -*-                                                                           from Bio import Entrez
Entrez.email = "use@your.real.email.addy.yo"
with open("human_pirna.fa", "w+") as output_file:
    for i in range(569913,601959):
        handle = Entrez.efetch(db="nuccore", id="DQ{0}".format(i), rettype="gb", retmode="text")
        entry = handle.read()
        pirna_string = entry.split("ORIGIN")[1].split("1")[1].split("//")[0].replace(" ", "")
        output_file.write(">DQ{0}\n".format(i))
        print pirna_string
        output_file.write(pirna_string)

Log in to answer this question.