0

我刚刚开始使用 Python 和 BioPython,没有太多的编程经验。我很感激你们能给我的任何帮助。

我正在尝试从 genbank 中提取 CDS 和/或 rRNA 序列。重要的是我只得到开放阅读框,这就是为什么我不只是拉出整个序列。当我运行下面的代码时,它会返回一条错误消息:

在句柄中找不到记录

对于如下代码行:record = SeqIO.read(handle, "genbank"). 我不知道如何纠正这个问题。我在下面包含了我正在使用的代码。

另外,如果有更简单的方法或发布代码,如果你们让我知道,我将不胜感激。

谢谢!

# search sequences by a combination of keywords
# need to find (number of) results to set 'retmax' value
handle = Entrez.esearch(db = searchdb, term = searchterm)
records = Entrez.read(handle)
handle.close()
# repeat search with appropriate 'retmax' value
all_handle = Entrez.esearch(db = searchdb, term = searchterm, retmax = records['Count'])
records = Entrez.read(all_handle)

print " "
print "Number of sequences found:", records['Count'] #printing to make sure that code is working thus far. 
print " "

locations = [] # store locations of target sequences
sequences = [] # store target sequences

for i in range(0,int(records['Count'])) :
    handle = Entrez.efetch(db = searchdb, id = records['IdList'][i], rettype = "gb", retmode = "xml") 
    record = SeqIO.read(handle, "genbank")
    for feature in record.features:
        if feature.type==searchfeaturetype: #searches features for proper feature type
            if searchgeneproduct in feature.qualifiers['product'][0]: #searches features for proper gene product
                if str(feature.qualifiers) not in locations: # no repeat location entries
                    locations.append(str(feature.location)) # appends location entry
                    sequences.append(feature.extract(record.seq)) # append sequence
4

1 回答 1

1

当您期望格式为 genbank 平面文件格式时,您正在向xmlgenbank请求。SeqIO.read尝试将您的efetch行更改为:

handle = Entrez.efetch(db = searchdb, id = records['IdList'][i], rettype = "gb", retmode = "txt") 
于 2014-03-25T18:02:36.063 回答