[BioPython] problem with GenBank.NCBIDictionary ?

Catherine Letondal letondal@pasteur.fr
Tue, 28 May 2002 18:25:32 +0200


Jeffrey Chang wrote:
> It looks like GenBank is expecting to get genbank ID's rather than
> accession numbers.  Using your code, if I look for the ID:
>     gb_rec = gb_dict['1617401']
> I get the gene back with accession X98475.
> 
> I'll have to look more closely into retrieving by accession number.
> 
> Jeff
> 

Thanks for your help, it worked.

I have another problem, when I want to get a GenBank.Record instead of just a string.
I think it's more with the parsers.


If I change the parser to be either the GenBank.RecordParser or the GenBank.FeatureParser
as shown in the tutorial, I get a Martel error message.
>>> record_parser = GenBank.FeatureParser()
>>> ncbi_dict = GenBank.NCBIDictionary(parser = record_parser)
>>> record = ncbi_dict['1617401']
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 1555, in __getitem__
    return self.parser.parse(handle)
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 268, in parse
    self._scanner.feed(handle, self._consumer)
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 1250, in feed
    self._parser.parseFile(handle)
  File "/local/lib/python2.2/site-packages/Martel/Parser.py", line 230, in parseFile
    self.parseString(fileobj.read())
  File "/local/lib/python2.2/site-packages/Martel/Parser.py", line 258, in parseString
    self._err_handler.fatalError(result)
  File "/local/lib/python2.2/xml/sax/handler.py", line 38, in fatalError
    raise exception
Martel.Parser.ParserPositionException: error parsing at or beyond character 55

Same with the GenBank.RecordParser:

>>> record_parser = GenBank.RecordParser()
>>> ncbi_dict = GenBank.NCBIDictionary(parser = record_parser)
>>> record = ncbi_dict['1617401']
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 1555, in __getitem__
    return self.parser.parse(handle)
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 289, in parse
    self._scanner.feed(handle, self._consumer)
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 1250, in feed
    self._parser.parseFile(handle)
  File "/local/lib/python2.2/site-packages/Martel/Parser.py", line 230, in parseFile
    self.parseString(fileobj.read())
  File "/local/lib/python2.2/site-packages/Martel/Parser.py", line 258, in parseString
    self._err_handler.fatalError(result)
  File "/local/lib/python2.2/xml/sax/handler.py", line 38, in fatalError
    raise exception
Martel.Parser.ParserPositionException: error parsing at or beyond character 55

It's actually the same when I try to feed the parser with a local file:

def get_filegbrec(file):
    handle = open(file)
    gb = GenBank.Iterator(handle, GenBank.RecordParser())
    record = gb.next()
    handle.close()
    return record

>>> get_filegbrec('data/M13699.gb')    
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 4, in get_filegbrec
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 183, in next
    return self._parser.parse(File.StringHandle(data))
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 289, in parse
    self._scanner.feed(handle, self._consumer)
  File "/local/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 1250, in feed
    self._parser.parseFile(handle)
  File "/local/lib/python2.2/site-packages/Martel/Parser.py", line 230, in parseFile
    self.parseString(fileobj.read())
  File "/local/lib/python2.2/site-packages/Martel/Parser.py", line 258, in parseString
    self._err_handler.fatalError(result)
  File "/local/lib/python2.2/xml/sax/handler.py", line 38, in fatalError
    raise exception
Martel.Parser.ParserPositionException: error parsing at or beyond character 55


Could someone help?
Thanks a lot!


--
Catherine Letondal -- Pasteur Institute Computing Center