[Bioperl-l] perl one-liner with Bio::SeqIO

Chris Fields cjfields at illinois.edu
Thu Jul 22 18:35:51 UTC 2010


It's fairly easy to check if something is seekable, using tell() (from perldoc -f tell):

tell() on pipes, fifos, and sockets usually returns -1.  

My guess is this is something that should be really be handled by Bio::Root::IO, then SeqIO could check this:

if (!$self->seekable) {
   #die a horrible death
}

chris

On Jul 22, 2010, at 12:51 PM, Stefan Kirov wrote:

> Sorry for copying you all, but my posts to bioperl list do not go through (my headers seem suspicious).
> I proposed (comment on the bug) that seek throws an IO error, I think this would be good practice in general (device gets disconnected, etc.)
> I agree with Aaron that one option would be that if STDIN is the input format MUST be specified or parser dies.
> Another option is to right to a temp file or slurp into memory. This could be dangerous though...
> 
> On 7/22/2010 1:15 PM, Aaron Mackey wrote:
>> You cannot seek on a pipe, unfortunately.  SeqIO should probably try to detect this, and die rather than invoking GuessSeqFormat.
>> 
>> -Aaron
>> 
>> On Thu, Jul 22, 2010 at 10:30 AM, Stefan Kirov <stefan.kirov at bms.com <mailto:stefan.kirov at bms.com>> wrote:
>> 
>>    From what I see in /bioperl-live/Bio/Tools/GuessSeqFormat.pm
>> 
>>       if (defined $self->{-file}) {
>>           # Close the file we opened.
>>           close($fh);
>>       } elsif (ref $fh eq 'GLOB') {
>>           # Try seeking to the start position.
>>    >>>        seek($fh, $start_pos, 0);
>>       } elsif (defined $fh && $fh->can('setpos')) {
>>           # Seek to the start position.
>>           $fh->setpos($start_pos);
>>       }
>>       return ($done ? $fmt_string : undef);
>> 
>>     seek($fh, $start_pos, 0); does not reset as expected- tell $fh
>>    after reset is where the second non-null line starts.
>>    I am not sure why- all manuals claim this should work?
>>    Hope this helps.
>>    Stefan
>> 
>>    On 7/22/2010 9:27 AM, Chris Fields wrote:
>> 
>>        cat test.fa | perl -MBio::SeqIO -e 'my $seq=Bio::SeqIO->new(-fh
>>        >>>  =>\*STDIN); while ($myseq=$seq->next_seq){ print
>>        >>>  $myseq->id,"\t",$myseq->seq,"\n"}
>> 
>> 
>> 
>>    _______________________________________________
>>    Bioperl-l mailing list
>>    Bioperl-l at lists.open-bio.org <mailto:Bioperl-l at lists.open-bio.org>
>>    http://lists.open-bio.org/mailman/listinfo/bioperl-l
>> 
>> 
> 
> <stefan_kirov.vcf>





More information about the Bioperl-l mailing list