【ROSALIND】【練Python,學(xué)生信】07 孟德爾第一定律

如果第一次閱讀本系列文檔請(qǐng)先移步閱讀【ROSALIND】【練Python,學(xué)生信】00 寫在前面 ?謝謝配合~

題目:
孟德爾第一定律(Mendel's First Law)
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.
所給:三個(gè)正整數(shù)k、m、n,分別代表一個(gè)群體中某基因的基因型個(gè)體數(shù)目,k是顯性純合個(gè)體,m是雜合個(gè)體,n為隱形純合個(gè)體,即群體總個(gè)體數(shù)為k+m+n。
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.
需得:隨機(jī)選取兩個(gè)個(gè)體,生出一個(gè)表現(xiàn)顯性性狀個(gè)體的概率(假設(shè)任意兩個(gè)個(gè)體均可交配)。
?
測(cè)試數(shù)據(jù)
2 2 2
測(cè)試輸出
0.78333
?
背景
孟德爾遺傳定律的分離定率如下:決定生物體遺傳性狀的一對(duì)等位基因在配子形成時(shí)彼此分開,分別進(jìn)入一個(gè)配子中。
?
思路
題目要求計(jì)算顯性性狀個(gè)體,但因?yàn)殡[性性狀只有一種情況,計(jì)算更簡(jiǎn)單,所以不妨先計(jì)算隱性性狀,再用1減去得到顯性性狀的概率。可得到隱性性狀后代的有如下組合:A為n,B為n;A為n,B為m;A為m,B為n;A為m,B為m。將各組合概率求出相加即為隱性性狀概率。
?
?
代碼
k = 2
m = 2
n = 2
s = k + m + n
c = 1 - (n/s * (n-1)/(s-1) + 2 * n/s * 0.5 * m/(s-1) + m/s * (m-1)/(s-1) * 0.25)
print(round(c,5))