python - 罗莎琳德:孟德尔第一定律

标签 python probability bioinformatics rosalind

我正尝试在 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.

我的解决方案适用于示例,但不适用于生成的任何问题。经过进一步研究,我似乎应该找到随机选择任何一个生物体的概率,找到选择第二个生物体的概率,然后是该配对产生具有显性等位基因的后代的概率。

那么我的问题是:我下面的代码找到的概率是多少?对于所有可能的交配,它是否找到具有显性等位基因的后代百分比 - 因此,我的代码不是计算一个随机交配的概率,而是在测试所有配对时求解具有显性等位基因的后代百分比?

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

最佳答案

看着你的代码,我很难弄清楚它应该做什么。我会在这里解决这个问题。

让我们简化措辞。有 n1 个类型 1、n2 个类型 2 和 n3 个类型 3 项。

有多少种方法可以从所有元素中选出一套尺寸为 2 的元素? (n1 + n2 + n3) 选择 2。

每对项目的项目类型对应于以下六个无序多重集之一:{1,1}、{2,2}、{3,3}、{1,2}、{1,3} , {2,3}

有多少个 {i,i} 形式的多重集?我选择 2.

有多少个 {i,j} 形式的多重集,其中 i != j? ni * nj.

因此,六个多重集的概率如下:

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

这些总和为 1。请注意,对于 X > 1,[X 选择 2] 只是 [X * (X - 1)/2],对于 X = 0 或 1,则为 0。

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

要回答这个问题,您只需确定六个多重集中的哪个对应于此事件。由于缺乏遗传学知识来回答这个问题,我会把它留给你。

例如,假设如果两个 parent 中的任何一个是 1 型,就会产生一个显性等位基因。那么感兴趣的事件是 {1,1}、{1,2}、{1,3} 和事件是 P({1,1}) + P({1,2}) + P({1,3})。

关于python - 罗莎琳德:孟德尔第一定律,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26385968/

相关文章:

python - 将2个不等长的列表映射到字典

python - 火车验证和测试集中的一种热编码(生产数据)

c# - 调整从列表中选择项目的机会

bioinformatics - 具有非零退出状态 2 的 Fastqc 错误

python - Python 中的高级/抽象 Canbus 接口(interface)

python - 在 python 中查找命令失败,出现 "missing argument to -exec"

c# - 每次 Random.Next() 调用时返回所有数字的概率是否相同?

python - 优化生成变量的拒绝方法

python - 在python中解析包含multifasta BLAST结果的xml文件

python - 属性错误 : 'str' object has no attribute 'transID'