Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rosalind: Mendel's first law

I'm trying to solve the problem at http://rosalind.info/problems/iprb/

Given: Three positive integers k, m, and n, representing a population containing k+m+n organisms: k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive.

Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate.

My solution works for the sample, but not for any problems generated. After further research it seems that I should find the probability of choosing any one organism at random, find the probability of choosing the second organism, and then the probability of that pairing producing offspring with a dominant allele.

My question is then: what does my code below find the probability of? Does it find the percentage of offspring with a dominant allele for all possible matings -- so rather than the probability of one random mating, my code is solving for the percentage of offspring with dominant alleles if all pairs were tested?

f = open('rosalind_iprb.txt', 'r')
r = f.read()
s = r.split()
############# k = # homozygotes dominant, m = #heterozygotes, n = # homozygotes recessive
k = float(s[0])
m = float(s[1])
n = float(s[2])
############# Counts for pairing between each group and within groups
k_k = 0
k_m = 0
k_n = 0

m_m = 0
m_n = 0

n_n = 0


##############
if k > 1:
    k_k = 1.0 + (k-2) * 2.0

k_m = k * m

k_n = k * n

if m > 1:
    m_m = 1.0 + (m-2) * 2.0

m_n = m * n

if n> 1:
    n_n = 1.0 + (n-2) * 2.0
#################
dom = k_k + k_m + k_n + 0.75*m_m + 0.5*m_n
total = k_k + k_m + k_n + m_m + m_n + n_n

chance = dom/total
print chance
like image 769
user4146164 Avatar asked Oct 15 '14 15:10

user4146164


People also ask

What is the first law of Mendel's law?

The first law of inheritance is the law of dominance. The law states that hybrid offspring will only inherit the dominant characteristics in the phenotype. The alleles that suppress a trait are recessive traits, whereas the alleles that define a trait are known as dominant traits.

What is Mendel's 1st and 2nd law?

Mendel's first law describes the segregation of the two copies of alleles of a particular gene into the gametes. Mendel's second law describes the independent assortment of alleles of different genes from each other during the formation of gametes.

What is Mendel's first law class 10?

Mendel's law of dominance states that: “When parents with pure, contrasting traits are crossed together, only one form of trait appears in the next generation. The hybrid offsprings will exhibit only the dominant trait in the phenotype.” Law of dominance is known as the first law of inheritance.

How is genetic drift related to Mendel's 1st law?

Genetic drift is related to Mendel's first law due to the interaction of alternative forms that the same gene can have, called allele.


1 Answers

Looking at your code, I'm having a hard time figuring out what it's supposed to do. I'll work through the problem here.

Let's simplify the wording. There are n1 type 1, n2 type 2, and n3 type 3 items.

How many ways are there to choose a set of size 2 out of all the items? (n1 + n2 + n3) choose 2.

Every pair of items will have item types corresponding to one of the six following unordered multisets: {1,1}, {2,2}, {3,3}, {1,2}, {1,3}, {2,3}

How many multisets of the form {i,i} are there? ni choose 2.

How many multisets of the form {i,j} are there, where i != j? ni * nj.

The probabilities of the six multisets are thus the following:

  • P({1,1}) = [n1 choose 2] / [(n1 + n2 + n3) choose 2]
  • P({2,2}) = [n2 choose 2] / [(n1 + n2 + n3) choose 2]
  • P({3,3}) = [n3 choose 2] / [(n1 + n2 + n3) choose 2]
  • P({1,2}) = [n1 * n2] / [(n1 + n2 + n3) choose 2]
  • P({1,3}) = [n1 * n3] / [(n1 + n2 + n3) choose 2]
  • P({2,3}) = [n2 * n3] / [(n1 + n2 + n3) choose 2]

These sum to 1. Note that [X choose 2] is just [X * (X - 1) / 2] for X > 1 and 0 for X = 0 or 1.

Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype).

To answer this question, you simply need to identify which of the six multisets correspond to this event. Lacking the genetics knowledge to answer that question, I'll leave that to you.

For example, suppose that a dominant allele results if either of the two parents was type 1. Then the events of interest are {1,1}, {1,2}, {1,3} and the probability of the event is P({1,1}) + P({1,2}) + P({1,3}).

like image 59
Timothy Shields Avatar answered Oct 02 '22 10:10

Timothy Shields