예제 #1
0
파일: coals.go 프로젝트: mingzhi/hgt_old
func NewWFPopulation(size, sample, length int, mutation, transfer float64, tract int) *WFPopulation {
	wf := &WFPopulation{
		Size:           size,
		SampleSize:     sample,
		GenomeLength:   length,
		MutationRate:   mutation,
		TransferRate:   transfer,
		TransferLength: tract,
	}
	wf.rng = randist.NewRNG(randist.MT19937)
	wf.history = NewEvolutionHistory(sample, length)
	return wf
}
예제 #2
0
파일: seq_pop.go 프로젝트: mingzhi/hgt_old
// NewSeqPop returns a population with full sequence genomes
func NewSeqPop(size, length int, mutation, transfer float64, fragment int) *SeqPop {
	// verify population size and genome length
	if size <= 0 || length <= 0 {
		log.Panic("Population size or genome length should be positive!")
	}
	// verify transfer rate and transferred fragment
	if transfer > 0 && fragment <= 0 {
		log.Panic("Transferred fragment should be positive when transfer rate > 0!")
	}

	// construct a population with parameters
	pop := SeqPop{
		Size:     size,
		Length:   length,
		Mutation: mutation,
		Transfer: transfer,
		Fragment: fragment,
	}

	// create random sources
	pop.rng = randist.NewRNG(randist.MT19937)

	// create genomes
	// randomly create a parent sequence
	pop.states = 4 // typical nucleotides, "ATGC"
	refseq := make(Sequence, pop.Length)
	for i := 0; i < len(refseq); i++ {
		refseq[i] = byte(randist.UniformRandomInt(pop.rng, pop.states)) // randomly assign a character
	}
	// copy the parent sequence to every genomes
	pop.Genomes = make([]Sequence, pop.Size)
	for i := 0; i < len(pop.Genomes); i++ {
		pop.Genomes[i] = make(Sequence, pop.Length)
		copy(pop.Genomes[i], refseq)
	}

	return &pop
}