Monday, 25 October 2021

Mendel's First Law (Rosalind | English)

     

rosalind


Hi everyone, how are you? In this time I want to discuss about a problem from rosalind.info's web. The title is "Complementing a Strand of DNA". For the reference, you can first check out the problem what will be discussed (here). 

Overview

In this problem we will given 3 integers stand for number of dominant homozygot organism (AA), heterozygot organism (Aa), and recessive homozygot organism (aa). Our job is searching the probability of their offsprings which have a dominant fenotype (AA/Aa) in decimal form (double). Every organism meets each other once. 


The Mendel's first law.

Thus, for searching the answer we can first looking for the possibility of appearing AA and Aa from each meeting; and then calculate them all. 

For the referrence, this is the list of the offspring's possibility for each meeting: 

- AA meets AA = 4 AA.
- AA meets Aa = 2 AA + 2 Aa.
- AA meets aa = 4 Aa.
- Aa meets Aa = 1 AA + 2 Aa + 1 aa.
- Aa meets aa = 2 Aa + 2 aa.
- aa meets aa = 4 aa.

If you've found the total possibility of appearing AA and Aa, then divide it by the number of all meeting occured. The answer has been founded! 

The Code 

This is the code for solving this problem with java language: 

static long seluncur (int x) {
return x * (x - 1) / 2;
}
static void solve() {
int k = ni();
int m = ni();
int n = ni();
long totDominant = (seluncur(k) * 4) + ((long)k * m * 4) + ((long)k * n * 4) + (seluncur(m) * 3) + ((long)m * n * 2);
out.printf("%.5f", 1.0 * totDominant / (seluncur(k + m + n) * 4));
}  

The Second Solution 

The second solution has an opposite solution from the previous one. If in previous solution we calculating the desired probability directly, in the second solution we first calculating the number of all meeting occured, and then we substract that number with the number of not desirable offsring's possibility. And the rest is dividing it by the number of all meeting occured

Input and Output

In the code above, I used in.read() function for entering the string form data. That function is a extend from one of the input systems which are available in java, called BufferedReader. 

And for the output I used function out.println(). That function is modification from function System.out.println() that is very familiar in java. You can see the additional code for that modification in my complete code at github

That's from me. 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