Skip to content

Commit

Permalink
closes #262 (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera authored Nov 7, 2024
1 parent 96df3f1 commit f060730
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pydna/amplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/test_module_amplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"])

0 comments on commit f060730

Please sign in to comment.