Skip to content

Commit

Permalink
tests for #281 #279, add type to pcr (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera authored Oct 8, 2024
1 parent 4c2d929 commit f063c40
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pydna/amplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def __str__(self):
report = __str__


def pcr(*args, **kwargs):
def pcr(*args, **kwargs) -> _Amplicon:
"""pcr is a convenience function for the Anneal class to simplify its
usage, especially from the command line. If more than one or no PCR
product is formed, a ValueError is raised.
Expand Down
2 changes: 2 additions & 0 deletions src/pydna/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def shift_location(original_location, shift, lim):
newparts = []
strand = original_location.strand
if lim is None:
if min(original_location) + shift < 0:
raise ValueError("Shift moves location below zero, use a `lim` to loop around if sequence is circular.")
lim = _sys.maxsize

for part in original_location.parts:
Expand Down
22 changes: 20 additions & 2 deletions tests/test_module_amplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,12 @@ def test_pcr():
)

for key, tst in enumerate(raw):
#print(tst[0], pcr(tst[1:]).seguid(), tst[0] in pcr(tst[1:]).seguid())
# print(tst[0], pcr(tst[1:]).seguid(), tst[0] in pcr(tst[1:]).seguid())
assert tst[0] in pcr(tst[1:]).seguid()


def test_shifts():
from pydna.parsers import parse
from pydna.parsers import parse_primers
from pydna.amplify import pcr

# from pydna.amplify import nopcr
Expand Down Expand Up @@ -782,5 +781,24 @@ def test_shifts():
f = pcr(f, r, t)


def test_annotation():
"""
Test that annotations are correctly added to the amplicon in primers with tails
https://github.com/BjornFJohansson/pydna/issues/279
"""
from pydna.amplify import pcr
from pydna.dseqrecord import Dseqrecord

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

forward_primer = "ccccggatccATGCAAACAGTAATGATGGA"
reverse_primer = "ttttggatccATTATCTTTTTCAGCAATAGAATCA"

pcr_product = pcr(forward_primer, reverse_primer, dsr)

assert pcr_product.features[0].location.extract(pcr_product).seq == dsr.seq


if __name__ == "__main__":
pytest.main([__file__, "-vv", "-s"])
30 changes: 27 additions & 3 deletions tests/test_module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ def test_smallest_rotation():


def test_memorize(monkeypatch):
import pytest
from unittest import mock

from pydna.utils import memorize as _memorize
Expand Down Expand Up @@ -474,6 +473,33 @@ def test_shift_location():
loc = SimpleLocation(0, 2, strand)
assert shift_location(shift_location(loc, 1, 6), -1, 6) == loc

# Shifting location on circular sequence
for strand in (1, -1, None):
loc = SimpleLocation(0, 4, strand)
assert shift_location(loc, 1, 6) == SimpleLocation(1, 5, strand)
if strand == -1:
assert shift_location(loc, -1, 6) == SimpleLocation(0, 3, strand) + SimpleLocation(5, 6, strand)
else:
assert shift_location(loc, -1, 6) == SimpleLocation(5, 6, strand) + SimpleLocation(0, 3, strand)

# Shifting ignoring the sequence length
# See https://github.com/BjornFJohansson/pydna/issues/281
for strand in (1, -1, None):
loc = SimpleLocation(4, 6, strand)
assert shift_location(loc, 1000, None) == SimpleLocation(1004, 1006, strand)
assert shift_location(loc, -4, None) == SimpleLocation(0, 2, strand)
try:
shift_location(loc, -1000, None)
raise AssertionError("Shift below zero should raise ValueError")
except ValueError:
pass

composed_loc = SimpleLocation(2, 4, strand) + SimpleLocation(5, 6, strand)
assert shift_location(composed_loc, 1000, None) == SimpleLocation(1002, 1004, strand) + SimpleLocation(
1005, 1006, strand
)
assert shift_location(composed_loc, -2, None) == SimpleLocation(0, 2, strand) + SimpleLocation(3, 4, strand)


def test_locations_overlap():
from pydna.utils import locations_overlap, shift_location
Expand Down Expand Up @@ -509,7 +535,5 @@ def test_locations_overlap():
assert not locations_overlap(main_shifted, loc_shifted, 20)




if __name__ == "__main__":
pytest.main([__file__, "-vv", "-s"])

0 comments on commit f063c40

Please sign in to comment.