コード例 #1
0
ファイル: dna.go プロジェクト: dbarabanov/rosalind
func proteinWeight(protein string) (weight float64) {
	weight = 0
	weights := map[byte]float64{'A': 71.03711,
		'C': 103.00919,
		'D': 115.02694,
		'E': 129.04259,
		'F': 147.06841,
		'G': 57.02146,
		'H': 137.05891,
		'I': 113.08406,
		'K': 128.09496,
		'L': 113.08406,
		'M': 131.04049,
		'N': 114.04293,
		'P': 97.05276,
		'Q': 128.05858,
		'R': 156.10111,
		'S': 87.03203,
		'T': 101.04768,
		'V': 99.06841,
		'W': 186.07931,
		'Y': 163.06333}
	for _, aa := range protein {
		weight += weights[byte(aa)]
	}

	return util.Round(weight, 3)
}
コード例 #2
0
ファイル: dna.go プロジェクト: dbarabanov/rosalind
//Return: The probability that at least N Aa Bb organisms will belong to the k-th generation of Tom's family tree (don't count the Aa Bb mates at each level). Assume that Mendel's second law holds for the factors.
func independentAlleles(generations int, n int) (prob float64) {
	var result float64
	total := int(math.Pow(2, float64(generations)))

	for i := n; i <= total; i++ {
		//fmt.Printf("i: %v. choose: %v total: %v\n", i, choose(total, i), total)
		result += float64(choose(total, i)) * math.Pow(0.25, float64(i)) * math.Pow(0.75, float64(total-i))
	}

	return util.Round(result, 3)
}
コード例 #3
0
ファイル: dna.go プロジェクト: dbarabanov/rosalind
//-5.737 -5.217 -5.263 -5.360 -5.958 -6.628 -7.009
func randomStrings(s string, gcContent []float64) (probs []float64) {
	probs = make([]float64, len(gcContent))
	for i, gc := range gcContent {
		for _, l := range s {
			if l == 'C' || l == 'G' {
				probs[i] += math.Log10(gc / 2)
			} else {
				probs[i] += math.Log10((1 - gc) / 2)
			}
		}
		probs[i] = util.Round(probs[i], 3)
	}
	return probs
}
コード例 #4
0
ファイル: dna.go プロジェクト: dbarabanov/rosalind
//0.78333
func probDominant(k int, m int, n int) (prob float64) {
	prob = 1 - (float64(n*(n-1)+n*m)+float64(m*(m-1))/4)/float64((k+m+n)*(k+m+n-1))
	return util.Round(prob, 5)
}