Ejemplo n.º 1
0
func (s *S) TestKmerFrequencies(c *check.C) {
	for k := MinKmerLen; k <= MaxKmerLen; k++ {
		if i, err := New(k, s.Seq); err != nil {
			c.Fatalf("New KmerIndex failed: %v", err)
		} else {
			freqs, ok := i.KmerFrequencies()
			c.Check(ok, check.Equals, true)
			hashFreqs := make(map[string]int)
			for i := 0; i+k <= s.Seq.Len(); i++ {
				hashFreqs[strings.ToLower(string(alphabet.LettersToBytes(s.Seq.Seq[i:i+k])))]++
			}
			for key := range freqs {
				c.Check(freqs[key], check.Equals, hashFreqs[i.Format(key)],
					check.Commentf("key %x, string of %q\n", key, i.Format(key)))
			}
			for key := range hashFreqs {
				if keyKmer, err := i.KmerOf(key); err != nil {
					c.Fatal(err)
				} else {
					c.Check(freqs[keyKmer], check.Equals, hashFreqs[key],
						check.Commentf("keyKmer %x, string of %q, key %q\n", keyKmer, i.Format(keyKmer), key))
				}
			}
		}
	}
}
Ejemplo n.º 2
0
func (s *S) TestKmerPositions(c *check.C) {
	for k := MinKmerLen; k < MaxKmerLen; k++ { // don't test full range to time's sake
		if i, err := New(k, s.Seq); err != nil {
			c.Fatalf("New KmerIndex failed: %v", err)
		} else {
			i.Build()
			hashPos := make(map[string][]int)
			for i := 0; i+k <= s.Seq.Len(); i++ {
				p := strings.ToLower(string(alphabet.LettersToBytes(s.Seq.Seq[i : i+k])))
				hashPos[p] = append(hashPos[p], i)
			}
			pos, ok := i.KmerIndex()
			c.Check(ok, check.Equals, true)
			for p := range pos {
				c.Check(pos[p], check.DeepEquals, hashPos[i.Format(p)])
			}
		}
	}
}