Exemple #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, ","))
	}
}
Exemple #2
0
func codev(treeFile, cellTypeFile string, p float64, min int, notall bool) devpat.CoTypes {
	// Read the tree and get the sublineages.
	tr, err := os.Open(treeFile)
	if err != nil {
		log.Fatalf("codev: %v", err)
	}
	defer tr.Close()

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

	var ts []*devpat.Tree
	if notall {
		ts = devpat.Sublineages(tree, p, min)
	} else {
		ts = devpat.AllSublineages(tree)
	}

	// Get the cell to CellType mapping.
	cr, err := os.Open(cellTypeFile)
	if err != nil {
		log.Fatalf("codev: %v", err)
	}
	defer cr.Close()

	cts, err := devpat.ReadCellTypes(cr)
	if err != nil {
		log.Fatalf("codev: reading cell types: %v", err)
	}

	// Write the CellTypes in each sublineage.
	var subFile string
	if notall {
		subFile = fmt.Sprintf("sublineages_%.0f_%d.csv", p, min)
	} else {
		subFile = "sublineages.csv"
	}
	subf, err := os.Create(subFile)
	if err != nil {
		log.Fatalf("codev: %v", err)
	}
	defer subf.Close()

	err = devpat.WriteSublineageCellTypes(subf, ts, cts)
	if err != nil {
		log.Fatalf("codev: writing sublineage cell types: %v", err)
	}

	// Read the CellType sublineages.
	subr, err := os.Open(subFile)
	if err != nil {
		log.Fatalf("codev: %v", err)
	}
	defer subr.Close()

	subs, err := devpat.ReadCellTypeSublineages(subr)
	if err != nil {
		log.Fatalf("codev: reading cell type sublineages: %v", err)
	}

	return devpat.CodevScores(subs)
}
Exemple #3
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)
			}
		}
	}
}