반응형
문제 설명:
멘델의 법칙
1.우열의 원리
2.분리의 법칙
3.독립의 법칙
dominant phenotype 의 확률을 구해줘야 하는데
recessive homo 가 나올 확률을 구하고 전체에서 빼줍니다.
주어진 문제에 따라 전체 샘플의 갯수는 6개
(AA,Aa)
aa 확률 = (2/6 x 1/5) x 1/4
(hetero/total * hetero/total-1) x (aa가 4개 genotype 중 하나 (AA,Aa,Aa,aa))
(Aa,Aa)
aa 확률 = (2/6 x 2/5) x 2 x 1/2
(recessive homo/total) x (hetero/total-1) x 2 x (aa가 4개 genotype 중 하나 (AA,Aa,Aa,aa))
(aa,aa)
aa 확률 = 2/6 x 1/5
(recessive homo/total) x (recessive homo/total-1)
=0.21666...
1 - 0.21666 = 0.78333
코드:
num1=2
num2=2
num3=2
case=num1+num2+num3
mendel=[]
probability=0
def combination(n,k):
numerator=1
denominator=1
k=min(n-k,k)
for i in range(1,k+1):
denominator*=i
numerator*=n+1-i
return numerator/denominator
total = combination(case,2)
for i in range(1,case+1):
if i <= num1:
mendel.append("AA")
elif i <= num1+num2:
mendel.append("Aa")
else:
mendel.append("aa")
for i in range(0,len(mendel)):
for j in range(i+1, len(mendel)):
if mendel[i]=="AA":
probability+=1
elif mendel[i]=="Aa" and mendel[j]=="Aa":
probability+=0.75
elif mendel[i]=="Aa" and mendel[j]=="aa":
probability+=0.5
print(round(probability/total,5))
#result
0.78333
반응형
'Python' 카테고리의 다른 글
Rosalind - Finding a Motif in DNA (0) | 2023.10.15 |
---|---|
Rosalind - Translating RNA into Protein (0) | 2023.09.30 |
Rosalind - Counting Point Mutations (0) | 2023.09.23 |
Rosalind - Computing GC Content (0) | 2023.09.14 |
Rosalind - Rabbits and Recurrence Relations (0) | 2023.09.11 |