<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 24, 2014 at 2:00 PM, Ivan Gregoretti <span dir="ltr">&lt;<a href="mailto:ivangreg@gmail.com" target="_blank">ivangreg@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Indeed, the STDIN stream is the challenge. That is why I though that<br>
the question was worth documenting in the Biopython list.<br>
<br>
Would anybody mind showing how peekline() is used? I tried using it on<br>
a SeqIO.parse generator but I get an error:<br>
<br>
AttributeError: &#39;generator&#39; object has no attribute &#39;peekline&#39;<br></blockquote><div><br></div><div>peekline() is a method of UndoHandle, not the generator.<br><br></div><div>Cheers,<br><br>Lenna<br><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I am using Biopython 1.61 and Python 2.7.3 on linux 64bit.<br>
<div class="im HOEnZb"><br>
Thank you,<br>
<br>
Ivan<br>
<br>
<br>
<br>
<br>
Ivan Gregoretti, PhD<br>
Bioinformatics<br>
<br>
<br>
</div><div class="HOEnZb"><div class="h5">On Tue, Jun 24, 2014 at 1:41 PM, Fields, Christopher J<br>
&lt;<a href="mailto:cjfields@illinois.edu">cjfields@illinois.edu</a>&gt; wrote:<br>
&gt; On Jun 24, 2014, at 11:54 AM, Peter Cock &lt;<a href="mailto:p.j.a.cock@googlemail.com">p.j.a.cock@googlemail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Hi Ivan,<br>
&gt;&gt;<br>
&gt;&gt; Biopython&#39;s SeqIO does not (and will not) do automatic file<br>
&gt;&gt; format detection, it is just too hard to get right so instead<br>
&gt;&gt; that&#39;s the user&#39;s task:<br>
&gt;&gt;<br>
&gt;&gt; Zen of Python: Explicit is better than implicit.<br>
&gt;&gt; <a href="http://legacy.python.org/dev/peps/pep-0020/" target="_blank">http://legacy.python.org/dev/peps/pep-0020/</a><br>
&gt;&gt;<br>
&gt;&gt; (BioPerl&#39;s SeqIO can do format guessing)<br>
&gt;<br>
&gt; (somewhat)<br>
&gt;<br>
&gt; You are welcome to try it, but Bio::Tools::GuessSeqFormat is IMHO one of the misbegotten step-children of Bioperl; if you delve into it, you’ll find it also tries to guess whether something is a sequence or an alignment file.  My general feeling is that if you don’t know the source of your data (and from that the format) then there is only so much we can do to help.  Doing so from STDIN is even trickier.<br>

&gt;<br>
&gt; So, it’s there, it works in most cases so we keep it around, but caveat emptor.  We really don’t really maintain that module any more than very routine bugs fixes.<br>
&gt;<br>
&gt;&gt; Your use case is one which highlights a technical reason<br>
&gt;&gt; why this is hard - you are using stdin, a read-once handle.<br>
&gt;&gt; You cannot peek at the file, guess the format, seek back to<br>
&gt;&gt; the beginning, and then give the handle to a specific parser.<br>
&gt;&gt;<br>
&gt;&gt; You could use Biopython&#39;s UndoHandle here, but it will<br>
&gt;&gt; impose a (modest) performance overhead.<br>
&gt;&gt;<br>
&gt;&gt; from Bio.File import UndoHandle<br>
&gt;&gt; help(UndoHandle)<br>
&gt;&gt;<br>
&gt;&gt; e.g. Use the .peekline() method to spot FASTA vs FASTQ?<br>
&gt;&gt;<br>
&gt;&gt; Peter<br>
&gt;<br>
&gt; That seems like a pretty reasonable option.<br>
&gt;<br>
&gt; chris<br>
&gt;<br>
&gt;&gt; On Tue, Jun 24, 2014 at 5:16 PM, Ivan Gregoretti &lt;<a href="mailto:ivangreg@gmail.com">ivangreg@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; Hello Biopythoneers,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The question:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; What is the strategy currently used for file format autodetection?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The context:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I have written a command line program that gets a stream of FASTQ data<br>
&gt;&gt;&gt; and reports how many records are contained. You can visualise it like<br>
&gt;&gt;&gt; this<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; zcat myfile.fq.gz | fxcounttags.py -i /dev/stdin -o /dev/stdout &gt; myfile.counts<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; That works fine for FASTQ but I need to extend the functionality to<br>
&gt;&gt;&gt; FASTA streams. How would you write fxcounttags.py to detect<br>
&gt;&gt;&gt; FASTQ/FASTA?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thank you,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Ivan<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Ivan Gregoretti, PhD<br>
&gt;&gt;&gt; Bioinformatics<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org">Biopython@mailman.open-bio.org</a><br>
&gt;&gt;&gt; <a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">http://mailman.open-bio.org/mailman/listinfo/biopython</a><br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org">Biopython@mailman.open-bio.org</a><br>
&gt;&gt; <a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">http://mailman.open-bio.org/mailman/listinfo/biopython</a><br>
&gt;<br>
<br>
_______________________________________________<br>
Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org">Biopython@mailman.open-bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">http://mailman.open-bio.org/mailman/listinfo/biopython</a></div></div></blockquote></div><br></div></div>