http://www.perlmonks.org?node_id=759255


in reply to perlkhan 77

In addition to the earlier comments, I'd suggest changing (as an example)
$count_G = ( $seq =~ tr/G//); $ratio_G = ($count_G/$len); # print "\n$ratio_G\n";
to
$ratio_G = Calculate( 'G' );
Writing the sub Calculate is left as an exercise to the reader. The advantages are you

Replies are listed 'Best First'.
Re^2: perlkhan 77
by Anonymous Monk on Apr 22, 2009 at 12:10 UTC
    sub Passref { my ( $define, $seq, $count, $outfh ) = @_; chomp($define); my $len = length($$seq); my %count = ( Miss => 0+( $$seq =~ m/^YCWLPHQIMTNKSRVADEGF/ig ) ); # YCWLPHQIMTNKSRVADEGF doesn't appear in test file my %ratio = ( Miss => 0+( $count{Miss} / $len ) ); for my $letter (qw[ E D A V R S K N T M I Q H P L W C Y F ]) { $count{$letter} = ( $$seq =~ m/$letter/g ); $ratio{$letter} = $count{$letter} / $len; } print {$outfh} join "\t", $define, $len, @ratio{qw[ E D A V R S K N T M I Q H P L W C Y F Miss ]}, "\n"; }
      For count you need
      $count{$letter} = ()= $$seq =~ m/$letter/g;