MCPcopy Create free account
hub / github.com/bebop/poly / AddCodonTable

Function AddCodonTable

synthesis/codon/codon.go:706–734  ·  view source on GitHub ↗

AddCodonTable takes 2 CodonTables and adds them together to create a new codonTable.

(firstCodonTable, secondCodonTable *TranslationTable)

Source from the content-addressed store, hash-verified

704// AddCodonTable takes 2 CodonTables and adds them together to create
705// a new codonTable.
706func AddCodonTable(firstCodonTable, secondCodonTable *TranslationTable) (*TranslationTable, error) {
707 // Add up codons
708 var finalAminoAcids []AminoAcid
709 for _, firstAa := range firstCodonTable.AminoAcids {
710 var finalCodons []Codon
711 for _, firstCodon := range firstAa.Codons {
712 for _, secondAa := range secondCodonTable.AminoAcids {
713 for _, secondCodon := range secondAa.Codons {
714 if firstCodon.Triplet == secondCodon.Triplet {
715 finalCodons = append(finalCodons, Codon{firstCodon.Triplet, firstCodon.Weight + secondCodon.Weight})
716 }
717 }
718 }
719 }
720 finalAminoAcids = append(finalAminoAcids, AminoAcid{firstAa.Letter, finalCodons})
721 }
722
723 mergedTable, err := firstCodonTable.Copy()
724 if err != nil {
725 return nil, err
726 }
727
728 err = mergedTable.UpdateWeights(finalAminoAcids)
729 if err != nil {
730 return nil, err
731 }
732
733 return mergedTable, nil
734}

Callers 2

ExampleAddCodonTableFunction · 0.92
TestAddCodonTableFunction · 0.85

Calls 2

CopyMethod · 0.80
UpdateWeightsMethod · 0.80

Tested by 2

ExampleAddCodonTableFunction · 0.74
TestAddCodonTableFunction · 0.68