Hi, I have trouble to down and save sequences from ncbi at one time. I get accession numbers using script:
from Bio import Entrez
def singleEntry(singleID): #the singleID is the accession number
handle = Entrez.efetch(db='nucleotide',id=singleID, rettype = 'fasta', retmode= 'text')
f = open('%s.fasta' % singleID, 'w')
f.write(handle.read())
handle.close()
f.close()
#get an id list: this makes a big search and gets a list of id
handle = Entrez.esearch(db='nucleotide', term = ["Poaceae[Orgn] AND als[Gene]"])
record = Entrez.read(handle)
handle.close()
print (record["IdList"])
I got IdList:
['1124779319', '1058275694', '160346987', '160346985', '313662298', '313662296', '313662294', '313662292', '148536620', '148536618', '944203885', '937553934', '698322664', '698322662', '698322660', '698322658', '683428019', '677285963', '677285961', '677285959']
Then, how to download those fasta sequences to one file? Thanks. I tried this:
from Bio import Entrez, SeqIO
def get_sequences(IdList):
ids = record["IdList"]
for seq_id in ids:
handle = Entrez.efetch(db="nucleotide", id="seq_id", rettype="fasta", retmode="text")
record = handle.read()
record = open('als.fasta', 'w')
record.write(record.rstrip('\n'))
but it showed: IndentationError: expected an indented block
hi, did you solve this?, i need to do the same