문제해결(PS)/ROSALIND

Independent Segregation of Chromosomes

곰탱이장 2024. 11. 2. 18:47

https://rosalind.info/problems/indc/

 

ROSALIND | Independent Segregation of Chromosomes

It appears that your browser has JavaScript disabled. Rosalind requires your browser to be JavaScript enabled. Independent Segregation of Chromosomes solved by 939 2012년 12월 4일 7:08:03 오전 by Rosalind Team Topics: Heredity, Probability Mendel's Wo

rosalind.info

Problem

Consider a collection of coin flips. One of the most natural questions we can ask is if we flip a coin 92 times, what is the probability of obtaining 51 "heads", vs. 27 "heads", vs. 92 "heads"?

Each coin flip can be modeled by a uniform random variable in which each of the two outcomes ("heads" and "tails") has probability equal to 1/2. We may assume that these random variables are independent (see “Independent Alleles”); in layman's terms, the outcomes of the two coin flips do not influence each other.

A binomial random variable XX takes a value of kk if nn consecutive "coin flips" result in kk total "heads" and nkn−k total "tails." We write that XBin(n,1/2)X∈Bin(n,1/2).

Given: A positive integer n50n≤50.

Return: An array AA of length 2n2n in which A[k]A[k] represents the common logarithm of the probability that two diploid siblings share at least kk of their 2n2n chromosomes (we do not consider recombination for now).

Sample Dataset

5

Sample Output

0.000 -0.004 -0.024 -0.082 -0.206 -0.424 -0.765 -1.262 -1.969 -3.010

 

 이 문제는 2*n개의 염색체를 가진 두 형제자매가 같은 염색체를 적어도 몇개 공유할 확률을 저장한 배열 A를 출력하는 문제이다. binominal random variable(이분확률변수?)에서는 사건이 일어날 확률이 0.5이다. 그러므로 예를 들어 동전 던지기에서 6번 던져 3번 앞이 나올 확률은 6C3 * (0.5)**6같은 식으로 나타낼 수 있다.

 배열 A는 1부터 2*n까지 있으므로 적어도 1개 있을 확률부터 구하는 것보다는 2*n이 같을 확률 즉 모두 같을 확률에서 2*n-1이 같을 확률, 2*n-2이 같을 확률,,,,,,1이 같을 확률을 차례대로 더해서 구하는 것이 구하기 편리하다.

 이를 그대로 파이썬의 numpy,math 모듈을 사용하여 구하면 된다.

import numpy as np
import math
n=int(input())

Pr=0
p=0.5
A=[]
for k in range(2*n,0,-1):
    Pr+=math.factorial(2*n)/(math.factorial(k)*math.factorial(2*n-k))*np.power(p,k)*np.power(1-p,2*n-k)
    A.append(round(np.log10(Pr),3))

f=open(r"파일경로",'w')
for i in A[::-1]:
    print(i,end=' ',file=f)

'문제해결(PS) > ROSALIND' 카테고리의 다른 글

Finding the Longest Multiple Repeat  (1) 2024.11.07
Finding Disjoint Motifs in a Gene  (1) 2024.11.03
Inferring Peptide from Full Spectrum  (0) 2024.11.02
Constructing a De Bruijn Graph  (1) 2024.10.20
Creating a Character Table  (1) 2024.10.19