[BioPython] NCBI: from protein to CDS

Iddo Friedberg idoerg at burnham.org
Fri Apr 11 17:53:01 EDT 2003


So while we have Andrew's rapt(?) attention, here is a question:

What am I doing wrong? I am trying to efetch a sequence as gb, using a 
gb ID. Works good for a FASTA fromat, but I think I am not persing it 
correctly for GenBank.

Help?

Thanks,

Iddo
-------------------  CUT HERE ----------------------------


#!/usr/bin/python2.2
import sys
from time import sleep
from EUtils import DBIds, DBIdsClient
from Bio import GenBank
from Bio.GenBank import LocationParser
from Bio.SeqIO import FASTA

# Get the sequence as FASTA - works OK
h = DBIdsClient.from_dbids(DBIds(db = "nucleotide",
                            ids = ["12083602"]))

infile = h.efetch(retmode = "text", rettype = "fasta")
fasta_seq = FASTA.FastaReader(infile).next()

FASTA.FastaWriter(sys.stdout).write(fasta_seq)
sleep(2) # NCBI directive: you don't want to mess with them

# Get the same sequence as genbank - no go.
#h = DBIdsClient.from_dbids(DBIds(db = "nucleotide",
#                          ids = ["12083602"]))

infile = h.efetch(retmode = "text", rettype = "gb")
# The following causes an error!
genpept_rec = GenBank.Iterator(infile, GenBank.FeatureParser()).next()
print genpept_rec


---------------------------------------------------------------------------




Traceback (most recent call last):
   File "./try_genbank.py", line 23, in ?
     genpept_rec = GenBank.Iterator(infile, GenBank.FeatureParser()).next()
   File "/usr/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 
183, in next
     return self._parser.parse(File.StringHandle(data))
   File "/usr/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 
268, in parse
     self._scanner.feed(handle, self._consumer)
   File "/usr/lib/python2.2/site-packages/Bio/GenBank/__init__.py", line 
1255, in feed
     self._parser.parseFile(handle)
   File "/usr/lib/python2.2/site-packages/Martel/Parser.py", line 338, 
in parseFile
     self.parseString(fileobj.read())
   File "/usr/lib/python2.2/site-packages/Martel/Parser.py", line 366, 
in parseString
     self._err_handler.fatalError(result)
   File "//usr/lib/python2.2/xml/sax/handler.py", line 38, in fatalError
     raise exception
Martel.Parser.ParserPositionException: error parsing at or beyond 
character 2424





------------------------------------- CUT HERE -------------------------





Andrew Dalke wrote:
> Jeff:
>  > Ha!  It flushed Andrew out of the woodwork.  This week's award for 
> most valuable
>  > python contributor goes to Jason!  :)
> 
> I confess.  I couldn't let working perl code just sit there on the 
> biopython
> list.
> 
> :)
> 
>                     Andrew
> 
> _______________________________________________
> BioPython mailing list  -  BioPython at biopython.org
> http://biopython.org/mailman/listinfo/biopython
> 
> 

-- 
Iddo Friedberg, Ph.D.
The Burnham Institute
10901 N. Torrey Pines Rd.
La Jolla, CA 92037
USA
Tel: +1 (858) 646 3100 x3516
Fax: +1 (858) 646 3171
http://bioinformatics.ljcrf.edu/~iddo



More information about the BioPython mailing list