Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patched start codon regression #414

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading