Exemplo n.º 1
0
func printAllSubs(treeFile string) {
	// Read the tree and get the sublineages.
	tr, err := os.Open(treeFile)
	defer tr.Close()
	if err != nil {
		log.Fatalf("subs: %v", err)
	}

	tree, err := devpat.ReadTree(tr)
	if err != nil {
		log.Fatalf("subs: reading tree: %v", err)
	}

	ts := devpat.AllSublineages(tree)
	for _, t := range ts {
		cs := make([]string, 0)
		for c := range devpat.GetCells(t) {
			cs = append(cs, c)
		}
		fmt.Println(strings.Join(cs, ","))
	}
}
Exemplo n.º 2
0
func fates(treeFile, xdatFile, markerFile string, cutoff, p float64, min int, all bool) {
	tr, err := os.Open(treeFile)
	defer tr.Close()
	if err != nil {
		log.Fatalf("fates: %v", err)
	}

	xs, err := devpat.ReadXDat(xdatFile)
	if err != nil {
		log.Fatalf("fates: %v", err)
	}

	mf, err := os.Open(markerFile)
	defer mf.Close()
	if err != nil {
		log.Fatalf("fates: %v", err)
	}

	input := bufio.NewScanner(mf)
	markers := make([]string, 0)
	for input.Scan() {
		markers = append(markers, input.Text())
	}

	if err := input.Err(); err != nil {
		log.Fatalf("fates: %v", err)
	}

	tree, err := devpat.ReadTree(tr)
	if err != nil {
		log.Fatalf("fates: reading tree: %v", err)
	}

	var ts []*devpat.Tree
	if all {
		ts = devpat.AllSublineages(tree)
	} else {
		ts = devpat.Sublineages(tree, p, min)
	}
	fates := devpat.Fates(ts, xs, markers, cutoff)
	//	devpat.PrintFates(fates)

	out, err := os.Create("fates.csv")
	defer out.Close()
	if err != nil {
		log.Fatalf("fates: %v", err)
	}
	devpat.WriteFates(out, fates)

	out, err = os.Create("sublineages.csv")
	defer out.Close()
	if err != nil {
		log.Fatalf("fates: %v", err)
	}

	if _, err := fmt.Fprintln(out, "cell,sublineage"); err != nil {
		log.Fatalf("fates: %v", err)
	}

	for i, t := range ts {
		for c := range devpat.GetCells(t) {
			_, err = fmt.Fprintf(out, "%s,%d\n", c, i)
			if err != nil {
				log.Fatalf("fates: %v", err)
			}
		}
	}
}