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.

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.

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