forked from bebop/poly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,843 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# .gitattributes | ||
*justfile linguist-vendored=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ jobs: | |
uses: golangci/[email protected] | ||
with: | ||
version: latest | ||
args: -c .golangci.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fold | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"testing" | ||
) | ||
|
||
func TestResult_MinimumFreeEnergy_LengthZero(t *testing.T) { | ||
result := Result{} // Create a Result instance with empty structs | ||
|
||
expectedEnergy := math.Inf(1) | ||
actualEnergy := result.MinimumFreeEnergy() | ||
|
||
if actualEnergy != expectedEnergy { | ||
t.Errorf("expected energy to be %f, but got %f", expectedEnergy, actualEnergy) | ||
} | ||
} | ||
|
||
func TestResult_DotBracket_LengthZero(t *testing.T) { | ||
result := Result{} // Create a Result instance with empty structs | ||
|
||
expectedDotBracket := "" | ||
actualDotBracket := result.DotBracket() | ||
|
||
if actualDotBracket != expectedDotBracket { | ||
t.Errorf("expected dot bracket to be %s, but got %s", expectedDotBracket, actualDotBracket) | ||
} | ||
} | ||
|
||
func TestNewFoldingContext_InvalidSequence(t *testing.T) { | ||
seq := "XYZ" | ||
temp := 37.0 | ||
|
||
_, err := newFoldingContext(seq, temp) | ||
if err == nil { | ||
t.Errorf("expected error, but got nil") | ||
} | ||
expectedError := fmt.Errorf("the sequence %s is not RNA or DNA", seq) | ||
if err.Error() != expectedError.Error() { | ||
t.Errorf("expected error message to be %q, but got %q", expectedError.Error(), err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package bwt | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
const wordSize = 64 | ||
|
||
// bitvector a sequence of 1's and 0's. You can also think | ||
// of this as an array of bits. This allows us to encode | ||
// data in a memory efficient manner. | ||
type bitvector struct { | ||
bits []uint64 | ||
numberOfBits int | ||
} | ||
|
||
// newBitVector will return an initialized bitvector with | ||
// the specified number of zeroed bits. | ||
func newBitVector(initialNumberOfBits int) bitvector { | ||
capacity := getNumOfBitSetsNeededForNumOfBits(initialNumberOfBits) | ||
bits := make([]uint64, capacity) | ||
return bitvector{ | ||
bits: bits, | ||
numberOfBits: initialNumberOfBits, | ||
} | ||
} | ||
|
||
// getBitSet gets the while word as some offset from the | ||
// bitvector. Useful if you'd prefer to work with the | ||
// word rather than with individual bits. | ||
func (b bitvector) getBitSet(bitSetPos int) uint64 { | ||
return b.bits[bitSetPos] | ||
} | ||
|
||
// getBit returns the value of the bit at a given offset | ||
// True represents 1 | ||
// False represents 0 | ||
func (b bitvector) getBit(i int) bool { | ||
b.checkBounds(i) | ||
|
||
chunkStart := i / wordSize | ||
offset := i % wordSize | ||
|
||
return (b.bits[chunkStart] & (uint64(1) << (63 - offset))) != 0 | ||
} | ||
|
||
// setBit sets the value of the bit at a given offset | ||
// True represents 1 | ||
// False represents 0 | ||
func (b bitvector) setBit(i int, val bool) { | ||
b.checkBounds(i) | ||
|
||
chunkStart := i / wordSize | ||
offset := i % wordSize | ||
|
||
if val { | ||
b.bits[chunkStart] |= uint64(1) << (63 - offset) | ||
} else { | ||
b.bits[chunkStart] &= ^(uint64(1) << (63 - offset)) | ||
} | ||
} | ||
|
||
func (b bitvector) checkBounds(i int) { | ||
if i >= b.len() || i < 0 { | ||
msg := fmt.Sprintf("access of %d is out of bounds for bitvector with length %d", i, b.len()) | ||
panic(msg) | ||
} | ||
} | ||
|
||
func (b bitvector) len() int { | ||
return b.numberOfBits | ||
} | ||
|
||
func getNumOfBitSetsNeededForNumOfBits(n int) int { | ||
return int(math.Ceil(float64(n) / wordSize)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package bwt | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type GetBitTestCase struct { | ||
position int | ||
expected bool | ||
} | ||
|
||
func TestBitVector(t *testing.T) { | ||
initialNumberOfBits := wordSize*10 + 1 | ||
|
||
bv := newBitVector(initialNumberOfBits) | ||
|
||
if bv.len() != initialNumberOfBits { | ||
t.Fatalf("expected len to be %d but got %d", initialNumberOfBits, bv.len()) | ||
} | ||
|
||
for i := 0; i < initialNumberOfBits; i++ { | ||
bv.setBit(i, true) | ||
} | ||
|
||
bv.setBit(3, false) | ||
bv.setBit(11, false) | ||
bv.setBit(13, false) | ||
bv.setBit(23, false) | ||
bv.setBit(24, false) | ||
bv.setBit(25, false) | ||
bv.setBit(42, false) | ||
bv.setBit(63, false) | ||
bv.setBit(64, false) | ||
bv.setBit(255, false) | ||
bv.setBit(256, false) | ||
|
||
getBitTestCases := []GetBitTestCase{ | ||
{0, true}, | ||
{1, true}, | ||
{2, true}, | ||
{3, false}, | ||
{4, true}, | ||
{7, true}, | ||
{8, true}, | ||
{9, true}, | ||
{10, true}, | ||
{11, false}, | ||
{12, true}, | ||
{13, false}, | ||
{23, false}, | ||
{24, false}, | ||
{25, false}, | ||
{42, false}, | ||
{15, true}, | ||
{16, true}, | ||
{62, true}, | ||
{63, false}, | ||
{64, false}, | ||
// Test past the first word | ||
{65, true}, | ||
{72, true}, | ||
{79, true}, | ||
{80, true}, | ||
{255, false}, | ||
{256, false}, | ||
{511, true}, | ||
{512, true}, | ||
} | ||
|
||
for _, v := range getBitTestCases { | ||
actual := bv.getBit(v.position) | ||
if actual != v.expected { | ||
t.Fatalf("expected %dth bit to be %t but got %t", v.position, v.expected, actual) | ||
} | ||
} | ||
} | ||
|
||
func TestBitVectorBoundPanic_GetBit_Lower(t *testing.T) { | ||
defer func() { _ = recover() }() | ||
|
||
initialNumberOfBits := wordSize*10 + 1 | ||
bv := newBitVector(initialNumberOfBits) | ||
bv.getBit(-1) | ||
|
||
t.Fatalf("expected get bit lower bound panic") | ||
} | ||
|
||
func TestBitVectorBoundPanic_GetBit_Upper(t *testing.T) { | ||
defer func() { _ = recover() }() | ||
initialNumberOfBits := wordSize*10 + 1 | ||
bv := newBitVector(initialNumberOfBits) | ||
bv.getBit(initialNumberOfBits) | ||
|
||
t.Fatalf("expected get bit upper bound panic") | ||
} | ||
|
||
func TestBitVectorBoundPanic_SetBit_Lower(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
return | ||
} | ||
t.Fatalf("expected set bit lower bound panic") | ||
}() | ||
initialNumberOfBits := wordSize*10 + 1 | ||
bv := newBitVector(initialNumberOfBits) | ||
bv.setBit(-1, true) | ||
} | ||
|
||
func TestBitVectorBoundPanic_SetBit_Upper(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
return | ||
} | ||
t.Fatalf("expected set bit upper bound panic") | ||
}() | ||
initialNumberOfBits := wordSize*10 + 1 | ||
bv := newBitVector(initialNumberOfBits) | ||
bv.setBit(initialNumberOfBits, true) | ||
} |
Oops, something went wrong.