MCPcopy Create free account
hub / github.com/bebop/poly / Optimize

Method Optimize

synthesis/codon/codon.go:169–201  ·  view source on GitHub ↗

Optimize will return a set of codons which can be used to encode the given amino acid sequence. The codons picked are weighted according to the computed translation table's weights

(aminoAcids string, randomState ...int)

Source from the content-addressed store, hash-verified

167// Optimize will return a set of codons which can be used to encode the given amino acid sequence. The codons
168// picked are weighted according to the computed translation table's weights
169func (table *TranslationTable) Optimize(aminoAcids string, randomState ...int) (string, error) {
170 // Finding any given aminoAcid is dependent upon it being capitalized, so
171 // we do that here.
172 aminoAcids = strings.ToUpper(aminoAcids)
173
174 if len(aminoAcids) == 0 {
175 return "", errEmptyAminoAcidString
176 }
177
178 // weightedRand library insisted setting seed like this. Not sure what environmental side effects exist.
179 var randomSource rand.Source
180 if len(randomState) > 0 {
181 randomSource = rand.NewSource(int64(randomState[0]))
182 } else {
183 randomSource = rand.NewSource(time.Now().UTC().UnixNano())
184 }
185 rand := rand.New(randomSource)
186
187 var codons strings.Builder
188 codonChooser := table.Choosers
189
190 for _, aminoAcid := range aminoAcids {
191 chooser, ok := codonChooser[string(aminoAcid)]
192 if !ok {
193 return "", invalidAminoAcidError{aminoAcid}
194 }
195 codon := chooser.PickSource(rand)
196
197 codons.WriteString(codon.(string))
198 }
199
200 return codons.String(), nil
201}
202
203// UpdateWeights will update the translation table's codon pickers with the given amino acid codon weights
204func (table *TranslationTable) UpdateWeights(aminoAcids []AminoAcid) error {

Calls

no outgoing calls