Skip to content

Commit

Permalink
Bump Golang version (#401)
Browse files Browse the repository at this point in the history
* Bump Golang version

* Replace ioutil references

* Update random to use new rand approach

* Attempt to fix codon Optimize rand usage

* fixed version error and ran go mod tidy.

* Pick using source instead of global rand

* Remove deprecated random.Seed

* changed go version in test.yml to 1.21

* bump to 1.21 in workflows.

---------

Co-authored-by: Timothy Stiles <tim@stiles.io>
Co-authored-by: Willow Carretero Chavez <sandiegobutterflies@gmail.com>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 2193867 commit 7b3bb48
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .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 Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bebop/poly

go 1.18
go 1.21

require (
github.com/google/go-cmp v0.5.8
Expand All @@ -9,14 +9,14 @@ require (
github.com/mroth/weightedrand v0.4.1
github.com/pmezard/go-difflib v1.0.0
github.com/sergi/go-diff v1.2.0
github.com/spaolacci/murmur3 v1.1.0
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0
lukechampine.com/blake3 v1.1.5
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-sqlite3 v1.14.13 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
)

require (
Expand Down
5 changes: 2 additions & 3 deletions io/slow5/slow5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package slow5
import (
"errors"
"io"
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -190,11 +189,11 @@ func TestWrite(t *testing.T) {
}

// Compare both files
example, err := ioutil.ReadFile("data/example.slow5")
example, err := os.ReadFile("data/example.slow5")
if err != nil {
t.Errorf("Failed to read example file: %s", err)
}
testWrite, err := ioutil.ReadFile("data/test_write.slow5")
testWrite, err := os.ReadFile("data/test_write.slow5")
if err != nil {
t.Errorf("Failed to read test file: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ProteinSequence(length int, seed int64) (string, error) {

// https://en.wikipedia.org/wiki/Amino_acid#Table_of_standard_amino_acid_abbreviations_and_properties
var aminoAcidsAlphabet = []rune("ACDEFGHIJLMNPQRSTVWY")
rand.Seed(seed)
randomSource := rand.New(rand.NewSource(seed))

randomSequence := make([]rune, length)

Expand All @@ -31,7 +31,7 @@ func ProteinSequence(length int, seed int64) (string, error) {
//* is the standard abbreviation for the stop codon. That's a signal for the ribosome to stop the translation and because of that a protein sequence is finished with *
randomSequence[peptide] = '*'
} else {
randomIndex := rand.Intn(len(aminoAcidsAlphabet))
randomIndex := randomSource.Intn(len(aminoAcidsAlphabet))
randomSequence[peptide] = aminoAcidsAlphabet[randomIndex]
}
}
Expand All @@ -51,7 +51,7 @@ func RNASequence(length int, seed int64) (string, error) {

func randomNucelotideSequence(length int, seed int64, alphabet []rune) string {
alphabetLength := len(alphabet)
rand.Seed(seed)
rand := rand.New(rand.NewSource(seed))

randomSequence := make([]rune, length)
for basepair := range randomSequence {
Expand Down
9 changes: 6 additions & 3 deletions synthesis/codon/codon.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ func (table *TranslationTable) Optimize(aminoAcids string, randomState ...int) (
}

// weightedRand library insisted setting seed like this. Not sure what environmental side effects exist.
var randomSource rand.Source
if len(randomState) > 0 {
rand.Seed(int64(randomState[0]))
randomSource = rand.NewSource(int64(randomState[0]))
} else {
rand.Seed(time.Now().UTC().UnixNano())
randomSource = rand.NewSource(time.Now().UTC().UnixNano())
}
rand := rand.New(randomSource)

var codons strings.Builder
codonChooser := table.Choosers
Expand All @@ -163,8 +165,9 @@ func (table *TranslationTable) Optimize(aminoAcids string, randomState ...int) (
if !ok {
return "", invalidAminoAcidError{aminoAcid}
}
codon := chooser.PickSource(rand)

codons.WriteString(chooser.Pick().(string))
codons.WriteString(codon.(string))
}

return codons.String(), nil
Expand Down

0 comments on commit 7b3bb48

Please sign in to comment.