Esempio n. 1
0
func mutateAll(seqMap map[int][]byte, lambda float64, l int, rng *randist.RNG) {
	for _, seq := range seqMap {
		count := randist.PoissonRandomInt(rng, lambda)
		for i := 0; i < count; i++ {
			idx := randist.UniformRandomInt(rng, l)
			a := NucleicAcids[randist.UniformRandomInt(rng, len(NucleicAcids))]
			for a == seq[idx] {
				a = NucleicAcids[randist.UniformRandomInt(rng, len(NucleicAcids))]
			}
			seq[idx] = a
		}
	}
}
Esempio n. 2
0
// evolutionary operators: mutation and transfer
func (pop *SeqPop) manipulate() {
	// calculate the number of events, which is poisson distribution
	lambda := float64(pop.Size) * float64(pop.Length) * (pop.Mutation + pop.Transfer)
	if pop.ExpTime {
		t := randist.ExponentialRandomFloat64(pop.rng, 1.0)
		lambda = t * lambda
	}
	k := randist.PoissonRandomInt(pop.rng, lambda)
	// given k, the number of mutations or transfers are following Binormial distribution.
	// therefore, we can do k times of Bernoulli test
	for i := 0; i < k; i++ {
		// determine whether this event is a mutation or transfer
		ratio := pop.Mutation / (pop.Mutation + pop.Transfer) // the ratio of mutation
		r := randist.UniformRandomFloat64(pop.rng)            // randomly produce a probability
		if r <= ratio {                                       // determin whether is a mutation or transfer
			pop.mutate()
		} else {
			pop.transfer()
		}
	}
}