From 2336f1a18ea981569151e4c9796f58711768e2c8 Mon Sep 17 00:00:00 2001 From: BjornFJohansson Date: Thu, 7 Dec 2023 15:36:11 +0000 Subject: [PATCH] tests for ligate --- src/pydna/ligate.py | 76 ++++------------------------------- tests/test_module_ligate.py | 80 +++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 69 deletions(-) create mode 100755 tests/test_module_ligate.py diff --git a/src/pydna/ligate.py b/src/pydna/ligate.py index 4c913958..7478a190 100644 --- a/src/pydna/ligate.py +++ b/src/pydna/ligate.py @@ -4,12 +4,9 @@ # This code is part of the Python-dna distribution and governed by its # license. Please see the LICENSE.txt file that should have been included # as part of this package. - - +"""docstring.""" from operator import add from functools import reduce -from pydna.dseq import Dseq -from pydna.dseqrecord import Dseqrecord import networkx as _nx from itertools import permutations import logging as _logging @@ -61,70 +58,11 @@ def ligate(fragments: list): if __name__ == "__main__": - a = Dseqrecord( - Dseq.from_representation( - """ - GATCaaa - tttTTCC""" - ) - ) - b = Dseqrecord( - Dseq.from_representation( - """ - AAGGatta - taatAGGA""" - ) - ) - c = Dseqrecord( - Dseq.from_representation( - """ - TCCTccact - ggtgaCTAG""" - ) - ) - - d = Dseqrecord( - Dseq.from_representation( - """ - Tcgcgc - gcgcgC""" - ) - ) - - e = Dseqrecord( - Dseq.from_representation( - """ - Gcaatt - gttaa""" - ) - ) - - fragments = [a, b, c, d, e] - rcfragments = [a.rc(), b.rc(), c.rc(), d.rc(), e.rc()] - - def list_combinations(a, b): - N = len(a) - combinations = [] - for i in range(2**N): - current = [] - for j in range(N): - if i & (1 << j): - current.append(a[j]) - else: - current.append(b[j]) - combinations.append(current) - - return combinations - - # Example usage: - combinations = list_combinations(fragments, rcfragments) + import os as _os - for frgs in combinations: - csequences, lsequences = ligate(frgs) + cached = _os.getenv("pydna_cached_funcs", "") + _os.environ["pydna_cached_funcs"] = "" + import doctest - for cs in csequences: - assert cs.cseguid() == "39FCQVitkpoxFJy5XX8ar9YJlsQ" - assert len(cs) == 24 - for ss in lsequences: - assert ss.lseguid() == "GI62R7QoGcNolvEQrr4x5GEF-Kk" - assert len(ss) == 12 + doctest.testmod(verbose=True, optionflags=doctest.ELLIPSIS) + _os.environ["pydna_cached_funcs"] = cached diff --git a/tests/test_module_ligate.py b/tests/test_module_ligate.py new file mode 100755 index 00000000..87707d3b --- /dev/null +++ b/tests/test_module_ligate.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +import pytest + + +def test_ligate(): + from pydna.ligate import ligate + from pydna.dseq import Dseq + from pydna.dseqrecord import Dseqrecord + + a = Dseqrecord( + Dseq.from_representation( + """ + GATCaaa + tttTTCC""" + ) + ) + b = Dseqrecord( + Dseq.from_representation( + """ + AAGGatta + taatAGGA""" + ) + ) + c = Dseqrecord( + Dseq.from_representation( + """ + TCCTccact + ggtgaCTAG""" + ) + ) + + d = Dseqrecord( + Dseq.from_representation( + """ + Tcgcgc + gcgcgC""" + ) + ) + + e = Dseqrecord( + Dseq.from_representation( + """ + Gcaatt + gttaa""" + ) + ) + + fragments = [a, b, c, d, e] + rcfragments = [a.rc(), b.rc(), c.rc(), d.rc(), e.rc()] + + def list_combinations(a, b): + N = len(a) + combinations = [] + for i in range(2**N): + current = [] + for j in range(N): + if i & (1 << j): + current.append(a[j]) + else: + current.append(b[j]) + combinations.append(current) + + return combinations + + # Example usage: + combinations = list_combinations(fragments, rcfragments) + + for frgs in combinations: + csequences, lsequences = ligate(frgs) + + for cs in csequences: + assert cs.cseguid() == "39FCQVitkpoxFJy5XX8ar9YJlsQ" + assert len(cs) == 24 + for ss in lsequences: + assert ss.lseguid() == "GI62R7QoGcNolvEQrr4x5GEF-Kk" + assert len(ss) == 12 + + +if __name__ == "__main__": + pytest.main([__file__, "-vv", "-s"])