Hi all, I'm doing an assignment that requires I shuffle a DNA sequence, then score the "mutations" according to a set of rules. I have come up with the below code and it is obviously not working (gives really odd results, like -2-4-400-200...etc) I'm hoping I just did something silly. My intent was to create a foreach loop that would use the subroutine I have that has a hash that creates numeric values based on evaluating the keys (hopefully that makes sense). Here is the code:

my $score; foreach(0 .. length($string) - 1){ my $s = substr($string, $_, 1); my $m = substr($shuf_seq, $_, 1); $score = scoring($s, $m); $score += $score; print $score; } print "\nThis is the total mutation score: $score \n"; #sub to calculate the scoring of mutations #If purine --> purine: -1 #If pyrimidine --> pyrimidine: -1 #If purine --> pyrimidine (or vice versa): -2 #If no change: 0 sub scoring{ my ($a, $b) = sort @_; my %scores; $scores{'A'}{'G'} = -1; $scores{'A'}{'T'} = -2; $scores{'A'}{'C'} = -2; $scores{'G'}{'T'} = -2; $scores{'C'}{'G'} = -2; $scores{'C'}{'T'} = -1; $scores{'A'}{'A'} = +0; $scores{'T'}{'T'} = +0; $scores{'C'}{'C'} = +0; $scores{'G'}{'G'} = +0; return $scores{$a}{$b}; }

In reply to Bioinformatics - Scoring DNA mutations by allsop_5

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.