I am trying to solve bioinformatics problems from rosalind.info and I am locked out with this problem: http://rosalind.info/problems/mrna/
To solve it you have to calculate the number of different RNA strings from which the protein could have been translated, modulo 1,000,000.
Biological background: A protein is a string composed of 20 amino acids represented with 20 different letters. Each amino acids can be replaced with more than one RNA string (composed by 3 letter each 1).
This problem gets you to the point of how to manage large number when programming, a usual case in bioinformatics. I have tried different things but I always get INF or a negative value so something I am doing something bad.
The problems itself suggest that I should find a way of manipulating large numbers without having to store them. How is this possible? How can I achieve that with PHP?
This is my best until now:
<?php function protein_reverse($sec) {
$sec_arr = str_split($sec);
$aa = array(
'F' => '2',
'L' => '6',
'S' => '6',
'Y' => '2',
'C' => '2',
'W' => '1',
'P' => '4',
'H' => '2',
'Q' => '2',
'R' => '4',
'I' => '3',
'M' => '1',
'T' => '4',
'N' => '2',
'K' => '2',
'V' => '4',
'A' => '4',
'D' => '2',
'E' => '2',
'G' => '4',
);
$r = 1;
foreach ( $sec_arr as $base ) {
$r *= $aa[$base] % 1000000;
}
return $r;
} ?>