Hi everyone, how are you? This time, I want to discuss about one of the problems that exist in rosalind.info's web. That title is "Counting Point Mutations". For the reference, you can first check out the problem what will be discussed (here).
Overview
In this problem, we will be given 6 integers-input representing the number of genotype pairing below:
1. AA-AA
2. AA-Aa
3. AA-aa
4. Aa-Aa
5. Aa-aa
6. aa-aa
Our task is to find the expected value of the number of offspring that have a dominant phenotype (AA & Aa) if we take 2 offsprings from each pair.
The expected value itself is an average value of all possible case that will happen. For example, the expected value of a dice roll is 3.5. That number is obtained from the average value of all possible case that will happen in a dice roll, (1 + 2 + 3 + 4 + 5 + 6) / 6.
The Code
This is the code for solving this problem (with java language):
1. static void solve() {
2. double[] val = {2, 2, 2, 1.5, 1, 0};
3. double tot = 0.0;
4. for (int i = 0; i < 6; i++) {
5. tot += val[i] * nd();
6. }
7. out.printf("%.1f\n", tot);
8. }
As you've seen, the solution code is quite simple. First, we make an array variable (double[] val) containing a set of probability that representing a dominant phenotype from each pair (AA-AA = 4/4, Aa-Aa = 3/4, etc; line 2). We can multiply that probability (line 2) with the number of sample would be taken. I did, I multiplied that probability with 2 (originally {1, 1, 1, 0.75, 0.5, 0}, transformed into {2, 2, 2, 1.5, 1, 0}).
The last step is multiplying the double[] val variable with the number of pair given.
Input and Output
In the code above, I used nd() function for entering the double-form data. That function is a extend from one of the system inputs which are available in java, called BufferedReader.
And for the output I used out.printf() function. That function is a modification from System.out.printf() function which is very familiar in java. You can see the additional code for that modification (input and output) in my complete code at github.
That's it. If you want to ask something, you can write it in the comment section below. I hope this article is useful and see you in the next article!
Reference :
Source of image 1 :https://www.facebook.com/ProjectRosalind/
Source of image 2 :https://4eso7phymodee.wordpress.com/2015/03/22/mendels-laws/
No comments:
Post a Comment