Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2018-02-23 03:39 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (300 votes). Check out past polls.