[Biopython] Read sequence from file

Horea Chrristian h.chr at mail.ru
Fri Feb 27 04:42:45 UTC 2015


Many thanks, 

from Bio.Seq import Seq
from Bio.Alphabet import generic_dna
with open("my_example.txt") as handle:
    my_seq = Seq(handle.read().strip(), generic_dna)

solves it just fine. I would want one sequence regardless the line
breaks, but that is not relly that important. What do you mean by "Right
now" - will this likely change soon?

Chhers,

On Mit, 2015-02-25 at 17:39 +0000, Peter Cock wrote:

> On Wed, Feb 25, 2015 at 4:03 PM, Horea Chrristian <h.chr at mail.ru> wrote:
> > Hi guys, how can I read a sequence from a .txt file which contains only a
> > string of letters (nucleotides)? I tried `SeqIO.read("my/file","...")` but
> > if my second value is fasta or genbank, it complains about missing handles,
> > and nothing like "plain", "string", or "str" worked... What can I do? It
> > would be nice if I can do this via a one-liner rather than just read it
> > explicitly with python and then explicitly parse it.
> >
> > Cheers,
> 
> Right now you'd just do something like this:
> 
> with open("my_example.txt") as handle:
>     my_seq_as_string = handle.read().strip()
> 
> Or, if you want a Seq object with eg DNA alphabet,
> 
> from Bio.Seq import Seq
> from Bio.Alphabet import generic_dna
> with open("my_example.txt") as handle:
>     my_seq = Seq(handle.read().strip(), generic_dna)
> 
> I'm assuming there are no line breaks or other whitespace etc.
> 
> What you are asking for sounds a bit like adding what EMBOSS calls
> the "raw" file format to Biopython's SeqIO:
> http://emboss.sourceforge.net/docs/themes/SequenceFormats.html
> 
> If this was added, what would you expect as the record's identifier?
> 
> Also would you expect one sequence regardless of any line breaks in the
> file - or one sequence per line?
> 
> Peter


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20150227/6dbc266c/attachment.html>


More information about the Biopython mailing list