Biopython for Loop IndexError
Biopython for Loop IndexError
当我输入此代码时,我得到 "IndexError: list is out of range"。此外,retmax 设置为 614,因为这是我发出请求时的结果总数。有没有办法使用根据搜索结果而变化的变量使 retmode 等于结果数?
#!/usr/bin/env python
from Bio import Entrez
Entrez.email = "something@gmail.com"
handle1 = Entrez.esearch(db = "nucleotide", term = "dengue full genome", retmax = 614)
record = Entrez.read(handle1)
IdNums = [int(i) for i in record['IdList']]
while i >= 0 and i <= len(IdNums):
handle2 = Entrez.esearch(db = "nucleotide", id = IdNums[i], type = "gb", retmode = "text")
record = Entrez.read(handle2)
print(record)
i += 1
除了使用 while 循环,您还可以使用 for 循环...
from Bio import Entrez
Entrez.email = 'youremailaddress'
handle1 = Entrez.esearch(db = 'nucleotide', term = 'dengue full genome', retmax = 614)
record = Entrez.read(handle1)
IdNums = [int(i) for i in record['IdList']]
for i in IdNums:
print(i)
handle2 = Entrez.esearch(db = 'nucleotide', term = 'dengue full genome', id = i, rettype = 'gb', retmode = 'text')
record = Entrez.read(handle2)
print(record)
我 运行 它在我的电脑上,它似乎可以工作。 for循环解决了越界,将term加入handle2解决了调用错误。
当我输入此代码时,我得到 "IndexError: list is out of range"。此外,retmax 设置为 614,因为这是我发出请求时的结果总数。有没有办法使用根据搜索结果而变化的变量使 retmode 等于结果数?
#!/usr/bin/env python
from Bio import Entrez
Entrez.email = "something@gmail.com"
handle1 = Entrez.esearch(db = "nucleotide", term = "dengue full genome", retmax = 614)
record = Entrez.read(handle1)
IdNums = [int(i) for i in record['IdList']]
while i >= 0 and i <= len(IdNums):
handle2 = Entrez.esearch(db = "nucleotide", id = IdNums[i], type = "gb", retmode = "text")
record = Entrez.read(handle2)
print(record)
i += 1
除了使用 while 循环,您还可以使用 for 循环...
from Bio import Entrez
Entrez.email = 'youremailaddress'
handle1 = Entrez.esearch(db = 'nucleotide', term = 'dengue full genome', retmax = 614)
record = Entrez.read(handle1)
IdNums = [int(i) for i in record['IdList']]
for i in IdNums:
print(i)
handle2 = Entrez.esearch(db = 'nucleotide', term = 'dengue full genome', id = i, rettype = 'gb', retmode = 'text')
record = Entrez.read(handle2)
print(record)
我 运行 它在我的电脑上,它似乎可以工作。 for循环解决了越界,将term加入handle2解决了调用错误。