[Biopython] Helpa Newbie Please.py
Peter
biopython at maubp.freeserve.co.uk
Mon Jun 7 04:39:50 EDT 2010
On Mon, Jun 7, 2010 at 12:36 AM, Willis, Jordan R
<jordan.r.willis at vanderbilt.edu> wrote:
> Hi Gary,
>
> Python will always look for the file in whichever directory you started
> python in. I would go to the command line and start python in the same
> directory in which you have ls_orchid.gbk.
>
> On another note, I'm not sure when this changed but SeqIO.parse
> will only accept a file object contrary to the example. So try this.
If using Biopython 1.54 or later, you can use a filename or handle.
http://news.open-bio.org/news/2010/04/biopython-seqio-and-alignio-easier/
If using Biopython 1.53 or older, you need a handle (file object)
as in Jordan's example:
> from Bio import SeqIO
> for seq_record in SeqIO.parse(open("ls_orchid.gbk"), "genbank"):
> print seq_record.id
> print repr(seq_record.seq)
> print len(seq_record)
Gary - If you don't have the file in your current working directory, it
might be simplest to give a full path, for example:
from Bio import SeqIO
filename = r"C:\My Documents\new work\ls_orchid.gbk""
for seq_record in SeqIO.parse(filename, "genbank"):
print seq_record.id
print repr(seq_record.seq)
print len(seq_record)
When defining the filename, using r"text" with a leading r means
a raw string. This means \n or \t etc won't be treated as a newline
or a tab which is what Python does normally - something to beware
of as Windows uses \ in paths.
Peter
More information about the Biopython
mailing list