CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
string mutation script behaving erraticaly

 



rushadrena
Novice

Jun 24, 2012, 9:17 PM

Post #1 of 5 (4158 views)
string mutation script behaving erraticaly Can't Post

Dear all,
I have written a perl program which mutates a a protein sequence ( based on 20 alphabets).
For each character it encounters the program generates a random number between 0 and 1.
Im using hashes for mutation matrix. But I dont know why this problem. Try running the code in the attachment.
Attachments: pam1_check.pl (4.68 KB)


FishMonger
Veteran / Moderator

Jun 25, 2012, 7:38 AM

Post #2 of 5 (4134 views)
Re: [rushadrena] string mutation script behaving erraticaly [In reply to] Can't Post

You didn't specify what problem you are trying to resolve.

What is your expected output and how does that differ from what you're actually getting?

Using backticks to shell out to the system's awk and srand commands doesn't make much sense. Use Perl's built-in rand function.

Remove the -w switch and add these 2 pragmas then fix the problems that they point out.

Code
use strict; 
use warnings;

You should fix your indentation; it's inconsistent and in some areas it's missing.

Use a single hash lookup instead of all of those elsif blocks.


rushadrena
Novice

Jun 25, 2012, 11:42 AM

Post #3 of 5 (4126 views)
Re: [FishMonger] string mutation script behaving erraticaly [In reply to] Can't Post

Heres what the code does.
The string to be mutated has already been provided inside the code(line 30).
The string is made of 20 alphabets(line 5-24).
%nuc (line 4)is a 24x24 matrix made in hash.
The program generates a random number between 0 and 1 for length times the input string (length $string).
It then checks this value in the corresponding hash %nuc. In our case since the $string has been hardcoded consisting of only "A", therefore each time a random number is generated the program goes to line 17 only.
It then traverses the line 17 horizontally until a number greater than the random number is encountered. The value of the counter is noted when a number greater than the random number is encountered.
For example in case our our $string which has only "A", it will mutate to another alphabet only if the random number is greater than .9799 otherwise it will remain as "A" only.
The biggest problem with this code is that hashes dont get printed in the same order you store them,this shuffling leads to erratic results.
I tried rearranging the rows of hash %nuc but it still didnt help.
Another error is that Im getting an alphabet more in the output string than the hardcoded string.


FishMonger
Veteran / Moderator

Jun 25, 2012, 4:59 PM

Post #4 of 5 (4114 views)
Re: [rushadrena] string mutation script behaving erraticaly [In reply to] Can't Post

Did you make the changes I suggested? If not, why not?

You can cleanup and remove some of those loops by using the List::Util module.

There are a couple ways to work with an ordered hash. One approach is to use the Tie::IxHash module.
http://search.cpan.org/~chorny/Tie-IxHash-1.22/lib/Tie/IxHash.pm


BillKSmith
Veteran

Jul 2, 2012, 6:25 AM

Post #5 of 5 (3634 views)
Re: [rushadrena] string mutation script behaving erraticaly [In reply to] Can't Post

The main error in your script has nothing to do with perl. The hash %nuc is really a matrix of the probabilities of every possible mutation. Even if your code did exactly what you describe, the results would not reflect this. Note that testing this code is not a simple task because the expected result is only a few mutations in tens of thousands of runs.

I recommend developing a corrected mutation subroutine as a module to simplify the testing. Use all of FishMonger's suggestions to help avoid common errors.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives