Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: perlkhan 77

by apl (Monsignor)
on Apr 22, 2009 at 12:06 UTC ( #759255=note: print w/replies, xml ) Need Help??

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";
$ratio_G = Calculate( 'G' );
Writing the sub Calculate is left as an exercise to the reader. The advantages are you
  • get rid of all of the temporary $count_* variables
  • remove duplicated code
  • make future changes (e.g. you want percentage rather than ratio) more centralized
  • make the intentions of your code much clearer

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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759255]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2016-10-23 17:28 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.