1

我想找到特定十字架的所有可能配子。

例如:'AABB'x'aabb'将被拆分为['AA', 'BB']['aa', 'bb']。我已经完成了那部分。在此之后,它应该返回:( [['Aa', 'Aa', 'Aa', 'Aa'], ['Bb', 'Bb', 'Bb', 'Bb']]对于父“A”中的每个等位基因,它与父“B”中的一个等位基因匹配;这是一个简化的 Punnett Square)。

这是我到目前为止所拥有的:

def punnett(a, b):
    n = int(len(a)/2)
    x = int(float(len(a)) / n)
    partsA, partsB, gametes = [a[i * x : i * x + x] for i in range(n)], [b[i * x : i * x + x] for i in range(n)], []
    for y in range(1, n):
        g = []
        for index in range(0, n/2 + y):
            for i in partsA[index]:
                for j in partsB[index]:
                    g.append(i+j)
        gametes.append(g)
    return gametes

但是,它并没有达到我的预期:

>>> punnett('AaBb', 'AaBb')
[['AA', 'Aa', 'aA', 'aa', 'BB', 'Bb', 'bB', 'bb']]

此外,三杂交也没有给出我预期的结果:

>>> punnett('AaBbCc', 'AaBbCc')
[['AA', 'Aa', 'aA', 'aa', 'BB', 'Bb', 'bB', 'bb'], ['AA', 'Aa', 'aA', 'aa', 'BB', 'Bb', 'bB', 'bb', 'CC', 'Cc', 'cC', 'cc']]

如果我能得到关于我做错了什么以及如何改进它的意见,那就太好了。谢谢!

4

1 回答 1

3

好的,我刚刚阅读了一些关于您可能想要实现的材料,以下是更改

>>> from itertools import product, izip

如果我理解正确,等位基因是忽略大小写的连续字符。在“AaBb”的情况下,它的 ['Aa' 和 'Bb']

>>> def allele(e):
    return [list(v) for _, v in groupby(e, key = str.lower)]

交叉定义为材料和亲本之间所有可能的等位基因交叉

然后从交叉中选择新的基因组

>>> def punnett(a, b):
    return [''.join(e)
        for e in product(*([''.join(e) for e in product(*e)]
                    for e in izip(allele(a), allele(b))))]

>>> punnett('AaBbCc', 'AaBbCc')
['AABBCC', 'AABBCc', 'AABBcC', 'AABBcc', 'AABbCC', 'AABbCc', 'AABbcC', 'AABbcc', 'AAbBCC', 'AAbBCc', 'AAbBcC', 'AAbBcc', 'AAbbCC', 'AAbbCc', 'AAbbcC', 'AAbbcc', 'AaBBCC', 'AaBBCc', 'AaBBcC', 'AaBBcc', 'AaBbCC', 'AaBbCc', 'AaBbcC', 'AaBbcc', 'AabBCC', 'AabBCc', 'AabBcC', 'AabBcc', 'AabbCC', 'AabbCc', 'AabbcC', 'Aabbcc', 'aABBCC', 'aABBCc', 'aABBcC', 'aABBcc', 'aABbCC', 'aABbCc', 'aABbcC', 'aABbcc', 'aAbBCC', 'aAbBCc', 'aAbBcC', 'aAbBcc', 'aAbbCC', 'aAbbCc', 'aAbbcC', 'aAbbcc', 'aaBBCC', 'aaBBCc', 'aaBBcC', 'aaBBcc', 'aaBbCC', 'aaBbCc', 'aaBbcC', 'aaBbcc', 'aabBCC', 'aabBCc', 'aabBcC', 'aabBcc', 'aabbCC', 'aabbCc', 'aabbcC', 'aabbcc']
>>> punnett('AaBb', 'AaBb')
['AABB', 'AABb', 'AAbB', 'AAbb', 'AaBB', 'AaBb', 'AabB', 'Aabb', 'aABB', 'aABb', 'aAbB', 'aAbb', 'aaBB', 'aaBb', 'aabB', 'aabb']
>>> 
于 2013-03-02T04:21:37.887 回答