Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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";
to
$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


Comment on Re: perlkhan 77
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-10-22 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls