Skip to content

Commit

Permalink
Remove unneeded dependencies (#28)
Browse files Browse the repository at this point in the history
* Removed many deps, integrated svb and wordwrap

* removed svb submodule

* added svb back

* add cpuid, murmur, remove testify

* change around workflows

* Fix linting problems except weightedrand

* Added go.mod to lib, removed weightedRand

* fix import problems

* update directories

* Updated readme and seqhash.go for clarity
  • Loading branch information
Koeng101 authored Dec 16, 2023
1 parent 6adf9db commit 37c32f8
Show file tree
Hide file tree
Showing 66 changed files with 4,809 additions and 697 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
- name: Checkout code
uses: actions/checkout@v2
- name: Generate coverage report
run: go test -v -coverprofile=profile.cov ./...
run: go test -v -coverprofile=profile.cov ./lib/...
- name: Parse overall coverage
run: coverage=$(go tool cover -func profile.cov | tail -1 | rev | cut -f 1 | rev) && echo "COVERAGE=$coverage" >> $GITHUB_ENV
- name: Create the Badge
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir
working-directory: lib

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.18.x,]
go-version: [1.21.x,]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -21,4 +21,4 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test -v ./...
run: go test -v ./lib/...
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ run:
skip-dirs:
- data
- api/gen
- lib/bio/slow5/svb
linters:
enable:
- bodyclose
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Write good, useful code. Open a pull request, and we'll see if it fits!

* Copyright (c) 2023 Keoni Gandall

### Sources

There are a few pieces of "complete" software that we have directly integrated into the source tree (with their associated licenses). These projects don't receive updates anymore (or just bug fixes with years between). In particular, `lib` has most of these, since we intend to have as few dependencies as possible in `lib`. The integrated projects include the following.
- [svb](https://github.com/rleiwang/svb) in `lib/bio/slow5/svb`
- [intel-cpuid](https://github.com/aregm/cpuid) in `lib/bio/slow5/svb/intel-cpuid`
- [murmur3](https://github.com/spaolacci/murmur3) in `lib/mash/murmur3`
- [wordwrap](https://github.com/mitchellh/go-wordwrap) in `lib/bio/genbank`

### Other

DnaDesign is a fork of [Poly](https://github.com/TimothyStiles/poly) at commit f76bf05 with a different mission focus.
30 changes: 0 additions & 30 deletions go.mod

This file was deleted.

66 changes: 0 additions & 66 deletions go.sum

This file was deleted.

3 changes: 3 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go 1.21.5

use ./lib
13 changes: 9 additions & 4 deletions lib/align/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/koeng101/dnadesign/lib/align/matrix"
"github.com/koeng101/dnadesign/lib/alphabet"
"github.com/stretchr/testify/assert"
)

func TestSubstitutionMatrix(t *testing.T) {
Expand All @@ -21,7 +20,9 @@ func TestSubstitutionMatrix(t *testing.T) {
}
subMat, err := matrix.NewSubstitutionMatrix(alpha1, alpha2, NUC_4)

assert.Nil(t, err)
if err != nil {
t.Error(err)
}

testCases := []struct {
symbol1 string
Expand All @@ -39,8 +40,12 @@ func TestSubstitutionMatrix(t *testing.T) {
sym2, _ := alpha2.Encode(tc.symbol2)
score, err := subMat.Score(tc.symbol1, tc.symbol2)

assert.Nil(t, err)
assert.Equal(t, NUC_4[sym1][sym2], score)
if err != nil {
t.Error(err)
}
if NUC_4[sym1][sym2] != score {
t.Errorf("NUC_4[sym1][sym2] and score should be equivalent, but are not.")
}

if score != tc.score {
t.Errorf("Expected score %d for symbols %s and %s, but got %d", tc.score, tc.symbol1, tc.symbol2, score)
Expand Down
8 changes: 3 additions & 5 deletions lib/bio/genbank/genbank.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"strings"

"github.com/koeng101/dnadesign/lib/transform"
"github.com/lunny/log"
"github.com/mitchellh/go-wordwrap"
)

/******************************************************************************
Expand Down Expand Up @@ -787,8 +785,7 @@ func (parser *Parser) Next() (*Genbank, error) {
parser.parameters.sequenceBuilder.WriteString(sequenceRegex.ReplaceAllString(line, ""))
}
default:
log.Warnf("Unknown parse step: %s", parser.parameters.parseStep)
parser.parameters.genbankStarted = false
return &Genbank{}, fmt.Errorf("Unknown parse step: %s", parser.parameters.parseStep)
}
}
return &Genbank{}, io.EOF
Expand Down Expand Up @@ -1100,7 +1097,8 @@ func buildMetaString(name string, data string) string {
keyWhitespaceTrail += " "
}
name += keyWhitespaceTrail
wrappedData := wordwrap.WrapString(data, 68)

wrappedData := wrapString(data, 68)
splitData := strings.Split(wrappedData, "\n")
var returnData string
for index, datum := range splitData {
Expand Down
21 changes: 15 additions & 6 deletions lib/bio/genbank/genbank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/koeng101/dnadesign/lib/transform"
"github.com/stretchr/testify/assert"
)

/******************************************************************************
Expand Down Expand Up @@ -673,7 +672,9 @@ func TestRead_error(t *testing.T) {
readFileFn = oldreadFileFn
}()
_, err := read("/tmp/file")
assert.EqualError(t, err, readErr.Error())
if err.Error() != readErr.Error() {
t.Errorf("err should equal readErr")
}
}

func TestBuildFeatureString(t *testing.T) {
Expand All @@ -685,7 +686,9 @@ func TestBuildFeatureString(t *testing.T) {
},
}
str := BuildFeatureString(feature)
assert.Equal(t, str, " test type gbk location\n")
if str != " test type gbk location\n" {
t.Errorf("BuildFeatureString did not produce proper string")
}
}

func TestParse_error(t *testing.T) {
Expand All @@ -698,10 +701,14 @@ func TestParse_error(t *testing.T) {
parseMultiNthFn = oldParseMultiNthFn
}()
_, err := parse(strings.NewReader(""))
assert.Equal(t, err, parseMultiErr.wraps)
if err != parseMultiErr.wraps {
t.Errorf("err should equal parseMultiErr.wraps")
}

_, err = parseMultiNth(strings.NewReader(""), 10000)
assert.Equal(t, err, parseMultiErr)
if err.Error() != parseMultiErr.Error() {
t.Errorf("err should equal parseMultiErr")
}
}

func TestParseReferences_error(t *testing.T) {
Expand All @@ -714,7 +721,9 @@ func TestParseReferences_error(t *testing.T) {
}()
file, _ := os.Open("data/puc19.gbk")
_, err := parseMultiNthFn(file, 1)
assert.Equal(t, err.info, "failed in parsing reference")
if err.info != "failed in parsing reference" {
t.Errorf("err.info should have failed to parse reference")
}
}

func TestIssue303Regression(t *testing.T) {
Expand Down
93 changes: 93 additions & 0 deletions lib/bio/genbank/wordwrap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package genbank

import (
"bytes"
"unicode"
)

/*
The MIT License (MIT)
Copyright (c) 2014 Mitchell Hashimoto
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

const nbsp = 0xA0

// wrapString wraps the given string within lim width in characters.
//
// Wrapping is currently naive and only happens at white-space. A future
// version of the library will implement smarter wrapping. This means that
// pathological cases can dramatically reach past the limit, such as a very
// long word.
func wrapString(s string, lim uint) string {
// Initialize a buffer with a slightly larger size to account for breaks
init := make([]byte, 0, len(s))
buf := bytes.NewBuffer(init)

var current uint
var wordBuf, spaceBuf bytes.Buffer
var wordBufLen, spaceBufLen uint

for _, char := range s {
if char == '\n' {
if wordBuf.Len() == 0 {
if current+spaceBufLen > lim {

} else {
_, _ = spaceBuf.WriteTo(buf)
}
spaceBuf.Reset()
spaceBufLen = 0
} else {
_, _ = spaceBuf.WriteTo(buf)
spaceBuf.Reset()
spaceBufLen = 0
_, _ = wordBuf.WriteTo(buf)
wordBuf.Reset()
wordBufLen = 0
}
buf.WriteRune(char)
current = 0
} else if unicode.IsSpace(char) && char != nbsp {
if spaceBuf.Len() == 0 || wordBuf.Len() > 0 {
current += spaceBufLen + wordBufLen
_, _ = spaceBuf.WriteTo(buf)
spaceBuf.Reset()
spaceBufLen = 0
_, _ = wordBuf.WriteTo(buf)
wordBuf.Reset()
wordBufLen = 0
}

spaceBuf.WriteRune(char)
spaceBufLen++
} else {
wordBuf.WriteRune(char)
wordBufLen++

if current+wordBufLen+spaceBufLen > lim && wordBufLen < lim {
buf.WriteRune('\n')
current = 0
spaceBuf.Reset()
spaceBufLen = 0
}
}
}

if wordBuf.Len() == 0 {
if current+spaceBufLen <= lim {
_, _ = spaceBuf.WriteTo(buf)
}
} else {
_, _ = spaceBuf.WriteTo(buf)
_, _ = wordBuf.WriteTo(buf)
}

return buf.String()
}
Loading

0 comments on commit 37c32f8

Please sign in to comment.