Skip to content

Commit 8ea0d04

Browse files
patched start codon regression (#414)
1 parent f76bf05 commit 8ea0d04

File tree

2 files changed

+4
-34
lines changed

2 files changed

+4
-34
lines changed

synthesis/codon/codon.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

synthesis/codon/codon_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ func TestTranslation(t *testing.T) {
2121
}
2222
}
2323

24-
// Non-Met start codons should still map to Met for our standard codon tables.
25-
// See https://github.com/TimothyStiles/poly/issues/305.
26-
func TestTranslationAlwaysMapsStartCodonToMet(t *testing.T) {
27-
gfpTranslation := "MASKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLVTTFSYGVQCFSRYPDHMKRHDFFKSAMPEGYVQERTISFKDDGNYKTRAEVKFEGDTLVNRIELKGIDFKEDGNILGHKLEYNYNSHNVYITADKQKNGIKANFKIRHNIEDGSVQLADHYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK*"
28-
gfpDnaSequence := "TTGGCTAGCAAAGGAGAAGAACTTTTCACTGGAGTTGTCCCAATTCTTGTTGAATTAGATGGTGATGTTAATGGGCACAAATTTTCTGTCAGTGGAGAGGGTGAAGGTGATGCTACATACGGAAAGCTTACCCTTAAATTTATTTGCACTACTGGAAAACTACCTGTTCCATGGCCAACACTTGTCACTACTTTCTCTTATGGTGTTCAATGCTTTTCCCGTTATCCGGATCATATGAAACGGCATGACTTTTTCAAGAGTGCCATGCCCGAAGGTTATGTACAGGAACGCACTATATCTTTCAAAGATGACGGGAACTACAAGACGCGTGCTGAAGTCAAGTTTGAAGGTGATACCCTTGTTAATCGTATCGAGTTAAAAGGTATTGATTTTAAAGAAGATGGAAACATTCTCGGACACAAACTCGAGTACAACTATAACTCACACAATGTATACATCACGGCAGACAAACAAAAGAATGGAATCAAAGCTAACTTCAAAATTCGCCACAACATTGAAGATGGATCCGTTCAACTAGCAGACCATTATCAACAAAATACTCCAATTGGCGATGGCCCTGTCCTTTTACCAGACAACCATTACCTGTCGACACAATCTGCCCTTTCGAAAGATCCCAACGAAAAGCGTGACCACATGGTCCTTCTTGAGTTTGTAACTGCTGCTGGGATTACACATGGCATGGATGAGCTCTACAAATAA"
29-
30-
if got, _ := NewTranslationTable(11).Translate(gfpDnaSequence); got != gfpTranslation {
31-
t.Errorf("TestTranslation has failed. Translate has returned %q, want %q", got, gfpTranslation)
32-
}
33-
}
34-
35-
func TestTranslationErrorsOnIncorrectStartCodon(t *testing.T) {
36-
badSequence := "GGG"
37-
38-
if _, gotErr := NewTranslationTable(11).Translate(badSequence); gotErr == nil {
39-
t.Errorf("Translation should return an error if given an incorrect start codon")
40-
}
41-
}
42-
4324
func TestTranslationErrorsOnEmptyAminoAcidString(t *testing.T) {
4425
nonEmptyCodonTable := NewTranslationTable(1)
4526
_, err := nonEmptyCodonTable.Translate("")

0 commit comments

Comments
 (0)