Skip to content

Commit

Permalink
fix err messages, add basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
TwFlem committed Jan 3, 2024
1 parent 94f2a15 commit 1cc3755
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bwt/bitvector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bwt

import (
"fmt"
"math"
)

Expand Down Expand Up @@ -62,7 +63,8 @@ func (b bitvector) setBit(i int, val bool) {

func (b bitvector) checkBounds(i int) {
if i >= b.len() || i < 0 {
panic("better out of bounds message")
msg := fmt.Sprintf("access of %d is out of bounds for bitvector with length %d", i, b.len())
panic(msg)
}
}

Expand Down
3 changes: 2 additions & 1 deletion bwt/bwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ func (bwt BWT) lookupSkipByOffset(offset int) skipEntry {
return bwt.firstColumnSkipList[skipIndex]
}
}
panic("figure out what to do here")
msg := fmt.Sprintf("could not find the skip entry that falls within the range of the skip column at a given offset. range: [0, %d) offset: %d", bwt.getLenOfOriginalStringWithNullChar(), offset)
panic(msg)
}

func (bwt BWT) getLenOfOriginalStringWithNullChar() int {
Expand Down
22 changes: 22 additions & 0 deletions bwt/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ import (
"golang.org/x/exp/slices"
)

// This example shows how BWT can be used for exact pattern
// matching by returning the offsets at which the pattern exists.
// This can be useful for alignment when you need need to reduce
// the memory footprint of a reference sequence without loosing
// any data since BWT is a lossless compression.
func ExampleBWT_basic() {
inputSequence := "AACCTGCCGTCGGGGCTGCCCGTCGCGGGACGTCGAAACGTGGGGCGAAACGTG"

bwt, err := bwt.New(inputSequence)
if err != nil {
log.Fatal(err)
}

offsets, err := bwt.Locate("GCC")
if err != nil {
log.Fatal(err)
}
slices.Sort(offsets)
fmt.Println(offsets)
// Output: [5 17]
}

func ExampleBWT_Count() {
inputSequence := "AACCTGCCGTCGGGGCTGCCCGTCGCGGGACGTCGAAACGTGGGGCGAAACGTG"

Expand Down

0 comments on commit 1cc3755

Please sign in to comment.