Skip to content

Commit 7c9a5a1

Browse files
added a test and a line that removes repeated enzymes i nthe Dseq.get_cutsites (#542)
1 parent 3b76f2f commit 7c9a5a1

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/pydna/dseq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ def get_cutsites(self: DseqType, *enzymes: EnzymesType) -> List[CutSiteType]:
22442244
# argument is probably a RestrictionBatch
22452245
enzymes = [e for e in enzymes[0]]
22462246

2247-
enzymes = flatten(enzymes)
2247+
enzymes = list(dict.fromkeys(flatten(enzymes))) # remove duplicate enzymes
22482248
out = list()
22492249
for e in enzymes:
22502250
# Positions of the cut on the watson strand. They are 1-based, so we subtract

tests/test_module_dseq.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,3 +1628,38 @@ def test_cast_to_ds():
16281628
Dseq("ACGT", "A", -3),
16291629
]:
16301630
assert query.cast_to_ds() == solution
1631+
1632+
1633+
def test_overlapping_cuts():
1634+
1635+
from pydna.dseq import Dseq
1636+
from Bio.Restriction import PstI, SbfI, BamHI, DpnI, BcgI
1637+
1638+
s = Dseq("CCTGCAGG")
1639+
1640+
assert s.cut(PstI) == (Dseq(b"CCXPIE"), Dseq(b"ZQJFGG"))
1641+
assert s.cut(SbfI) == (Dseq(b"CCXPIE"), Dseq(b"ZQJFGG"))
1642+
1643+
with pytest.raises(ValueError):
1644+
s.cut(PstI, SbfI)
1645+
1646+
t = Dseq("GGATCC")
1647+
1648+
assert t.cut(BamHI) == (Dseq("GQFZJ"), Dseq("PEXIC"))
1649+
assert t.cut(DpnI) == (Dseq("GGA"), Dseq("TCC"))
1650+
1651+
with pytest.raises(ValueError):
1652+
t.cut(BamHI, DpnI)
1653+
1654+
q = Dseq("TgcgtagatcgtACGAggatccTGCGtcaagtgtctat")
1655+
assert q.cut(BamHI, BamHI, BamHI) == (
1656+
Dseq("TgcgtagatcgtACGAgqfzj"),
1657+
Dseq("pexicTGCGtcaagtgtctat"),
1658+
)
1659+
1660+
assert q.cut(BamHI, BcgI) == (
1661+
Dseq("Tpi"),
1662+
Dseq("qjgtagatcgtACGAgqfzj"),
1663+
Dseq("pexicTGCGtcaagtgtcxe"),
1664+
Dseq("zft"),
1665+
)

0 commit comments

Comments
 (0)