Hi all,

I have list of pubchem Compound names and want to retreive pubchem Ids from NCBI Pubchem database using NCBI eutilities to acheive that i wrote biopython script as follows

from Bio import Entrez
Entrez.email = "ni@gmail.com"
#Input names 
infile = open("file1", "r")
out_put = open("file2.csv","w")
for line in infile.readlines():
  single_id = line
  #Post list of names to database
  handle= Entrez.epost("pccompound",id=single_id)
  record = Entrez.read(handle)
  #history
  webEnv=record["WebEnv"]
  queryKey=record["QueryKey"]
  #Retreiving information
  data = Entrez.esummary(db="pccompound",webenv=webEnv,query_key=queryKey)
  res=Entrez.read(data)
  for compound in res:  
    Name = compound["SynonymList"]
    Cid = compound["Id"]
    print "%s:%s" %(Name,Cid)
    out_put.write("%s:%s\n" %(Name,Cid))
out_put.close()

but i shows following error

Traceback (most recent call last):                                                                                                          
  File "compundids.py", line 13, in<module>                                                                                              
record = Entrez.read(handle)                                                                                                          
  File "/usr/lib/pymodules/python2.6/Bio/Entrez/__init__.py", line 258, in read                                                             
    record = handler.read(handle)                                                                                                           
  File "/usr/lib/pymodules/python2.6/Bio/Entrez/Parser.py", line 108, in read                                                               
    self.parser.ParseFile(handle)                                                                                                           
  File "/usr/lib/pymodules/python2.6/Bio/Entrez/Parser.py", line 218, in endElementHandler                                                  
    raise RuntimeError(value)                                                                                                               
RuntimeError: Empty ID list; Nothing to store 

I want output as follows

Compoud names     pubchem Id
BETULIN           72326
OBTUSAQUINONE     6377243  
.
.
 .
.

Can any body tell me where i going wrong..

Thanks in advance
Ni

Edited 4 Years Ago by pyTony: code tag police

Traceback (most recent call last):
File "compundids.py", line 13, in<module>
record = Entrez.read(handle)

There is something wrong with the read. Does your input file have any empty records? Add a print statement to print "line" before the error to see which record is causing this.

Edited 4 Years Ago by woooee

This article has been dead for over six months. Start a new discussion instead.