Skip to content

Commit

Permalink
Get next overhang (#215)
Browse files Browse the repository at this point in the history
* Moved synthesis to fixer and wrote fragment

* Added NextOverhang

Co-authored-by: Tim <[email protected]>
  • Loading branch information
Koeng101 and TimothyStiles authored Dec 30, 2021
1 parent 902f46d commit 15cd727
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 10 deletions.
11 changes: 11 additions & 0 deletions synthesis/fragment/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ func Example_basic() {
// Output: [ATGACCATGATTACGCCAAGCTTGCATGCCTGCAGGTCGACTCTAGAGGATCCCCGGGTACCGAGCTCGAATTCACTGGCCGTCGTTTTACAACGTCGTGACTGG CTGGGAAAACCCTGGCGTTACCCAACTTAATCGCCTTGCAGCACATCCCCCTTTCGCCAGCTGGCGTAATAGCGAAGAGGCCCGCACCGATCGCCCTTCCCAACA AACAGTTGCGCAGCCTGAATGGCGAATGGCGCCTGATGCGGTATTTTCTCCTTACGCATCTGTGCG TGCGGTATTTCACACCGCATATGGTGCACTCTCAGTACAATCTGCTCTGATGCCGCATAG]
}

// This example shows how to generate a new overhang onto a list of overhangs.
func ExampleNextOverhang() {
primerOverhangs := []string{"ATAA"}
primerOverhangs = append(primerOverhangs, fragment.NextOverhang(primerOverhangs))
primerOverhangs = append(primerOverhangs, fragment.NextOverhang(primerOverhangs))
primerOverhangs = append(primerOverhangs, fragment.NextOverhang(primerOverhangs))

fmt.Println(primerOverhangs)
// Output: [ATAA AAAT AATA AAGA]
}

func ExampleFragment() {
lacZ := "ATGACCATGATTACGCCAAGCTTGCATGCCTGCAGGTCGACTCTAGAGGATCCCCGGGTACCGAGCTCGAATTCACTGGCCGTCGTTTTACAACGTCGTGACTGGGAAAACCCTGGCGTTACCCAACTTAATCGCCTTGCAGCACATCCCCCTTTCGCCAGCTGGCGTAATAGCGAAGAGGCCCGCACCGATCGCCCTTCCCAACAGTTGCGCAGCCTGAATGGCGAATGGCGCCTGATGCGGTATTTTCTCCTTACGCATCTGTGCGGTATTTCACACCGCATATGGTGCACTCTCAGTACAATCTGCTCTGATGCCGCATAG"
fragments, efficiency, _ := fragment.Fragment(lacZ, 95, 105)
Expand Down
77 changes: 67 additions & 10 deletions synthesis/fragment/fragment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package fragment

import (
"fmt"
"github.com/TimothyStiles/poly/checks"
"github.com/TimothyStiles/poly/transform"
"strings"
)
Expand All @@ -34,6 +35,63 @@ func SetEfficiency(overhangs []string) float64 {
return efficiency
}

// NextOverhangs gets a list of possible next overhangs to use for an overhang
// list, along with their efficiencies. This can be used for more optimal
// fragmentation of sequences with potential degeneracy.
func NextOverhangs(currentOverhangs []string) ([]string, []float64) {
currentOverhangMap := make(map[string]bool)
for _, overhang := range currentOverhangs {
currentOverhangMap[overhang] = true
}

// These 4 for loops generate all combinations of 4 base pairs
// checking all 256 4mer combinations for palindromes. Palindromes
// can cause problems in large combinatorial reactions, so are
// removed here.
bases := []rune{'A', 'T', 'G', 'C'}
var overhangsToTest []string
for _, base1 := range bases {
for _, base2 := range bases {
for _, base3 := range bases {
for _, base4 := range bases {
newOverhang := string([]rune{base1, base2, base3, base4})
_, ok := currentOverhangMap[newOverhang]
if !ok {
if !checks.IsPalindromic(newOverhang) {
overhangsToTest = append(overhangsToTest, newOverhang)
}
}
}
}
}
}

var efficiencies []float64
for _, overhang := range overhangsToTest {
efficiencies = append(efficiencies, SetEfficiency(append(currentOverhangs, overhang)))
}
return overhangsToTest, efficiencies
}

// NextOverhang gets next most efficient overhang to use for a given set of
// overhangs. This is useful for when developing a new set of standard
// overhangs. Note: NextOverhang is biased towards high AT overhangs, but this
// will not affect fidelity at all.
func NextOverhang(currentOverhangs []string) string {
overhangsToTest, efficiencies := NextOverhangs(currentOverhangs)
var efficiency float64
var newOverhang string
maxEfficiency := float64(0)
for i, overhang := range overhangsToTest {
efficiency = efficiencies[i]
if efficiency > maxEfficiency {
maxEfficiency = efficiency
newOverhang = overhang
}
}
return newOverhang
}

// optimizeOverhangIteration takes in a sequence and optimally fragments it.
func optimizeOverhangIteration(sequence string, minFragmentSize int, maxFragmentSize int, existingFragments []string, existingOverhangs []string) ([]string, float64, error) {
// If the sequence is smaller than maxFragment size, stop iteration.
Expand Down Expand Up @@ -66,10 +124,6 @@ func optimizeOverhangIteration(sequence string, minFragmentSize int, maxFragment
maxFragmentSizeBuffer = maxFragmentSize
}
minFragmentSize = maxFragmentSizeBuffer - maxAndMinDifference
// Basic check for minimal size
if minFragmentSize < 12 {
minFragmentSize = 12
}
maxFragmentSize = maxFragmentSizeBuffer // buffer is needed equations above pass.
}

Expand All @@ -90,13 +144,16 @@ func optimizeOverhangIteration(sequence string, minFragmentSize int, maxFragment
}
}
if !alreadyExists {
// Get this overhang set's efficiency
setEfficiency := SetEfficiency(append(existingOverhangs, overhangToTest))
// See if this overhang is a palindrome
if !checks.IsPalindromic(overhangToTest) {
// Get this overhang set's efficiency
setEfficiency := SetEfficiency(append(existingOverhangs, overhangToTest))

// If this overhang is more efficient than any other found so far, set it as the best!
if setEfficiency > bestOverhangEfficiency {
bestOverhangEfficiency = setEfficiency
bestOverhangPosition = overhangPosition
// If this overhang is more efficient than any other found so far, set it as the best!
if setEfficiency > bestOverhangEfficiency {
bestOverhangEfficiency = setEfficiency
bestOverhangPosition = overhangPosition
}
}
}
}
Expand Down

0 comments on commit 15cd727

Please sign in to comment.