<div dir="ltr"><div><div>Hi Haiyan,<br><br></div>You need to use the '-fh' option in Bio::SeqIO new and have it use Perl's DATA filehandle like so:<br>my $in = Bio::SeqIO->new(-fh => \*DATA, -format => 'fasta');<br>
<br>This was taken from <a href="http://perldoc.perl.org/perldata.html#Special-Literals">http://perldoc.perl.org/perldata.html#Special-Literals</a>:<br>"Text after __DATA__ may be read via the filehandle <code class=""><span class="">PACKNAME::DATA</span></code>
,
where <code class=""><span class="">PACKNAME</span></code>
is the package that was current when the __DATA__
token was encountered."<br><br><br></div>Good luck,<br><br>Paul<br><div><br><br></div></div><div class="gmail_extra"><br clear="all"><div>Paul Cantalupo<br>University of Pittsburgh<br></div>
<br><br><div class="gmail_quote">On Sat, Jul 12, 2014 at 8:35 AM, Haiyan Lin <span dir="ltr"><<a href="mailto:linhy0120@gmail.com" target="_blank">linhy0120@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hill, dear perlers,<br>
<br>
I‘m trying to use Bio::SeqIO to read Fasta sequence from pipe, or @ARGV,<br>
like "while (<>) {....}". After several trier and error, I'm failed and<br>
need to ask for herp from you. Could you please help me to check or try<br>
following code?<br>
<br>
Thanks in advance.<br>
<br>
---------------------------------------<br>
use Bio::SeqIO ;<br>
use Statistics::Descriptive ;<br>
<br>
my %opt = () ;<br>
my $sta = Statistics::Descriptive::Full->new();<br>
<br>
##### here is the key, I think.<br>
my $in = Bio::SeqIO->new(-format=>"Fasta");<br>
while(my $s = $in->next_seq()){<br>
$sta->add_data($s->length()) ;<br>
}<br>
print $sta->sum() if $opt{sum} ;<br>
<br>
__DATA__<br>
>ct1<br>
AGAGAGAGA<br>
>ctg2<br>
ATATATAT<br>
-----------------------------------------------<br>
<br>
Regards<br>
<br>
Haiyan<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Bioperl-l mailing list<br>
<a href="mailto:Bioperl-l@mailman.open-bio.org">Bioperl-l@mailman.open-bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/bioperl-l" target="_blank">http://mailman.open-bio.org/mailman/listinfo/bioperl-l</a></blockquote></div><br></div>