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

Method Translate

synthesis/codon/codon.go:256–279  ·  view source on GitHub ↗

Translate will return an amino acid sequence which the given DNA will yield

(dnaSeq string)

Source from the content-addressed store, hash-verified

254
255// Translate will return an amino acid sequence which the given DNA will yield
256func (table *TranslationTable) Translate(dnaSeq string) (string, error) {
257 if dnaSeq == "" {
258 return "", errEmptySequenceString
259 }
260
261 var aminoAcids strings.Builder
262 var currentCodon strings.Builder
263 translationTable := table.TranslationMap
264
265 for _, letter := range dnaSeq {
266 // add current nucleotide to currentCodon
267 currentCodon.WriteRune(letter)
268
269 // if current nucleotide is the third in a codon, translate to amino acid, write to aminoAcids, and reset currentCodon
270 if currentCodon.Len() == 3 {
271 aminoAcids.WriteString(translationTable[strings.ToUpper(currentCodon.String())])
272
273 // reset codon string builder for the next codon
274 currentCodon.Reset()
275 }
276 }
277
278 return aminoAcids.String(), nil
279}
280
281// weightAminoAcids weights each codon in a codon table according to input string codon frequency, adding weight to
282// the given NCBI base codon table

Calls 2

LenMethod · 0.80
ResetMethod · 0.45