Skip to content

Commit

Permalink
Make codon work with json (#4)
Browse files Browse the repository at this point in the history
* Removed update weights

* add freqB table
  • Loading branch information
Koeng101 authored Dec 7, 2023
1 parent 395849e commit 38185e9
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 47 deletions.
5 changes: 4 additions & 1 deletion synthesis/codon/codon.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ func (table *TranslationTable) Optimize(aminoAcids string, randomState ...int) (
}

var codons strings.Builder
codonChooser := table.Choosers
codonChooser, err := newAminoAcidChoosers(table.AminoAcids)
if err != nil {
return "", err
}

for _, aminoAcid := range aminoAcids {
chooser, ok := codonChooser[string(aminoAcid)]
Expand Down
18 changes: 18 additions & 0 deletions synthesis/codon/codon_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package codon

import (
_ "embed"
"errors"
"os"
"strings"
Expand Down Expand Up @@ -558,3 +559,20 @@ func TestUpdateWeights(t *testing.T) {
})
}
}

//go:embed default_tables/freqB.json
var ecoliCodonTable []byte

func TestCodonJSONRegression(t *testing.T) {
ct := ParseCodonJSON(ecoliCodonTable)
gfp := "MASKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLVTTFSYGVQCFSRYPDHMKRHDFFKSAMPEGYVQERTISFKDDGNYKTRAEVKFEGDTLVNRIELKGIDFKEDGNILGHKLEYNYNSHNVYITADKQKNGIKANFKIRHNIEDGSVQLADHYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK"
seed := 0
sequence, err := ct.Optimize(gfp, seed)
if err != nil {
t.Errorf("Failed to optimize with premade table. Got error: %s", err)
}
expectedSequence := `ATGGCATCCAAGGGCGAGGAGTTGTTCACCGGTGTTGTGCCGATCCTGGTGGAGCTGGACGGTGACGTGAACGGTCACAAATTTAGCGTGTCCGGTGAGGGTGAGGGTGATGCTACCTATGGCAAGCTGACCCTGAAATTCATTTGTACCACGGGTAAACTGCCGGTCCCGTGGCCGACGCTGGTGACCACCTTCAGCTATGGTGTGCAGTGTTTCAGCCGCTACCCGGACCACATGAAGCGCCACGACTTTTTCAAGAGCGCGATGCCGGAGGGTTATGTGCAAGAACGTACCATCAGCTTTAAAGATGATGGTAACTATAAGACCCGCGCGGAAGTCAAGTTTGAGGGTGACACGCTGGTGAATCGTATTGAGTTGAAGGGTATTGACTTTAAGGAGGATGGTAATATTTTGGGCCACAAACTGGAGTACAATTACAATAGCCACAATGTTTACATCACGGCAGATAAACAGAAGAACGGTATCAAGGCGAACTTCAAAATTCGTCACAACATTGAGGACGGTTCTGTTCAACTGGCGGACCATTACCAACAGAATACCCCGATCGGTGACGGCCCGGTTCTGCTGCCGGACAACCATTATTTGAGCACCCAGTCCGCCCTGAGCAAGGACCCGAATGAGAAGCGTGATCATATGGTTCTGCTGGAGTTTGTGACCGCGGCGGGCATCACCCACGGCATGGACGAGCTGTACAAG`
if sequence != expectedSequence {
t.Errorf("Failed to output expected sequence.")
}
}
Loading

0 comments on commit 38185e9

Please sign in to comment.