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

Haiyan Lin linhy0120 at gmail.com
Sun Jul 13 02:23:59 UTC 2014


Hi, geogre,

Thanks your code is working for data embedded in code with "__DATA__".
But, it failed to hand data from outside. Following is the data and
result.

[linhy at bioinfo1 Script]$ more try.fa
>Contig000001
CCACGTAAGAGCACCTGGGTCCCCGCCCGCCAAGCGCCGCGAGCGCCAGCAGCAGCTCGC
>hello
ATATATTTTT
[linhy at bioinfo1 Script]$ cat try.fa | perl try.pl 
seq is AGAGAGAGA
seq is ATATATAT

Thanks

Haiyan



On Sat, 2014-07-12 at 18:36 -0700, george hartzell wrote:
> I just did this on my Mac OS X 10.9.4 system with perl 5.18.2:
> 
> cd tmp
> mkdir haiyan
> cd haiyan
> cpanm -n -L local Bio::SeqIO
> 
> perl -Ilocal/lib/perl5 foo.pl
> 
> With the following little program in foo.pl:
> 
> use Bio::SeqIO ;
> 
> my $in = Bio::SeqIO->new(-format=>"Fasta", -fh => \*DATA);
> while(my $s = $in->next_seq()){
>     print "seq is " . $s->seq . "\n"
> }
> 
> __DATA__
> >ct1
> AGAGAGAGA
> >ctg2
> ATATATAT
> 
> and it does this when I run it:
> 
> (alacrity)[18:22:58]haiyan>>perl -Ilocal/lib/perl5 foo.pl
> seq is AGAGAGAGA
> seq is ATATATAT
> (alacrity)[18:24:42]haiyan>>
> 
> Can you get the same series of things to work?
> 
> If you’re doing a bunch of this kind of stuff, you might want to look
> at Data::Section; rjbs discusses it
> here. It’s warmer and fuzzier than dealing with the DATA handle by
> yourself.
> 
> g.
> 
>



More information about the Bioperl-l mailing list