From d0a23a82980909310460365f47a6e5d2d821a5a5 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Sun, 10 Dec 2023 10:27:27 -0800 Subject: [PATCH] patched start codon regression --- synthesis/codon/codon.go | 19 ++++--------------- synthesis/codon/codon_test.go | 19 ------------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/synthesis/codon/codon.go b/synthesis/codon/codon.go index 4bb88357..db3c4fc1 100644 --- a/synthesis/codon/codon.go +++ b/synthesis/codon/codon.go @@ -231,31 +231,20 @@ func (table *TranslationTable) Translate(dnaSeq string) (string, error) { var aminoAcids strings.Builder var currentCodon strings.Builder translationTable := table.TranslationMap - startCodonTable := table.StartCodonTable - startCodonReached := false for _, letter := range dnaSeq { // add current nucleotide to currentCodon currentCodon.WriteRune(letter) - // if current nucleotide is the third in a codon translate to aminoAcid write to aminoAcids and reset currentCodon. - // use start codon table for the first codon only, erroring out if an invalid start codon is provided + // if current nucleotide is the third in a codon, translate to amino acid, write to aminoAcids, and reset currentCodon if currentCodon.Len() == 3 { - if startCodonReached { - aminoAcids.WriteString(translationTable[strings.ToUpper(currentCodon.String())]) - } else { - aminoAcid, ok := startCodonTable[strings.ToUpper(currentCodon.String())] - if !ok { - return "", fmt.Errorf("start codon %q is not in start codon table %v", currentCodon.String(), startCodonTable) - } - aminoAcids.WriteString(aminoAcid) - startCodonReached = true - } + aminoAcids.WriteString(translationTable[strings.ToUpper(currentCodon.String())]) - // reset codon string builder for next codon. + // reset codon string builder for the next codon currentCodon.Reset() } } + return aminoAcids.String(), nil } diff --git a/synthesis/codon/codon_test.go b/synthesis/codon/codon_test.go index 9feafe70..a73fb8a7 100644 --- a/synthesis/codon/codon_test.go +++ b/synthesis/codon/codon_test.go @@ -21,25 +21,6 @@ func TestTranslation(t *testing.T) { } } -// Non-Met start codons should still map to Met for our standard codon tables. -// See https://github.com/TimothyStiles/poly/issues/305. -func TestTranslationAlwaysMapsStartCodonToMet(t *testing.T) { - gfpTranslation := "MASKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLVTTFSYGVQCFSRYPDHMKRHDFFKSAMPEGYVQERTISFKDDGNYKTRAEVKFEGDTLVNRIELKGIDFKEDGNILGHKLEYNYNSHNVYITADKQKNGIKANFKIRHNIEDGSVQLADHYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK*" - gfpDnaSequence := "TTGGCTAGCAAAGGAGAAGAACTTTTCACTGGAGTTGTCCCAATTCTTGTTGAATTAGATGGTGATGTTAATGGGCACAAATTTTCTGTCAGTGGAGAGGGTGAAGGTGATGCTACATACGGAAAGCTTACCCTTAAATTTATTTGCACTACTGGAAAACTACCTGTTCCATGGCCAACACTTGTCACTACTTTCTCTTATGGTGTTCAATGCTTTTCCCGTTATCCGGATCATATGAAACGGCATGACTTTTTCAAGAGTGCCATGCCCGAAGGTTATGTACAGGAACGCACTATATCTTTCAAAGATGACGGGAACTACAAGACGCGTGCTGAAGTCAAGTTTGAAGGTGATACCCTTGTTAATCGTATCGAGTTAAAAGGTATTGATTTTAAAGAAGATGGAAACATTCTCGGACACAAACTCGAGTACAACTATAACTCACACAATGTATACATCACGGCAGACAAACAAAAGAATGGAATCAAAGCTAACTTCAAAATTCGCCACAACATTGAAGATGGATCCGTTCAACTAGCAGACCATTATCAACAAAATACTCCAATTGGCGATGGCCCTGTCCTTTTACCAGACAACCATTACCTGTCGACACAATCTGCCCTTTCGAAAGATCCCAACGAAAAGCGTGACCACATGGTCCTTCTTGAGTTTGTAACTGCTGCTGGGATTACACATGGCATGGATGAGCTCTACAAATAA" - - if got, _ := NewTranslationTable(11).Translate(gfpDnaSequence); got != gfpTranslation { - t.Errorf("TestTranslation has failed. Translate has returned %q, want %q", got, gfpTranslation) - } -} - -func TestTranslationErrorsOnIncorrectStartCodon(t *testing.T) { - badSequence := "GGG" - - if _, gotErr := NewTranslationTable(11).Translate(badSequence); gotErr == nil { - t.Errorf("Translation should return an error if given an incorrect start codon") - } -} - func TestTranslationErrorsOnEmptyAminoAcidString(t *testing.T) { nonEmptyCodonTable := NewTranslationTable(1) _, err := nonEmptyCodonTable.Translate("")