Skip to content

Commit

Permalink
tests for ligate
Browse files Browse the repository at this point in the history
  • Loading branch information
BjornFJohansson committed Dec 7, 2023
1 parent 2b203bc commit 2336f1a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 69 deletions.
76 changes: 7 additions & 69 deletions src/pydna/ligate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
80 changes: 80 additions & 0 deletions tests/test_module_ligate.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 2336f1a

Please sign in to comment.