I want to find all the possible gametes of a specific cross.
For example: 'AABB'
x 'aabb'
would be split into ['AA', 'BB']
and ['aa', 'bb']
. I have that part done. After this, it should return:
[['Aa', 'Aa', 'Aa', 'Aa'], ['Bb', 'Bb', 'Bb', 'Bb']]
(for every allele in parent 'A', it matches with an allele in parent 'B'; this is a simplified Punnett Square).
This is what I have so far:
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
It doesn't result in what I expected it would, though:
>>> punnett('AaBb', 'AaBb')
[['AA', 'Aa', 'aA', 'aa', 'BB', 'Bb', 'bB', 'bb']]
Also, a trihybrid cross does not give the results I expected, either:
>>> punnett('AaBbCc', 'AaBbCc')
[['AA', 'Aa', 'aA', 'aa', 'BB', 'Bb', 'bB', 'bb'], ['AA', 'Aa', 'aA', 'aa', 'BB', 'Bb', 'bB', 'bb', 'CC', 'Cc', 'cC', 'cc']]
If I could get input on what I'm doing wrong and how I could improve it, that would be great. Thanks!