From 222d643f65d24dc468a26a5e88a31c855388069f Mon Sep 17 00:00:00 2001 From: BjornFJohansson Date: Tue, 19 Dec 2023 07:50:39 +0000 Subject: [PATCH] fusion PCR kind of works --- src/pydna/fusionpcr.py | 40 ++++++++++++++++++++++++++-------- tests/test_module_fusionpcr.py | 27 ++++++++++------------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/pydna/fusionpcr.py b/src/pydna/fusionpcr.py index e8533805..cee6cfe1 100644 --- a/src/pydna/fusionpcr.py +++ b/src/pydna/fusionpcr.py @@ -26,15 +26,20 @@ def anneal(x, y, limit=limit): new = Dseqrecord(Dseq(a.seq.watson, b.seq.crick, ovhg=-s1)) new.features = copy(a.features) new.features.extend([f._shift(s1) for f in b.features]) - new.parents = b, a # Setting a new property dynamically + new.left = b # Setting a new property dynamically + new.right = a # Setting a new property dynamically elif s1 == 0: new = Dseqrecord(Dseq(b.seq.watson, a.seq.crick, ovhg=-s2)) new.features = copy(b.features) new.features.extend([f._shift(s2) for f in a.features]) - new.parents = b, a # Setting a new property dynamically + new.left = a # Setting a new property dynamically + new.right = b # Setting a new property dynamically return new argument = fragments + for arg in argument: + arg.left = None + arg.right = None newfragments = [] while True: for a, b in combinations(fragments, 2): @@ -50,15 +55,32 @@ def anneal(x, y, limit=limit): newfragments = [] else: break + return [x for x in fragments if x not in argument] -if __name__ == "__main__": - import os as _os +def list_parts(fusion_pcr_fragment): + stack = [fusion_pcr_fragment] + processed = [] + + while stack: + obj = stack.pop() + try: + a, b = obj.right, obj.left + except AttributeError: + pass + else: + stack.extend((a, b)) + processed.append(obj) + + parts = [x for x in processed[::-1] if x] + + msg = "---\n\n" - cached = _os.getenv("pydna_cached_funcs", "") - _os.environ["pydna_cached_funcs"] = "" - import doctest + for part in parts: + if hasattr(part, "anneal"): + msg += repr(part.anneal) + "\n\n" + msg += f"{part.name}\n{part.seq.watson}\n{part.seq.crick[::-1]}\n\n---\n\n" + msg += repr(part.seq) + "\n\n" - doctest.testmod(verbose=True, optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)) - _os.environ["pydna_cached_funcs"] = cached + return msg diff --git a/tests/test_module_fusionpcr.py b/tests/test_module_fusionpcr.py index 0ae8a64f..08df0207 100644 --- a/tests/test_module_fusionpcr.py +++ b/tests/test_module_fusionpcr.py @@ -78,21 +78,18 @@ def test_fusionpcr3(): assert eq(result, r) -# from Bio.SeqFeature import SeqFeature, SimpleLocation -# x = Dseqrecord(Dseq("tctggtcaagctgaagggtattc"), -# features=[SeqFeature(SimpleLocation(5, 10, strand=1), -# type="misc_feature")]) -# y = Dseqrecord(Dseq("tattcgtacacagatg"), -# features=[SeqFeature(SimpleLocation(5, 10, strand=1), -# type="misc_feature")]) -# z = Dseqrecord(Dseq("acagatgacgtgt"), -# features=[SeqFeature(SimpleLocation(5, 10, strand=1), -# type="misc_feature")]) - - -# seqtuples = [ (x, y, z)] -# for arg in seqtuples: -# result = fuse_by_pcr(arg, limit=5).pop() +from Bio.SeqFeature import SeqFeature, SimpleLocation + +x = Dseqrecord( + Dseq("tctggtcaagctgaagggtattc"), features=[SeqFeature(SimpleLocation(5, 10, strand=1), type="misc_feature")] +) +y = Dseqrecord(Dseq("tattcgtacacagatg"), features=[SeqFeature(SimpleLocation(5, 10, strand=1), type="misc_feature")]) +z = Dseqrecord(Dseq("acagatgacgtgt"), features=[SeqFeature(SimpleLocation(5, 10, strand=1), type="misc_feature")]) + + +seqtuples = [(x, y, z)] +for arg in seqtuples: + result = fuse_by_pcr(arg, limit=5).pop() if __name__ == "__main__":