首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >异常处理,并在python中继续使用for循环

异常处理,并在python中继续使用for循环
EN

Stack Overflow用户
提问于 2014-11-13 15:56:50
回答 1查看 252关注 0票数 2

我有以下代码:

代码语言:javascript
复制
import Bio
from bioservices import KEGGParser, UniProt, QuickGO

#start a new method of my custom 'Retrieve_Data' class
def locate_common_GO(self,list_of_genes,GO_term):
    
    #initialize variables and classes
    q = QuickGO()
    a = Retrieve_Data()
    b=[]

使用(自定义方法) hugo2uniprot获取uniprot

代码语言:javascript
复制
for i in range(0,len(list_of_genes)):
    b.append(a.hugo2uniprot(list_of_genes[i],'hsa'))
    print 'Gene: {} \t UniProtID: {}'.format(list_of_genes[i],b[i])

搜索GO术语(使用bioservicesQuickGO)并存储为字典

代码语言:javascript
复制
GO_dict = {}
q = QuickGO()

一些大的基因名称,我没有返回任何点击。这些导致了我想要处理的AttributeError,然后转到列表中的下一项。当前代码返回错误:

AttributeError:'int‘对象没有属性’拆分‘。

错误起源于bioservices模块(所以当我调用q.Annotation时)

代码语言:javascript
复制
for i in range(len(b)):
    try:
        GO_dict[list_of_genes[i]] = q.Annotation(protein=b[i], frmt="tsv", _with=True,tax=9606, source="UniProt", col="goName")
    except AttributeError:
        continue

# The rest of this code is irrelevant to my problem but I've included it for completeness: 
# Essentially it is designed to locate specific keywords in the results of the above code and return the gene name that they came from. 
keys = GO_dict.keys()
matches = []
for gene in range(0,len(keys)):
    if GO_term in GO_dict[keys[gene]].splitlines():
        matches.append(keys[gene])
return matches

有没有人建议让异常处理工作,这样它就可以完成对指定列表的迭代,而不是停止脚本?

EN

回答 1

Stack Overflow用户

发布于 2014-11-13 16:31:32

好吧,我刚刚意识到问题是错误来自不同的代码.所以我基本上什么都没处理。我现在已经修好了,多亏了所有的回应。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26912999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档