Skip to content

Commit

Permalink
patched start codon regression
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyStiles committed Dec 10, 2023
1 parent f76bf05 commit d0a23a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
19 changes: 4 additions & 15 deletions synthesis/codon/codon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 0 additions & 19 deletions synthesis/codon/codon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down

0 comments on commit d0a23a8

Please sign in to comment.