Example #1
0
func main() {
	// use all cpus
	runtime.GOMAXPROCS(runtime.NumCPU())

	// population paramters
	length := 1000      // genome length = 1000
	mutation := 0.00001 // mutation rate = 1e-5
	transfer := 0.0     // transfer rate = 0
	fragment := 0       // transferred length = 0

	// simulation parameters
	samplesize := 100
	numofgen := 100000

	// population size array
	sizearray := []int{100, 1000, 10000}
	for _, size := range sizearray {
		// population
		pop := fwd.NewSeqPop(size, length, mutation, transfer, fragment)

		// result files
		ksname := fmt.Sprintf("ks_size_%d.csv", size)
		ksfile, err := os.Create(ksname)
		if err != nil {
			panic(err)
		}
		vdname := fmt.Sprintf("vd_size_%d.csv", size)
		vdfile, err := os.Create(vdname)
		if err != nil {
			panic(err)
		}

		// info file
		infoname := fmt.Sprintf("ks_size_%d.txt", size)
		infofile, err := os.Create(infoname)
		if err != nil {
			panic(err)
		}
		infofile.WriteString(fmt.Sprintf("Size = %d\n", pop.Size))
		infofile.WriteString(fmt.Sprintf("Length = %d\n", pop.Length))
		infofile.WriteString(fmt.Sprintf("Mutation = %g\n", pop.Mutation))

		// population evolve
		for i := 0; i < numofgen; i++ {
			pop.Evolve()
			sample := fwd.Sample(pop.Genomes, samplesize)
			dmatrix := fwd.GenerateDistanceMatrix(sample)
			cmatrix := covs.NewCMatrix(samplesize, length, dmatrix)
			ks, vd := cmatrix.D()
			ksfile.WriteString(fmt.Sprintf("%g\n", ks))
			vdfile.WriteString(fmt.Sprintf("%g\n", vd))
		}

		// close files
		ksfile.Close()
		vdfile.Close()
		infofile.Close()
	}
}
Example #2
0
func init() {
	//assign flags
	flag.IntVar(&size, "size", 1000, "usage: -size 1000")
	flag.IntVar(&length, "length", 1000, "usage: -length 1000")
	flag.IntVar(&ngen, "ngen", 1000, "usage: -ngen 1000")
	flag.IntVar(&sampleSize, "samplesize", 100, "usage: -samplesize 1000")
	flag.IntVar(&sampleTime, "sampletime", 1, "usage: -sampletime 10")
	flag.IntVar(&fragment, "fragment", 100, "usage: -fragment 1000")
	flag.Float64Var(&mutation, "mutation", 1e-5, "usage: -mutation 1e-5")
	flag.Float64Var(&transfer, "transfer", 0.0, "usage: -transfer 1e-9")
	flag.StringVar(&fname, "fname", "ks", "usage: -fname ks")

	// parse flags
	flag.Parse()

	// construct a population
	pop = fwd.NewSeqPop(size, length, mutation, transfer, fragment)
	// use all the available CPUs
	runtime.GOMAXPROCS(runtime.NumCPU())
}