예제 #1
0
파일: sptd.go 프로젝트: nkitchen/rosalind
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)
}
예제 #2
0
파일: qrtd.go 프로젝트: nkitchen/rosalind
func distanceFromSplits(t1, t2 *tree.Node, taxa map[string]int) int {
	s1 := phylo.Splits(t1, taxa)
	s2 := phylo.Splits(t2, taxa)

	q1 := quartetsFromSplits(s1)
	q2 := quartetsFromSplits(s2)

	shared := 0
	for q := range q1 {
		if q2[q] {
			shared++
		}
	}

	return len(q1) + len(q2) - 2*shared
}