<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/4.8.5">
</HEAD>
<BODY>
Many thanks, <BR>
<BR>
from Bio.Seq import Seq<BR>
from Bio.Alphabet import generic_dna<BR>
with open("my_example.txt") as handle:<BR>
my_seq = Seq(handle.read().strip(), generic_dna)<BR>
<BR>
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?<BR>
<BR>
Chhers,<BR>
<BR>
On Mit, 2015-02-25 at 17:39 +0000, Peter Cock wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
On Wed, Feb 25, 2015 at 4:03 PM, Horea Chrristian <<A HREF="mailto:h.chr@mail.ru">h.chr@mail.ru</A>> wrote:
<FONT COLOR="#737373">> Hi guys, how can I read a sequence from a .txt file which contains only a</FONT>
<FONT COLOR="#737373">> string of letters (nucleotides)? I tried `SeqIO.read("my/file","...")` but</FONT>
<FONT COLOR="#737373">> if my second value is fasta or genbank, it complains about missing handles,</FONT>
<FONT COLOR="#737373">> and nothing like "plain", "string", or "str" worked... What can I do? It</FONT>
<FONT COLOR="#737373">> would be nice if I can do this via a one-liner rather than just read it</FONT>
<FONT COLOR="#737373">> explicitly with python and then explicitly parse it.</FONT>
<FONT COLOR="#737373">></FONT>
<FONT COLOR="#737373">> Cheers,</FONT>
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:
<A HREF="http://emboss.sourceforge.net/docs/themes/SequenceFormats.html">http://emboss.sourceforge.net/docs/themes/SequenceFormats.html</A>
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
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>