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. <start example> my $sq='ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgta'; say $sq.trans(['A','T','G','C','a','t','g','c'] => ['T','A','C','G','t','a','c','g']).reverse; <end example> 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_001ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgtaacgtagcgctccactccgttcgaaaggccggaggaaacaatcgctgaacaactgggtagacataaccatgtcgtctctgtgctactcccggggccacgggtatattaaggcagataaggttgcttagtgggacctataac>EMBOSS_002cggattcagaattggacccggaagcatgcaggcgtggaatgtgggggggttaagggaccgaagtatttcgttactattccgatagtatccgatgagtccgtagcgggatgcacgtcataatcctagccttgaacgaccgggtactggttacgcaattccacccatgtaccttcccacagcccacatgcgacttatttttt>EMBOSS_003tctacgtatgggaataggacgtgctcaatacacgcatggcttgccgtccatcgggaaaaagcgttgcaagtcaaagagctaggcttaacctggactgagtggtcattgcgccgatgcacggcctgcctcagcgctgggagtaatttttcgtcaccccatagcaagtgtattgtagcgtcatcccaggcctcgaggcctaa>EMBOSS_004gtcccctgccgaacgcgccactctcccgcggtgcttaatcgagttggactcaccggggacctaccacacaacaccggatgcgctaactccgggcatctgtcgcaaggcttcatggaaccctacactggtaatcatggtaatagattcaacgtgggttccgttcatatagacaccactcacaaaggcgttcgtgccctgat>EMBOSS_005atatcactcagcctgtggacgtgagttttccacccgcgctcactctcgctgtagattatgtcg > > gggagagaacgtagaatctgtaatcatcggtcatatgaagtaatccaccgacaccgagcaacgttgctactgacaacgggacatttaagagtgctggaaaaaaattgagttattccgcctggataattggcggtttg > >