Example #1
0
func simusome(begin, end int, ch chan Results) {
	for i := begin; i < end; i++ {
		w := coals.NewWFPopulation(size, sample, length, mutation, transfer, fragment)
		w.Seed(i)
		w.Backtrace()
		seqs := w.Fortrace()
		diffmatrix := [][]int{}
		sample := w.SampleSize
		for j := 0; j < sample; j++ {
			for k := j + 1; k < sample; k++ {
				diff := []int{}
				for h := 0; h < length; h++ {
					if seqs[j][h] != seqs[k][h] {
						diff = append(diff, h)
					}
				}
				diffmatrix = append(diffmatrix, diff)
			}
		}

		cmatrix := covs.NewCMatrix(len(diffmatrix), length, diffmatrix)
		ks, vd := cmatrix.D()
		scovs, rcovs, xyPL, xsysPL, smXYPL := cmatrix.CovCircle(maxl)
		results := Results{
			ks:     ks,
			vd:     vd,
			scovs:  scovs,
			rcovs:  rcovs,
			xyPL:   xyPL,
			xsysPL: xsysPL,
			smXYPL: smXYPL,
		}
		ch <- results
	}
}
Example #2
0
func main() {
	means := make([][]*desc.Mean, 5)
	sds := make([][]*desc.StandardDeviation, 5)
	for i := 0; i < 5; i++ {
		means[i] = make([]*desc.Mean, maxl)
		sds[i] = make([]*desc.StandardDeviation, maxl)
		for j := 0; j < maxl; j++ {
			means[i][j] = desc.NewMean()
			sds[i][j] = desc.NewStandardDeviationWithBiasCorrection()
		}
	}

	dfile, err := os.Create(prefix + "_d.csv")
	if err != nil {
		panic(err)
	}
	defer dfile.Close()

	dfile.WriteString(fmt.Sprintf("#size: %d\n", size))
	dfile.WriteString(fmt.Sprintf("#sample: %d\n", sample))
	dfile.WriteString(fmt.Sprintf("#length: %d\n", length))
	dfile.WriteString(fmt.Sprintf("#fragment: %d\n", fragment))
	dfile.WriteString(fmt.Sprintf("#repeats: %d\n", repeats))
	dfile.WriteString(fmt.Sprintf("#maxl: %d\n", maxl))
	dfile.WriteString(fmt.Sprintf("#mutation: %g\n", mutation))
	dfile.WriteString(fmt.Sprintf("#transfer: %g\n", transfer))
	dfile.WriteString("#ks, vd\n")

	runtime.GOMAXPROCS(runtime.NumCPU())

	t0 := time.Now()
	for c := 0; c < repeats; c++ {
		w := coals.NewWFPopulation(size, sample, length, mutation, transfer, fragment)
		w.Seed(c)
		w.Backtrace()
		seqs := w.Fortrace()
		diffmatrix := [][]int{}
		for i := 0; i < sample; i++ {
			for j := i + 1; j < sample; j++ {
				diff := []int{}
				for k := 0; k < length; k++ {
					if seqs[i][k] != seqs[j][k] {
						diff = append(diff, k)
					}
				}
				diffmatrix = append(diffmatrix, diff)
			}
		}

		cmatrix := covs.NewCMatrix(len(diffmatrix), length, diffmatrix)
		ks, vd := cmatrix.D()
		dfile.WriteString(fmt.Sprintf("%g,%g\n", ks, vd))

		scovs, rcovs, xyPL, xsysPL, smXYPL := cmatrix.CovCircle(maxl)
		for l := 0; l < maxl; l++ {
			means[0][l].Increment(scovs[l])
			means[1][l].Increment(rcovs[l])
			means[2][l].Increment(xyPL[l])
			means[3][l].Increment(xsysPL[l])
			means[4][l].Increment(smXYPL[l])

			sds[0][l].Increment(scovs[l])
			sds[1][l].Increment(rcovs[l])
			sds[2][l].Increment(xyPL[l])
			sds[3][l].Increment(xsysPL[l])
			sds[4][l].Increment(smXYPL[l])
		}

		if (c+1)%(repeats/100) == 0 {
			t1 := time.Now()
			fmt.Printf("%d%%,%v\n", (c+1)/(repeats/100), t1.Sub(t0))
			covfile, err := os.Create(prefix + "_covs.csv")
			if err != nil {
				fmt.Println(err)
			}

			covfile.WriteString(fmt.Sprintf("#size: %d\n", size))
			covfile.WriteString(fmt.Sprintf("#sample: %d\n", sample))
			covfile.WriteString(fmt.Sprintf("#length: %d\n", length))
			covfile.WriteString(fmt.Sprintf("#fragment: %d\n", fragment))
			covfile.WriteString(fmt.Sprintf("#repeats: %d\n", repeats))
			covfile.WriteString(fmt.Sprintf("#maxl: %d\n", maxl))
			covfile.WriteString(fmt.Sprintf("#mutation: %g\n", mutation))
			covfile.WriteString(fmt.Sprintf("#transfer: %g\n", transfer))
			covfile.WriteString("#dist, scov, rcov, xy, xsys, smxy, scov_sd, rcov_sd, xy_sd, xsys_sd, smxy_sd\n")

			for i := 0; i < maxl; i++ {
				covfile.WriteString(fmt.Sprintf("%d,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g\n",
					i,
					means[0][i].GetResult(),
					means[1][i].GetResult(),
					means[2][i].GetResult(),
					means[3][i].GetResult(),
					means[4][i].GetResult(),
					sds[0][i].GetResult()/math.Sqrt(float64(repeats)),
					sds[1][i].GetResult()/math.Sqrt(float64(repeats)),
					sds[2][i].GetResult()/math.Sqrt(float64(repeats)),
					sds[3][i].GetResult()/math.Sqrt(float64(repeats)),
					sds[4][i].GetResult()/math.Sqrt(float64(repeats)),
				))
			}

			covfile.Close()
		}
	}

	covfile, err := os.Create(prefix + "_covs.csv")
	if err != nil {
		fmt.Println(err)
	}
	defer covfile.Close()

	covfile.WriteString(fmt.Sprintf("#size: %d\n", size))
	covfile.WriteString(fmt.Sprintf("#sample: %d\n", sample))
	covfile.WriteString(fmt.Sprintf("#length: %d\n", length))
	covfile.WriteString(fmt.Sprintf("#fragment: %d\n", fragment))
	covfile.WriteString(fmt.Sprintf("#repeats: %d\n", repeats))
	covfile.WriteString(fmt.Sprintf("#maxl: %d\n", maxl))
	covfile.WriteString(fmt.Sprintf("#mutation: %g\n", mutation))
	covfile.WriteString(fmt.Sprintf("#transfer: %g\n", transfer))
	covfile.WriteString("#dist, scov, rcov, xy, xsys, smxy, scov_sd, rcov_sd, xy_sd, xsys_sd, smxy_sd\n")

	for i := 0; i < maxl; i++ {
		covfile.WriteString(fmt.Sprintf("%d,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g\n",
			i,
			means[0][i].GetResult(),
			means[1][i].GetResult(),
			means[2][i].GetResult(),
			means[3][i].GetResult(),
			means[4][i].GetResult(),
			sds[0][i].GetResult()/math.Sqrt(float64(repeats)),
			sds[1][i].GetResult()/math.Sqrt(float64(repeats)),
			sds[2][i].GetResult()/math.Sqrt(float64(repeats)),
			sds[3][i].GetResult()/math.Sqrt(float64(repeats)),
			sds[4][i].GetResult()/math.Sqrt(float64(repeats)),
		))
	}
}