Example #1
0
func main() {
	flag.Parse()
	size, _ := strconv.Atoi(flag.Arg(0))

	br := bufio.NewReader(os.Stdin)

	line, _ := br.ReadString('\n')
	taxa := strings.Fields(line)

	taxaToKeep := taxa[:size]
	taxaMap := map[string]bool{}
	for _, taxon := range taxaToKeep {
		taxaMap[taxon] = true
	}

	line, _ = br.ReadString('\n')
	t1, _ := tree.ReadNewick(strings.NewReader(line))
	s1 := tree.CollapseUnrootedBinary(t1, taxaMap)

	line, _ = br.ReadString('\n')
	t2, _ := tree.ReadNewick(strings.NewReader(line))
	s2 := tree.CollapseUnrootedBinary(t2, taxaMap)

	for _, taxon := range taxaToKeep {
		fmt.Printf("%v ", taxon)
	}
	fmt.Println()
	s1.WriteNewick(os.Stdout)
	fmt.Println()
	s2.WriteNewick(os.Stdout)
	fmt.Println()
}
Example #2
0
func main() {
	br := bufio.NewReader(os.Stdin)

	line, _ := br.ReadString('\n')
	taxa := strings.Fields(line)
	taxaInv := map[string]int{}
	for i, taxon := range taxa {
		taxaInv[taxon] = i
	}

	line, _ = br.ReadString('\n')
	t1, _ := tree.ReadNewick(strings.NewReader(line))
	line, _ = br.ReadString('\n')
	t2, _ := tree.ReadNewick(strings.NewReader(line))

	splits1 := phylo.Splits(t1, taxaInv)
	splits2 := phylo.Splits(t2, taxaInv)
	normalize(splits1)
	normalize(splits2)

	m1 := map[string]bool{}
	for _, a := range splits1 {
		m1[string(a)] = true
	}

	shared := 0
	for _, a := range splits2 {
		if m1[string(a)] {
			shared++
		}
	}

	d := 2 * (len(taxa) - 3 - shared)
	fmt.Println(d)
}
Example #3
0
func main() {
	verify := flag.Bool("verify", false, "Check the distance for correctness")
	memprof := flag.String("memprof", "", "Write memory profile to this file")
	flag.Parse()

	br := bufio.NewReader(os.Stdin)

	line, _ := br.ReadString('\n')
	taxa := strings.Fields(line)
	taxaInv := map[string]int{}
	for i, taxon := range taxa {
		taxaInv[taxon] = i
	}

	line, _ = br.ReadString('\n')
	t1, err := tree.ReadNewick(strings.NewReader(line))
	if err != nil {
		panic(err)
	}
	line, _ = br.ReadString('\n')
	t2, err := tree.ReadNewick(strings.NewReader(line))
	if err != nil {
		panic(err)
	}

	d := phylo.QuartetDistance(t1, t2, len(taxa))
	fmt.Println(d)

	if *verify {
		d2 := distanceFromSplits(t1, t2, taxaInv)
		fmt.Println("From splits:", d2)
		if d == d2 {
			fmt.Println("ok")
		} else {
			fmt.Println("mismatch")
			os.Exit(1)
		}
	}

	if *memprof != "" {
		f, err := os.Create(*memprof)
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		pprof.Lookup("heap").WriteTo(f, 0)
	}
}
Example #4
0
func main() {
	br := bufio.NewReader(os.Stdin)

	for {
		input, err := br.ReadString(';')
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatal(err)
		}
		t, err := tree.ReadNewick(strings.NewReader(input))
		if err != nil {
			log.Fatal(err)
		}
		_, _ = br.ReadString('\n')

		line, err := br.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}
		labels := strings.Fields(line)
		fmt.Print(t.Distance(labels[0], labels[1]), " ")

		buf, _ := br.Peek(1)
		if len(buf) > 0 && buf[0] == '\n' {
			_, _ = br.ReadByte()
		}
	}
	fmt.Println()
}
Example #5
0
func main() {
	br := bufio.NewReader(os.Stdin)

	_, _ = br.ReadString('\n')

	t, _ := tree.ReadNewick(br)

	countLeaves(t)
	e := tree.Edge{t, 0}
	_, q := countPQ(e, 0, 0)
	fmt.Println(q)
}
Example #6
0
func main() {
	br := bufio.NewReader(os.Stdin)

	line, _ := br.ReadString('\n')
	t, err := tree.ReadNewick(strings.NewReader(line))
	if err != nil {
		log.Fatal(err)
	}

	fasta, err := gene.ReadAllFasta(br)
	if err != nil {
		log.Fatal(err)
	}

	for _, f := range fasta {
		dna[f.Description] = f.Data
	}
	n = len(fasta[0].Data)

	d := bestDistances(t)
	where := make([]int32, n)
	total := float32(0)
	for i := 0; i < n; i++ {
		bestDist := d[i][0]
		where[i] = 0
		for j := int32(1); j < 5; j++ {
			if d[i][j] < bestDist {
				bestDist = d[i][j]
				where[i] = j
			}
		}
		total += bestDist
	}

	fmt.Println(total)
	collectBestDna(t, where)
}
Example #7
0
func main() {
	pedigree, _ := tree.ReadNewick(os.Stdin)

	fmt.Println(genotypeDistribution(pedigree))
}