/*
Package dna implements various DNA analyzing functions.
*/
package dna
import "errors"
// Histogram is a mapping from nucleotide to its count in given DNA.
type Histogram map[rune]int
// DNA is a series of nucleotides.
type DNA string
// Counts generates a histogram of valid nucleotides in the given DNA.
// Returns an error if d contains an invalid nucleotide.
func (d DNA) Counts() (Histogram, error) {
var hist = Histogram{
'A': 0,
'G': 0,
'C': 0,
'T': 0,
}
for _, nucleotide := range d {
_, exists := hist[nucleotide]
if !exists {
return hist, errors.New("Unrecognized nucleotide")
}
hist[nucleotide]++
}
return hist, nil
}