<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"><<a href="mailto:ivangreg@gmail.com" target="_blank">ivangreg@gmail.com</a>></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: 'generator' object has no attribute 'peekline'<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>
<<a href="mailto:cjfields@illinois.edu">cjfields@illinois.edu</a>> wrote:<br>
> On Jun 24, 2014, at 11:54 AM, Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com">p.j.a.cock@googlemail.com</a>> wrote:<br>
><br>
>> Hi Ivan,<br>
>><br>
>> Biopython's SeqIO does not (and will not) do automatic file<br>
>> format detection, it is just too hard to get right so instead<br>
>> that's the user's task:<br>
>><br>
>> Zen of Python: Explicit is better than implicit.<br>
>> <a href="http://legacy.python.org/dev/peps/pep-0020/" target="_blank">http://legacy.python.org/dev/peps/pep-0020/</a><br>
>><br>
>> (BioPerl's SeqIO can do format guessing)<br>
><br>
> (somewhat)<br>
><br>
> 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>
><br>
> 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>
><br>
>> Your use case is one which highlights a technical reason<br>
>> why this is hard - you are using stdin, a read-once handle.<br>
>> You cannot peek at the file, guess the format, seek back to<br>
>> the beginning, and then give the handle to a specific parser.<br>
>><br>
>> You could use Biopython's UndoHandle here, but it will<br>
>> impose a (modest) performance overhead.<br>
>><br>
>> from Bio.File import UndoHandle<br>
>> help(UndoHandle)<br>
>><br>
>> e.g. Use the .peekline() method to spot FASTA vs FASTQ?<br>
>><br>
>> Peter<br>
><br>
> That seems like a pretty reasonable option.<br>
><br>
> chris<br>
><br>
>> On Tue, Jun 24, 2014 at 5:16 PM, Ivan Gregoretti <<a href="mailto:ivangreg@gmail.com">ivangreg@gmail.com</a>> wrote:<br>
>>> Hello Biopythoneers,<br>
>>><br>
>>> The question:<br>
>>><br>
>>> What is the strategy currently used for file format autodetection?<br>
>>><br>
>>><br>
>>> The context:<br>
>>><br>
>>> I have written a command line program that gets a stream of FASTQ data<br>
>>> and reports how many records are contained. You can visualise it like<br>
>>> this<br>
>>><br>
>>> zcat myfile.fq.gz | fxcounttags.py -i /dev/stdin -o /dev/stdout > myfile.counts<br>
>>><br>
>>> That works fine for FASTQ but I need to extend the functionality to<br>
>>> FASTA streams. How would you write fxcounttags.py to detect<br>
>>> FASTQ/FASTA?<br>
>>><br>
>>> Thank you,<br>
>>><br>
>>> Ivan<br>
>>><br>
>>><br>
>>><br>
>>> Ivan Gregoretti, PhD<br>
>>> Bioinformatics<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><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><br>
><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>