From f060730dba18acef8ac43b8f638497358bab01ef Mon Sep 17 00:00:00 2001 From: Manuel Lera-Ramirez Date: Thu, 7 Nov 2024 12:14:52 +0000 Subject: [PATCH] closes #262 (#326) --- src/pydna/amplify.py | 2 +- tests/test_module_amplify.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/pydna/amplify.py b/src/pydna/amplify.py index 09ff68e5..907a5b20 100644 --- a/src/pydna/amplify.py +++ b/src/pydna/amplify.py @@ -344,9 +344,9 @@ def products(self): if self.template.circular: shift = fp.position - fp._fp tpl = self.template.shifted(shift) # shift template so that it starts where the fp starts anneling - feats = tpl[: rp.position + rp._fp].features fp.position = fp._fp # New position of fp becomes the footprint length rp.position = (rp.position - shift) % len(self.template) # Shift the rp position as well + feats = tpl[: rp.position + rp._fp].features elif fp.position <= rp.position: # pcr products only formed if fp anneals forward of rp feats = self.template[ fp.position - fp._fp : rp.position + rp._fp diff --git a/tests/test_module_amplify.py b/tests/test_module_amplify.py index 8aa869d0..0fa15014 100644 --- a/tests/test_module_amplify.py +++ b/tests/test_module_amplify.py @@ -788,6 +788,7 @@ def test_annotation(): """ from pydna.amplify import pcr from pydna.dseqrecord import Dseqrecord + from pydna.primer import Primer dsr = Dseqrecord("ATGCAAACAGTAATGATGGATGACATTCAAAGCACTGATTCTATTGCTGAAAAAGATAAT") dsr.add_feature(x=0, y=60, type="gene", label="my_gene") # We add a feature to highlight the sequence as a gene @@ -804,6 +805,33 @@ def test_annotation(): pcr_product_circ = pcr(forward_primer, reverse_primer, dsr_circ) assert str(pcr_product_circ.features[0].location.extract(pcr_product_circ).seq) == str(dsr_circ.seq) + # Check that annotations are transmitted properly if the PCR product spans + # the origin in a circular sequence + + vector = Dseqrecord( + "ATGCAAACAGTAATGATGGATGACACCAGCTTCATGAAATGGAACAGTGCCAGAAAAAACTTGAAGATGTTCAAAGCACTGATTCTATTGCTGAAAAAGATAAT", + circular=True, + ) + + vector.add_feature(17, 40, type_="test", label=["left"]) + vector.add_feature(41, 90, type_="test", label=["right"]) + vector.add_feature(17, 90, type_="test", label=["all"]) + vector.add_feature(30, 60, type_="test", label=["middle"]) + + feature_seqs = set(str(f.location.extract(vector).seq) for f in vector.features) + + for shift in range(len(vector)): + shifted_vector = vector.shifted(shift) + + primer_f = Primer("acgtGGATGACACCAGCTTCAT") + primer_r = Primer("attacCAATAGAATCAGTGCTTTGAACA") + + product = pcr(primer_f, primer_r, shifted_vector) + + product_seqs = set(str(f.location.extract(product).seq) for f in product.features if f.type == "test") + + assert product_seqs == feature_seqs, f"Shift {shift}" + if __name__ == "__main__": pytest.main([__file__, "-vv", "-s"])