Exception handling and continuing with a for loop in python -
i have following code:
import bio bioservices import keggparser, uniprot, quickgo #start new method of custom 'retrieve_data' class def locate_common_go(self,list_of_genes,go_term): #initialize variables , classes q = quickgo() = retrieve_data() b=[]
get uniprot ids using (custom method) hugo2uniprot
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])
search go terms (using bioservices quickgo) , store dictionary
go_dict = {} q = quickgo()
some of large list of gene names have not return hits. these cause attributeerror want handle move on next item in list. current code returns error: attributeerror: 'int' object has no attribute 'split'. error originates within bioservices module (so when i'm calling q.annotation...)
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 code irrelevant problem i've included completeness: #essentially designed locate specific keywords in results of above code , return gene name came from. keys = go_dict.keys() matches = [] gene in range(0,len(keys)): if go_term in go_dict[keys[gene]].splitlines(): matches.append(keys[gene]) return matches
does have suggestions exception handling working finishes iterating on specified list instead of halting script?
okay i've realized problem error coming different bit of code... trying handle nothing. i've fixed now, responded.
Comments
Post a Comment