func (s *S) TestKmerKmerUtilities(c *check.C) { for k := MinKmerLen; k <= 8; k++ { // again not testing all exhaustively for kmer := Kmer(0); uint(kmer) <= util.Pow4(k)-1; kmer++ { // Interconversion between string and Kmer s, err := Format(kmer, k, alphabet.DNA) c.Assert(err, check.Equals, nil) rk, err := KmerOf(k, alphabet.DNA.LetterIndex(), s) c.Assert(err, check.Equals, nil) c.Check(rk, check.Equals, kmer) // Complementation dc := ComplementOf(k, ComplementOf(k, kmer)) skmer, _ := Format(kmer, k, alphabet.DNA) sdc, _ := Format(dc, k, alphabet.DNA) c.Check(dc, check.Equals, kmer, check.Commentf("kmer: %s\ndouble complement: %s\n", skmer, sdc)) // GC content ks, _ := Format(kmer, k, alphabet.DNA) gc := 0 for _, b := range ks { if b == 'g' || b == 'c' { gc++ } } c.Check(GCof(k, kmer), check.Equals, float64(gc)/float64(k)) } } }
// Return an estimate of the amount of memory required for the filter. func (p *PALS) filterMemRequired(filterParams *filter.Params) uintptr { words := util.Pow4(filterParams.WordSize) tubeWidth := filterParams.TubeOffset + filterParams.MaxError maxActiveTubes := (p.target.Len()+tubeWidth-1)/filterParams.TubeOffset + 1 tubes := uintptr(maxActiveTubes) * unsafe.Sizeof(tubeState{}) finger := unsafe.Sizeof(uint32(0)) * uintptr(words) pos := unsafe.Sizeof(0) * uintptr(p.target.Len()) return finger + pos + tubes }
// Create a new Kmer Index with a word size k based on sequence func New(k int, s *linear.Seq) (*Index, error) { switch { case k > MaxKmerLen: return nil, ErrKTooLarge case k < MinKmerLen: return nil, ErrKTooSmall case k+1 > s.Len(): return nil, ErrShortSeq case s.Alpha.Len() != 4: return nil, ErrBadAlphabet } ki := &Index{ finger: make([]Kmer, util.Pow4(k)+1), // Need a Tn+1 finger position so that Tn can be recognised k: k, kMask: Kmer(util.Pow4(k) - 1), seq: s, lookUp: s.Alpha.LetterIndex(), indexed: false, } ki.buildKmerTable() return ki, nil }