@@ -231,31 +231,20 @@ func (table *TranslationTable) Translate(dnaSeq string) (string, error) {
231231 var aminoAcids strings.Builder
232232 var currentCodon strings.Builder
233233 translationTable := table .TranslationMap
234- startCodonTable := table .StartCodonTable
235234
236- startCodonReached := false
237235 for _ , letter := range dnaSeq {
238236 // add current nucleotide to currentCodon
239237 currentCodon .WriteRune (letter )
240238
241- // if current nucleotide is the third in a codon translate to aminoAcid write to aminoAcids and reset currentCodon.
242- // use start codon table for the first codon only, erroring out if an invalid start codon is provided
239+ // if current nucleotide is the third in a codon, translate to amino acid, write to aminoAcids, and reset currentCodon
243240 if currentCodon .Len () == 3 {
244- if startCodonReached {
245- aminoAcids .WriteString (translationTable [strings .ToUpper (currentCodon .String ())])
246- } else {
247- aminoAcid , ok := startCodonTable [strings .ToUpper (currentCodon .String ())]
248- if ! ok {
249- return "" , fmt .Errorf ("start codon %q is not in start codon table %v" , currentCodon .String (), startCodonTable )
250- }
251- aminoAcids .WriteString (aminoAcid )
252- startCodonReached = true
253- }
241+ aminoAcids .WriteString (translationTable [strings .ToUpper (currentCodon .String ())])
254242
255- // reset codon string builder for next codon.
243+ // reset codon string builder for the next codon
256244 currentCodon .Reset ()
257245 }
258246 }
247+
259248 return aminoAcids .String (), nil
260249}
261250
0 commit comments