Skip to content

Commit 7b3bb48

Browse files
matiasinsaurraldeTimothyStilescarreter
authored
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 <tim@stiles.io> Co-authored-by: Willow Carretero Chavez <sandiegobutterflies@gmail.com>
1 parent 2193867 commit 7b3bb48

File tree

7 files changed

+16
-14
lines changed

7 files changed

+16
-14
lines changed

‎.github/workflows/coverage.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install Go
1414
uses: actions/setup-go@v2
1515
with:
16-
go-version: 1.18
16+
go-version: 1.21
1717
- name: Checkout code
1818
uses: actions/checkout@v2
1919
- name: Generate coverage report

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Set up Go
1919
uses: actions/setup-go@v2
2020
with:
21-
go-version: 1.18
21+
go-version: 1.21
2222
-
2323
name: Run GoReleaser
2424
uses: goreleaser/goreleaser-action@v2

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go-version: [1.18.x,]
13+
go-version: [1.21.x,]
1414
platform: [ubuntu-latest, macos-latest]
1515
runs-on: ${{ matrix.platform }}
1616
steps:

‎go.mod‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/bebop/poly
22

3-
go 1.18
3+
go 1.21
44

55
require (
66
github.com/google/go-cmp v0.5.8
@@ -9,14 +9,14 @@ require (
99
github.com/mroth/weightedrand v0.4.1
1010
github.com/pmezard/go-difflib v1.0.0
1111
github.com/sergi/go-diff v1.2.0
12+
github.com/spaolacci/murmur3 v1.1.0
1213
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0
1314
lukechampine.com/blake3 v1.1.5
1415
)
1516

1617
require (
1718
github.com/davecgh/go-spew v1.1.1 // indirect
1819
github.com/mattn/go-sqlite3 v1.14.13 // indirect
19-
github.com/spaolacci/murmur3 v1.1.0 // indirect
2020
)
2121

2222
require (

‎io/slow5/slow5_test.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package slow5
33
import (
44
"errors"
55
"io"
6-
"io/ioutil"
76
"os"
87
"testing"
98
)
@@ -190,11 +189,11 @@ func TestWrite(t *testing.T) {
190189
}
191190

192191
// Compare both files
193-
example, err := ioutil.ReadFile("data/example.slow5")
192+
example, err := os.ReadFile("data/example.slow5")
194193
if err != nil {
195194
t.Errorf("Failed to read example file: %s", err)
196195
}
197-
testWrite, err := ioutil.ReadFile("data/test_write.slow5")
196+
testWrite, err := os.ReadFile("data/test_write.slow5")
198197
if err != nil {
199198
t.Errorf("Failed to read test file: %s", err)
200199
}

‎random/random.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func ProteinSequence(length int, seed int64) (string, error) {
1919

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

2424
randomSequence := make([]rune, length)
2525

@@ -31,7 +31,7 @@ func ProteinSequence(length int, seed int64) (string, error) {
3131
//* 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 *
3232
randomSequence[peptide] = '*'
3333
} else {
34-
randomIndex := rand.Intn(len(aminoAcidsAlphabet))
34+
randomIndex := randomSource.Intn(len(aminoAcidsAlphabet))
3535
randomSequence[peptide] = aminoAcidsAlphabet[randomIndex]
3636
}
3737
}
@@ -51,7 +51,7 @@ func RNASequence(length int, seed int64) (string, error) {
5151

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

5656
randomSequence := make([]rune, length)
5757
for basepair := range randomSequence {

‎synthesis/codon/codon.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ func (table *TranslationTable) Optimize(aminoAcids string, randomState ...int) (
149149
}
150150

151151
// weightedRand library insisted setting seed like this. Not sure what environmental side effects exist.
152+
var randomSource rand.Source
152153
if len(randomState) > 0 {
153-
rand.Seed(int64(randomState[0]))
154+
randomSource = rand.NewSource(int64(randomState[0]))
154155
} else {
155-
rand.Seed(time.Now().UTC().UnixNano())
156+
randomSource = rand.NewSource(time.Now().UTC().UnixNano())
156157
}
158+
rand := rand.New(randomSource)
157159

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

167-
codons.WriteString(chooser.Pick().(string))
170+
codons.WriteString(codon.(string))
168171
}
169172

170173
return codons.String(), nil

0 commit comments

Comments
 (0)