[Biopython] Entrez.efetch
Olumide Olufuwa
olumideolufuwa at yahoo.com
Mon Apr 19 07:30:24 UTC 2010
Hello there,
I wrote a program, I am not awesome in biopython but this is what it does: The program code that
accepts user defined UNIPROT ID, retrieves the record using Entrez.efetch and then it
is parsed to obtain the Pubmed ID which i use to search Medline for Title, Abstract and other information about the entry.
The code is simply:
query_id=str(raw_input("please
enter your UNIPROT_ID: ")) #Request UNIPROT ID from user
Entrez.email="ludax5 at yahoo.com"
prothandle=Entrez.efetch(db="protein",
id=query_id, rettype="gb" #queries Protein DB with the given ID
#The
program returns an error here if a wrong ID is given. Details of the
error is given below
seq_record=SeqIO.read(prothandle, "gb")
for
record in seq_record.annotations['references']: # To obtain Pubmed id
from the seqrecord
key_word=record.pubmed_id
if key_word:
handle=Entrez.efetch(db="pubmed",
id=key_word, rettype="medline")
medRecords=Medline.parse(handle)
for rec in medRecords: #prints
title and Abstract
if rec.has_key('AB') and
rec.has_key('TI'):
print "TITLE: ",rec['TI']
print "ABSTRACT: ",rec['AB']
print ' '
THE
PROBLEM: The program gives an error if a wrong ID is entered or an ID
other than UNIPROT ID e.g PDB ID, GSS ID etc.
An Example Run with a wrong ID is shown below:
please enter your UNIPROT_ID:
1wio #A PDB ID is given instead
Traceback (most recent call last):
File "file.py", line 11, in
<module>
seq_record=SeqIO.read(prothandle, "gb")
File
"/usr/lib/python2.5/site-packages/Bio/SeqIO/__init__.py", line 522, in
read
raise ValueError("No records found in handle")
ValueError:
No records found in handle
I want to avoid this error, thus i
want the program to print "INCORRECT ID GIVEN" when a wrong or an
incorrect ID is given.
Thanks a lot.
lummy
More information about the Biopython
mailing list