From 7b3bb48a00ef58bb741952efa6f84f8449e97c07 Mon Sep 17 00:00:00 2001 From: Matias Insaurralde Date: Tue, 12 Dec 2023 01:17:20 -0300 Subject: [PATCH] Bump Golang version (#401) * 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 Co-authored-by: Willow Carretero Chavez --- .github/workflows/coverage.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- go.mod | 4 ++-- io/slow5/slow5_test.go | 5 ++--- random/random.go | 6 +++--- synthesis/codon/codon.go | 9 ++++++--- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 240e03b83..12bac1d7c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f56252d30..9efe9256b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e8626192..545db78d7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/go.mod b/go.mod index db54fa954..054ea4582 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bebop/poly -go 1.18 +go 1.21 require ( github.com/google/go-cmp v0.5.8 @@ -9,6 +9,7 @@ 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 ) @@ -16,7 +17,6 @@ require ( 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 ( diff --git a/io/slow5/slow5_test.go b/io/slow5/slow5_test.go index 65027bfc1..950faf740 100644 --- a/io/slow5/slow5_test.go +++ b/io/slow5/slow5_test.go @@ -3,7 +3,6 @@ package slow5 import ( "errors" "io" - "io/ioutil" "os" "testing" ) @@ -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) } diff --git a/random/random.go b/random/random.go index 7b933a9bd..363b56b49 100644 --- a/random/random.go +++ b/random/random.go @@ -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) @@ -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] } } @@ -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 { diff --git a/synthesis/codon/codon.go b/synthesis/codon/codon.go index 2f7fdf82f..75ae10f16 100644 --- a/synthesis/codon/codon.go +++ b/synthesis/codon/codon.go @@ -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 @@ -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