欢迎光临散文网 会员登陆 & 注册

【ROSALIND】【练Python,学生信】07 孟德尔第一定律

2019-02-03 21:25 作者:未琢  | 我要投稿

如果第一次阅读本系列文档请先移步阅读【ROSALIND】【练Python,学生信】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.

所给:三个正整数k、m、n,分别代表一个群体中某基因的基因型个体数目,k是显性纯合个体,m是杂合个体,n为隐形纯合个体,即群体总个体数为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.

需得:随机选取两个个体,生出一个表现显性性状个体的概率(假设任意两个个体均可交配)。

 

测试数据

2 2 2

测试输出

0.78333

 

背景

孟德尔遗传定律的分离定率如下:决定生物体遗传性状的一对等位基因在配子形成时彼此分开,分别进入一个配子中。

 

思路

题目要求计算显性性状个体,但因为隐性性状只有一种情况,计算更简单,所以不妨先计算隐性性状,再用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))


【ROSALIND】【练Python,学生信】07 孟德尔第一定律的评论 (共 条)

分享到微博请遵守国家法律