[Bioperl-l] use Bio::SeqIO to read Fasta sequence from pipe, or @ARGV, like "while (<>) {....}"

Paul Cantalupo pcantalupo at gmail.com
Sat Jul 12 14:22:03 UTC 2014


Hi Haiyan,

You need to use the '-fh' option in Bio::SeqIO new and have it use Perl's
DATA filehandle like so:
my $in = Bio::SeqIO->new(-fh => \*DATA, -format => 'fasta');

This was taken from http://perldoc.perl.org/perldata.html#Special-Literals:
"Text after __DATA__ may be read via the filehandle PACKNAME::DATA , where
PACKNAME is the package that was current when the __DATA__ token was
encountered."


Good luck,

Paul



Paul Cantalupo
University of Pittsburgh


On Sat, Jul 12, 2014 at 8:35 AM, Haiyan Lin <linhy0120 at gmail.com> wrote:

> Hill, dear perlers,
>
> I‘m trying to use Bio::SeqIO to read Fasta sequence from pipe, or @ARGV,
> like "while (<>) {....}". After several trier and error,  I'm failed and
> need to ask for herp from you. Could you please help me to check or try
> following code?
>
> Thanks in advance.
>
> ---------------------------------------
> use Bio::SeqIO ;
> use Statistics::Descriptive ;
>
> my %opt = () ;
> my $sta = Statistics::Descriptive::Full->new();
>
> ##### here is the key, I think.
> my $in = Bio::SeqIO->new(-format=>"Fasta");
> while(my $s = $in->next_seq()){
>     $sta->add_data($s->length()) ;
> }
> print $sta->sum() if $opt{sum} ;
>
> __DATA__
> >ct1
> AGAGAGAGA
> >ctg2
> ATATATAT
> -----------------------------------------------
>
> Regards
>
> Haiyan
>
>
>
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at mailman.open-bio.org
> http://mailman.open-bio.org/mailman/listinfo/bioperl-l
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/bioperl-l/attachments/20140712/6910afaa/attachment.html>


More information about the Bioperl-l mailing list