コード例 #1
0
ファイル: dna.go プロジェクト: dbarabanov/rosalind
//Rosalind_0498 Rosalind_0442
//Rosalind_0498 Rosalind_2391
//Rosalind_2391 Rosalind_2323
func overlapGraph(filename string) (graph string) {
	k := 3
	reads := util.ReadFasta(filename)
	prefixes := make(map[string][]string)
	for id, seq := range reads {
		prefix := seq[:k]
		prefixes[prefix] = append(prefixes[prefix], id)
	}
	matches := make(map[string]struct{})
	for id, seq := range reads {
		suffix := seq[len(seq)-3:]
		for _, match := range prefixes[suffix] {
			if id != match {
				//matches[id] = match
				//matches += id + " " + match + "\n"
				matches[id+" "+match] = struct{}{}
			}
		}
	}
	var keys []string
	for k := range matches {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	out := ""
	for _, k := range keys {
		out += k + "\n"
	}
	return out
}
コード例 #2
0
ファイル: dna.go プロジェクト: dbarabanov/rosalind
//ATGCAACT
//A: 5 1 0 0 5 5 0 0
//C: 0 0 1 4 2 0 6 1
//G: 1 1 6 3 0 1 0 0
//T: 1 5 0 0 0 1 1 6
func consensusAndProfile(filename string) (result string) {
	reads := util.ReadFasta(filename)
	//fmt.Printf("reads: %v\n", reads)
	letters := []rune{'A', 'C', 'G', 'T'}

	var profile map[rune][]int
	var rowlen int
	for _, seq := range reads {
		rowlen = len(seq)
		if profile == nil {
			profile = map[rune][]int{'A': make([]int, rowlen), 'T': make([]int, rowlen), 'G': make([]int, rowlen), 'C': make([]int, rowlen)}
		}
		for i, l := range seq {
			profile[l][i]++
		}
	}

	var consensus []rune
	for i := range profile['A'] {
		var winner rune
		maxScore := 0
		for _, k := range letters {
			if profile[k][i] >= maxScore {
				winner = k
				maxScore = profile[k][i]
			}
		}
		consensus = append(consensus, winner)
	}

	result = string(consensus) + "\n"
	for _, l := range letters {
		result += string(l) + ": " + strings.Trim(fmt.Sprintf("%v", profile[l]), "[]") + "\n"
	}
	//ioutil.WriteFile("test_data/consensusAndProfile.out", []byte(result), 0644)

	return result
}