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

Bioinformatics - Scoring DNA mutations

by allsop_5 (Initiate)
on Apr 30, 2016 at 01:28 UTC ( [id://1161939]=perlquestion: print w/replies, xml ) Need Help??

allsop_5 has asked for the wisdom of the Perl Monks concerning the following question:

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}; }

Replies are listed 'Best First'.
Re: Bioinformatics - Scoring DNA mutations
by Athanasius (Archbishop) on Apr 30, 2016 at 07:23 UTC

    Hello allsop_5, and welcome to the Monastery!

    The code as given is imcomplete, as it doesn’t show the declaration and initialization of the variables $string and $shuf_seq. It would be useful if you could provide sample values for these variables, together with the final $score value you expect to generate from these sample values.

    One point stands out: in these lines:

    $score = scoring($s, $m); $score += $score;

    you first overwrite the value of the variable $score, then add this new value to itself (thereby doubling it). Neither of these is what you intend. You need something along these lines:

    my $score; foreach (...) { ... my $local_score = scoring($s, $m); $score += $local_score; print $local_score; # (or did you want to print $score here?) }

    And BTW: you do begin your script with:

    use strict; use warnings;

    don’t you?

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Bioinformatics - Scoring DNA mutations
by graff (Chancellor) on Apr 30, 2016 at 15:44 UTC
    Also, I think part of the problem (as you described it) may be due to the lack of suitable formatting (spaces and/or tabs and/or newlines, plus maybe some descriptive labels) when you print things. Note the difference between these two snippets:
    my @arr = ( -10, -5, -1, 0, 2, 6, 11 ); # mimicking to the OP code: for my $n ( @arr ) { print $n; } # being more detail-oriented: for my $n ( @arr ) { print "$n\n"; # include a newline after the value }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1161939]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-23 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found