罗莎琳德“孟德尔第一定律”IPRB

Bem*_*mmu 2 python bioinformatics rosalind

作为即将到来的生物信息学课程的准备工作,我正在做一些来自 rosalind.info 的作业。我目前被困在任务“孟德尔第一定律”中。

我想我可以用蛮力来解决这个问题,但不知何故,我的想法一定太复杂了。我的方法是这样的:

构建一个具有三个级别的概率树。有两种生物交配,生物 A 和生物 B。第一级是,选择生物 A 纯合显性 (k)、杂合 (m) 或纯合隐性 (n) 的概率是多少。看起来,例如对于纯合优势,因为总共有 (k+m+n) 个生物,其中 k 是纯合优势,概率是 k/(k+m+n)。

然后在这棵树中,假设我们知道生物 A 被选为什么生物,那么在每个树下都会出现生物 B 为 k / m / n 的概率。例如,如果生物 A 被选为杂合 (m),那么生物 B 也是杂合的概率是 (m-1)/(k+m+n-1),因为现在剩下的杂合生物少了一个。

这将给出两个级别的概率,并且会涉及很多代码来实现这一点,因为我实际上是在构建树结构,并且为每个分支手动编写了该部分的代码。

在此处输入图片说明

现在在选择生物 A 和 B 后,它们每个都有两条染色体。可以随机挑选这些染色体之一。因此,对于 A,可以选择 1 或 2 号染色体,B 的染色体也相同。因此有 4 种不同的选择:选择 A 中的 1,B 中的 1。选择 A 中的 2,B 中的 1。选择 A 中的 1,B 中选择 2。 A 中的 2 个,B 中的 2 个。这些中的每一个的概率都是 1/4。所以最后这棵树会有这些叶子概率。

然后从那里以某种方式通过魔法我将所有这些概率相加,看看两个生物体产生具有显性等位基因的生物的概率是多少。

我怀疑这项任务是否需要花费数小时才能解决。我在想什么太难了?

更新:

以最荒谬的蛮力方式解决了这个问题。刚刚运行了数千次模拟交配并找出最终具有显性等位基因的部分,直到有足够的精度通过分配。

import random
k = 26
m = 18
n = 25

trials = 0
dominants = 0

while True:
    s = ['AA'] * k + ['Aa'] * m + ['aa'] * n
    first = random.choice(s)
    s.remove(first)
    second = random.choice(s)
    has_dominant_allele = 'A' in [random.choice(first), random.choice(second)]
    trials += 1
    if has_dominant_allele:
        dominants += 1
    print "%.5f" % (dominants / float(trials))
Run Code Online (Sandbox Code Playgroud)

Kla*_*cha 5

具有显性等位基因的物种是AAAa

Your total ppopulation (k + n + m consists of k (hom) homozygous dominant organisms with AA, m (het) heterozygous dominant organisms with Aa and n (rec) homozygous recessive organisms with aa. Each of these can mate with any other.

The probability for organisms with the dominant allele is:

P_dom = n_dominant/n_total or 1 - n_recessive/n_total
Run Code Online (Sandbox Code Playgroud)

Doing the Punnett squares for each of these combinations is not a bad idea:

  hom + het

  |  A | a
-----------
A | AA | Aa
a | Aa | aa


  het + rec

  |  a | a
-----------
A | Aa | Aa
a | aa | aa
Run Code Online (Sandbox Code Playgroud)

Apparently, mating of of two organisms results in four possible children. hom + het yields 1 of 4 organisms with the recessive allele, het + rec yields 2 of 4 organisms with the recessive allele.

You might want to do that for the other combinations as well.

Since we're not just mating the organisms one on one, but throw together a whole k + m + n bunch, the total number of offspring and the number of 'children' with a particular allele would be nice to know.

If you don't mind a bit of Python, comb from scipy.misc might be helpful here. in the calculation, don't forget (a) that you get 4 children from each combination and (b) that you need a factor (from the Punnett squares) to determine the recessive (or dominant) offspring from the combinations.

Update

    # total population
    pop_total = 4 * comb(hom + het + rec, 2)

    # use PUNNETT squares!

    # dominant organisms         
    dom_total = 4*comb(hom,2) + 4*hom*het + 4*hom*rec + 3*comb(het,2) + 2*het*rec

    # probability for dominant organisms
    phom = dom_total/pop_total
    print phom

    # probability for dominant organisms + 
    # probability for recessive organisms should be 1
    # let's check that:
    rec_total = 4 * comb(rec, 2) + 2*rec*het + comb(het, 2)
    prec = totalrec/totalpop
    print 1 - prec
Run Code Online (Sandbox Code Playgroud)