From 165561ead2ae62640f21104acde1b2780eae68d5 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Thu, 30 Nov 2023 22:49:12 -0800 Subject: [PATCH] fixed bug where linear, non-directional, single cuts were copying and not just moving overhangs from the fragment sequence. --- clone/clone.go | 14 ++++++++++---- clone/clone_test.go | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/clone/clone.go b/clone/clone.go index 4b9096bf..e7f1c3ee 100644 --- a/clone/clone.go +++ b/clone/clone.go @@ -186,19 +186,25 @@ func CutWithEnzyme(part Part, directional bool, enzyme Enzyme) []Fragment { // 2 fragments if len(overhangs) == 1 && !directional && !part.Circular { // Check the case of a single cut // In the case of a single cut in a linear sequence, we get two fragments with only 1 stick end - fragmentSequence1 := sequence[overhangs[0].Position+overhangs[0].Length:] - fragmentSequence2 := sequence[:overhangs[0].Position] + var fragmentSequence1 string + var fragmentSequence2 string var overhangSequence string if len(forwardOverhangs) > 0 { + fragmentSequence1 = sequence[overhangs[0].Position+overhangs[0].Length:] + fragmentSequence2 = sequence[:overhangs[0].Position] overhangSequence = sequence[overhangs[0].Position : overhangs[0].Position+overhangs[0].Length] + fragments = append(fragments, Fragment{fragmentSequence1, overhangSequence, ""}) + fragments = append(fragments, Fragment{fragmentSequence2, "", overhangSequence}) } else { + fragmentSequence1 = sequence[overhangs[0].Position:] + fragmentSequence2 = sequence[:overhangs[0].Position-overhangs[0].Length] overhangSequence = sequence[overhangs[0].Position-overhangs[0].Length : overhangs[0].Position] + fragments = append(fragments, Fragment{fragmentSequence2, "", overhangSequence}) + fragments = append(fragments, Fragment{fragmentSequence1, overhangSequence, ""}) } - fragments = append(fragments, Fragment{fragmentSequence1, overhangSequence, ""}) - fragments = append(fragments, Fragment{fragmentSequence2, "", overhangSequence}) return fragments } diff --git a/clone/clone_test.go b/clone/clone_test.go index ce59a778..ee0ca789 100644 --- a/clone/clone_test.go +++ b/clone/clone_test.go @@ -116,20 +116,26 @@ func TestCutWithEnzymeRegression(t *testing.T) { t.Errorf("Expected 2 fragments, got: %d", len(fragments)) } - if fragments[0].ForwardOverhang != "ACTT" { - t.Errorf("Expected forward overhang to be ACTT, got: %s", fragments[0].ForwardOverhang) + if fragments[0].ForwardOverhang != "" { + t.Errorf("Expected forward overhang to be empty, got: %s", fragments[1].ForwardOverhang) } - if fragments[0].ReverseOverhang != "" { - t.Errorf("Expected reverse overhang to be GAGT, got: %s", fragments[0].ReverseOverhang) + if fragments[0].ReverseOverhang != "ACTT" { + t.Errorf("Expected reverse overhang to be GAGT, got: %s", fragments[1].ReverseOverhang) } - if fragments[1].ForwardOverhang != "" { - t.Errorf("Expected forward overhang to be empty, got: %s", fragments[1].ForwardOverhang) + if fragments[1].ForwardOverhang != "ACTT" { + t.Errorf("Expected forward overhang to be ACTT, got: %s", fragments[0].ForwardOverhang) } - if fragments[1].ReverseOverhang != "ACTT" { - t.Errorf("Expected reverse overhang to be GAGT, got: %s", fragments[1].ReverseOverhang) + if fragments[1].ReverseOverhang != "" { + t.Errorf("Expected reverse overhang to be GAGT, got: %s", fragments[0].ReverseOverhang) + } + + // assemble the fragments back together + assembly := fragments[0].Sequence + fragments[0].ReverseOverhang + fragments[1].Sequence + if assembly != sequence { + t.Errorf("Expected assembly to be %s, got: %s", sequence, assembly) } }