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.
Here are the codes, Perl 6 on top, Perl 5 on middle, a test input file on 
bottom (should be stored to "makeseq.fasta"). The Perl 6's revcom() sub works 
very slow.
#########################################################################!/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_001ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgtaacgtagcgctccactccgttcgaaaggccggaggaaacaatcgctgaacaactgggtagacataaccatgtcgtctctgtgctactcccggggccacgggtatattaaggcagataaggttgcttagtgggacctataac>EMBOSS_002cggattcagaattggacccggaagcatgcaggcgtggaatgtgggggggttaagggaccgaagtatttcgttactattccgatagtatccgatgagtccgtagcgggatgcacgtcataatcctagccttgaacgaccgggtactggttacgcaattccacccatgtaccttcccacagcccacatgcgacttatttttt>EMBOSS_003tctacgtatgggaataggacgtgctcaatacacgcatggcttgccgtccatcgggaaaaagcgttgcaagtcaaagagctaggcttaacctggactgagtggtcattgcgccgatgcacggcctgcctcagcgctgggagtaatttttcgtcaccccatagcaagtgtattgtagcgtcatcccaggcctcgaggcctaa>EMBOSS_004gtcccctgccgaacgcgccactctcccgcggtgcttaatcgagttggactcaccggggacctaccacacaacaccggatgcgctaactccgggcatctgtcgcaaggcttcatggaaccctacactggtaatcatggtaatagattcaacgtgggttccgttcatatagacaccactcacaaaggcgttcgtgccctgat>EMBOSS_005atatcactcagcctgtggacgtgagttttccacccgcgctcactctcgctgtagattatgtcggggagagaacgtagaatctgtaatcatcggtcatatgaagtaatccaccgacaccgagcaacgttgctactgacaacgggacatttaagagtgctggaaaaaaattgagttattccgcctggataattggcggtttg
                                           
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969

Reply via email to