Re: Severe performance loss, comparing with perl 5

2010-06-13 Thread yary
2010/6/13 Richard Hainsworth :
...
> Your revcom can be replaced with a single line using core perl6 functions.
> I'll give an example that currently works on rakudo for a simple string,
> but you can put it into the loop.
> 
> my $sq='ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgta';
> say $sq.trans(['A','T','G','C','a','t','g','c'] =>
> ['T','A','C','G','t','a','c','g']).reverse;
> 

That can also be translated "in spirit" back to p5-

my $_='ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgta';
tr/atgcATGC/tacgTACG/;
print scalar reverse,"\n";


Re: Severe performance loss, comparing with perl 5

2010-06-13 Thread Richard Hainsworth
Dear Xi,

It may be more useful to rewrite your code to take advantage of perl6.

Your revcom can be replaced with a single line using core perl6 functions.
I'll give an example that currently works on rakudo for a simple string,
but you can put it into the loop.

my $sq='ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgta';
say $sq.trans(['A','T','G','C','a','t','g','c'] =>
['T','A','C','G','t','a','c','g']).reverse;


Really so simple. And probably much faster. The advantage over your
revcom subroutine is that it is much easier to understand.

Richard

On 06/13/10 10:03, Xi Yang wrote:
> #!/usr/bin/perl6use
>  v6;use Bio::SeqIO;
> say "program initialized";my $IN = Bio::SeqIO.new('fasta','makeseq.fasta');
> say "input stream created";
> while (my $obj = $IN.next_seq) {  say "\tid: <",$obj.display_id,">";  
> say "\tseq: <{$obj.seq}>";  say "\trev: <{revcom($obj.seq)}>";}
> sub revcom(Str $seq) {my $len = $seq.chars;   my $result; loop 
> (my $i=$len-1; $i>=0; $i--) {  given ($seq.substr($i,1)) {
>  when ('A') {$result~='T'}   when ('T') 
> {$result~='A'}   when ('G') {$result~='C'}
>when ('C') {$result~='G'}   when ('a') 
> {$result~='t'}   when ('t') {$result~='a'}
>when ('g') {$result~='c'}   when ('c') 
> {$result~='g'}   }   }   return 
> $result;}
> #!/usr/bin/perl
> use strict;use Bio::SeqIO;use feature qw/say switch/;
> say "program initialized";
> my $IN = Bio::SeqIO->new(-file=>'makeseq.fasta');
> say "input stream created";
> while (my $obj = $IN->next_seq) {say "\tid: <",$obj->display_id,">";
> say "\tseq: <",$obj->seq,">";say "\trev: <",revcom($obj->seq),">";}
> sub revcom {  my $seq = shift;my $len = length $seq;  my $result; 
> for (my $i=$len-1; $i>=0; $i--) {   given (substr $seq,$i,1) {
>   when ('A') {$result.='T'}   when ('T') 
> {$result.='A'}   when ('G') {$result.='C'}
>when ('C') {$result.='G'}   when ('a') 
> {$result.='t'}   when ('t') {$result.='a'}
>when ('g') {$result.='c'}   when ('c') 
> {$result.='g'}   }   }   return $result;}
> >EMBOSS_001ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgtaacgtagcgctccactccgttcgaaaggccggaggaaacaatcgctgaacaactgggtagacataaccatgtcgtctctgtgctactcccccacgggtatattaaggcagataaggttgcttagtgggacctataac>EMBOSS_002cggattcagaattggacccggaagcatgcaggcgtggaatgtgggttaagggaccgaagtatttcgttactattccgatagtatccgatgagtccgtagcgggatgcacgtcataatcctagccttgaacgaccgggtactggttacgcaattccacccatgtaccttcccacagcccacatgcgacttatt>EMBOSS_003tctacgtatgggaataggacgtgctcaatacacgcatggcttgccgtccatcgggagcgttgcaagtcaaagagctaggcttaacctggactgagtggtcattgcgccgatgcacggcctgcctcagcgctgggagtaatcgtcaatagcaagtgtattgtagcgtcatcccaggcctcgaggcctaa>EMBOSS_004gttgccgaacgcgccactctcccgcggtgcttaatcgagttggactcaccacctaccacacaacaccggatgcgctaactccgggcatctgtcgcaaggcttcatggaaccctacactggtaatcatggtaatagattcaacgtgggttccgttcatatagacaccactcacaaaggcgttcgtgccctgat>EMBOSS_005atatcactcagcctgtggacgtgagccacccgcgctcactctcgctgtagattatgtcg
>  
> gggagagaacgtagaatctgtaatcatcggtcatatgaagtaatccaccgacaccgagcaacgttgctactgacaacgggacatttaagagtgctggaaattgagttattccgcctggataattggcggtttg
>   
>   



Re: Severe performance loss, comparing with perl 5

2010-06-13 Thread Guy Hulbert
On Sun, 2010-13-06 at 06:03 +, Xi Yang wrote:
> I'm trying to use use Perl 6 to process some nucleotide sequences.
> However, I found it strangely slow on substr or string concat
> operations, compared with its Perl 5 equivalent.

I don't think that's unexpected at this stage of development.  Other
benchmarks (at least one ;-) have been posted to this list, showing the
same result.

-- 
--gh