Independent Alleles

A problem from rosalind “Bioinformatics Stronghold” category, Probability Calculation

  • A problem from rosalind “Bioinformatics Stronghold” category
    Rosalind Problem Link

  • Description

    • 0th generation: AaBb
    • 1st generation: AaBb (0th generation) x AaBb
    • nth generation: ? ((n-1)th generation) x AaBb
    • Each individual gets 2 offsprings
    • Goal: The probability that at least N Aa Bb organisms will belong to the kth generation
    • The genes satisfy the law of independent assorment

My Solution

  • Sketch
    • AaBb (0th generation) x AaBb
      • Offspring genotype ratio


                    AA       Aa      aa
              BB     1        2       1
              Bb     2        4       2
              bb     1        2       1
        
    • Critical Point: In all of generations, the genotype ratio is maintained
      • That is, AaBb’s ratio in all of generations is 4/16 (0.75)
      • Reason
        • The ingredient (gamete’s genotype) for making offspring’s genotype in 0th generation is AA, Ab, aB, ab
        • The ratio of each ingredient is maintained because the new ingredient is supplied as the same amount with AaBb (0th generation)
        • For the same reason
          • When 0th generation’s genotype is α and repeat to do cross with genotype α -> First offspring’s genotype ratio is maintained in all of generations
    • “The probability that at least N Aa Bb organisms will belong to the kth generation”
      • Number of offsprings in kth generation = 2k
      • If the number of AaBb is n in kth generation
        • Probability = 2kCn * 0.75(2k - n) * 0.25n
      • Answer_prob = 1 - 2kC0 * 0.75(2k - 0) * 0.250 - 2kC1 * 0.75(2k - 1) * 0.251 - 2kC2 * 0.75(2k - 2) * 0.252 - ….. - 2kCN - 1 * 0.75(2k - (N - 1)) * 0.25N - 1


  • Code


def factorial(n):
    if n == 1 or n == 0:
        return 1
    return n * factorial(n - 1)

def combination(n, r):
    return factorial(n)/(factorial(r) * factorial(n - r))

name = input()
f = open(name, 'r')
k, N = list(map(int, f.readline().split()))

prob = 1
num = 2 ** k

for i in range(N):
    sub_prob = combination(num, i) * (0.75 ** (num - i)) * (0.25 ** i)
    prob -= sub_prob

print(prob)

© 2017. All rights reserved.

Powered by Hydejack v조현진