func main() { saveto := util.CreateFile(util.Arg(0)) defer saveto.Close() w := func(format string, v ...interface{}) { _, err := fmt.Fprintf(saveto, format, v...) util.Assert(err) } var fmats []*bufio.Reader for _, fmat := range util.Args()[1:] { fmats = append(fmats, bufio.NewReader(util.OpenFile(fmat))) } LOOP: for { var columns int scores := make([][]float64, len(fmats)) // matrix -> fields -> sas score for i, fmat := range fmats { line, err := fmat.ReadBytes('\n') if len(line) == 0 && err == io.EOF { break LOOP } else if err != io.EOF { util.Assert(err) } fields := bytes.Fields(line) columns = len(fields) scores[i] = make([]float64, columns) for j, sas := range fields { scores[i][j], err = strconv.ParseFloat(string(sas), 64) util.Assert(err) } } before := "" for j := 0; j < columns; j++ { best := scores[0][j] for i := 1; i < len(scores); i++ { if scores[i][j] < best { best = scores[i][j] } } if best == 0 { w("%s0", before) } else { w("%s%f", before, best) } before = " " } w("\n") } }
func main() { if len(util.FlagCpuProf) > 0 { f := util.CreateFile(util.FlagCpuProf) pprof.StartCPUProfile(f) defer f.Close() defer pprof.StopCPUProfile() } vectors := readVectors(util.Arg(1)) groups := readCathGroups(util.Args()[2:]) out := util.CreateFile(util.Arg(0)) defer out.Close() pf := func(format string, v ...interface{}) { // fmt.Printf(format, v...) fmt.Fprintf(out, format, v...) } type labeledPval struct { Name1, Name2 string Pval float32 } b := stdb(vectors, groups) pairs := combinations(len(groups)) dopairs, pvals := make(chan pair), make(chan labeledPval) wg := new(sync.WaitGroup) for i := 0; i < util.FlagCpu; i++ { wg.Add(1) go func() { for p := range dopairs { g1, g2 := groups[p.i], groups[p.j] b1, b2 := b[p.i], b[p.j] bm1, bm2 := bmean(b1, b2) bw := delta(bm1, bm2) randws := make([]float32, 1000) for i := range randws { randws[i] = delta(shuffle_mean_rows(b1, b2)) } bigger := 0 for _, rw := range randws { if rw >= bw { bigger++ } } pval := float32(bigger) / float32(len(randws)) pvals <- labeledPval{g1.Name, g2.Name, pval} } wg.Done() }() } done := make(chan struct{}) go func() { sig, cutoff := 0, 0.05/float32(len(pairs)) for pval := range pvals { if pval.Pval < cutoff { sig++ } pf("%s\t%s\t%f\n", pval.Name1, pval.Name2, pval.Pval) } pf("significant\t%d/%d\t(cutoff: %f)\n", sig, len(pairs), cutoff) done <- struct{}{} }() for _, p := range pairs { dopairs <- p } close(dopairs) wg.Wait() close(pvals) <-done }
func main() { outDir := util.Arg(0) fasInps := util.Args()[1:] util.Assert(os.MkdirAll(outDir, 0777)) fastaChan := make(chan string) wg := new(sync.WaitGroup) for i := 0; i < max(1, runtime.GOMAXPROCS(0)); i++ { go func() { wg.Add(1) for fasta := range fastaChan { util.Verbosef("Computing map for '%s'...", fasta) fmap := util.GetFmap(fasta) outF := path.Join(outDir, fmt.Sprintf("%s.fmap", fmap.Name)) util.FmapWrite(util.CreateFile(outF), fmap) } wg.Done() }() } for _, fasta := range fasInps { fastaChan <- fasta } close(fastaChan) wg.Wait() }