https://rosalind.info/problems/afrq/
ROSALIND | Counting Disease Carriers
It appears that your browser has JavaScript disabled. Rosalind requires your browser to be JavaScript enabled. Counting Disease Carriers solved by 791 Genetic Drift and the Hardy-Weinberg Principle Mendel's laws of segregation and independent assortment ar
rosalind.info
Problem
To model the Hardy-Weinberg principle, assume that we have a population of NN diploid individuals. If an allele is in genetic equilibrium, then because mating is random, we may view the 2N2N chromosomes as receiving their alleles uniformly. In other words, if there are mm dominant alleles, then the probability of a selected chromosome exhibiting the dominant allele is simply p=m2Np=m2N.
Because the first assumption of genetic equilibrium states that the population is so large as to be ignored, we will assume that NN is infinite, so that we only need to concern ourselves with the value of pp.
Given: An array AA for which A[k]A[k] represents the proportion of homozygous recessive individuals for the kk-th Mendelian factor in a diploid population. Assume that the population is in genetic equilibrium for all factors.
Return: An array BB having the same length as AA in which B[k]B[k] represents the probability that a randomly selected individual carries at least one copy of the recessive allele for the kk-th factor.
Sample Dataset
0.1 0.25 0.5
Sample Output
0.532 0.75 0.914
이 문제는 순종 열성 유전자형을 지닌 인구의 비율로 전체 인구 중 열성 대립유전자를 지닌 사람의 비율을 구하는 문제이다. 이 문제를 풀기 위해서는 하디-바인베르크 법칙에 대해서 얼추 알아야한다.
하디-바인베르크 법칙은 쉽게 말하자면 특별한 일이 없다면 유전자풀의 비율이 변하지 않는다는 법칙이다. 이를 수학적으로 증명할 수 있다. 우성 대립유전자A의 비율을 p, 열성 대립유전자a의 비율을 q라 하고 p+q=1이다.
이때 1번의 완전랜덤한 교미가 일어난다면, 아래와 같은 유전형질로 나타날 것이다.
|
A
|
a
|
A
|
AA
|
Aa
|
a
|
Aa
|
aa
|
이 표의 유전자형의 확률을 구하면 AA(p^2),Aa(2*pq),aa(q^2)이다. 이때 A의 유전자비율은 AA와 Aa중 절반이므로 p^2+1/2 * 2*pq=p(p+q) = p이다. 똑같이 a의 유전자비율은 Aa중 절반과 aa이므로 q^2+1/2 *2*pq = q(q+p) = q이다. 이와 같이와같이 완전랜덤하게 교배를 한다면 A와a의 유전자 비율이 몇 세대를 걸쳐도 변하지 않는다는 것을 알 수 있다.
다시 문제로 돌아가보자. 이제는 단순한 산수 문제가 되었다. 이 문제에서는 열성 동형접합의 유전자형의 비율을 실수 n으로 알려주었다. 위의 표에서는 이는 aa의 비율을 알려준것이다. 그러므로 q^2이 주어진것이다. 그러므로 q=n^1/2이다. 그리고 우리가 구해야할 것은 Aa와aa의 비율이므로 2pq+q^2이다. 2pq+q^2은 1-p^2과 동일하다. p=1-q이므로 p=1-n^1/2이다. 1-p^2 = 2*n^1/2 - n이다.
import numpy as np
if __name__ == '__main__':
with open(r"파일경로",'r') as f:
A = list(map(float,next(f).rstrip().split()))
B=[]
for n in A:
B.append(round((2*(n**(0.5))-n),3))
with open(r"파일경로",'w') as wf:
print(*B,file=wf)
'문제해결(PS) > ROSALIND' 카테고리의 다른 글
Counting Optimal Alignments (0) | 2024.11.16 |
---|---|
Creating a Character Table from Genetic Strings (2) | 2024.11.11 |
Wobble Bonding and RNA Secondary Structures (0) | 2024.11.09 |
Newick Format with Edge Weights (1) | 2024.11.09 |
Finding the Longest Multiple Repeat (1) | 2024.11.07 |