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

more permanent fix to start codon regression #415

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
23 changes: 11 additions & 12 deletions synthesis/codon/codon.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,28 @@ func (table *TranslationTable) Translate(dnaSeq string) (string, error) {
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)
}
codon := strings.ToUpper(currentCodon.String())

// check if the currentCodon exists in the startCodonTable
if aminoAcid, ok := startCodonTable[codon]; ok {
aminoAcids.WriteString(aminoAcid)
} else if aminoAcid, ok := translationTable[codon]; ok {
aminoAcids.WriteString(aminoAcid)
startCodonReached = true
} else {
return "", fmt.Errorf("codon %q not found in translation table", codon)
}

// reset codon string builder for next codon.
// reset codon string builder for the next codon
currentCodon.Reset()
}
}

return aminoAcids.String(), nil
}

Expand Down