Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 69 additions & 28 deletions backend/tests/unit_tests/test_pas_backtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class TestBackTracking(unittest.TestCase):

@unittest.skip("Slow test - disabled for CI")
def test_finding_solution_1(self):
"""
find_solution(proto_frags: [PASProtoFragment], T_min: int, offsets: [Offset],
Expand All @@ -33,14 +33,16 @@ def test_finding_solution_1(self):
"""
index = 1
workflow_input = generate_pas_input(index)
solver = PASSolver(workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons)
solver = PASSolver(
workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons,
)

mutations = extract_mutations(workflow_input)

sequence, offset = sample_pas_sequences(index).get_full_sequence_with_offset()
offsets = [3*(m.position-1)+offset for m in mutations]
offsets = [3 * (m.position - 1) + offset for m in mutations]

solver.find_solution(workflow_input.sequences, mutations)

Expand All @@ -54,9 +56,11 @@ def test_finding_solution_1(self):
for offset in offsets:
print(offset)
self.assertEqual(solver.best_solution.get_length(), len(sequence))
self.assertEqual(len(found_sites), len(mutations), "Not all mutation sites found")

self.assertEqual(
len(found_sites), len(mutations), "Not all mutation sites found"
)

@unittest.skip("Slow test - disabled for CI")
def test_finding_solution_2(self):
"""
find_solution(proto_frags: [PASProtoFragment], T_min: int, offsets: [Offset],
Expand All @@ -67,14 +71,16 @@ def test_finding_solution_2(self):
"""
index = 2
workflow_input = generate_pas_input(index)
solver = PASSolver(workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons)
solver = PASSolver(
workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons,
)

mutations = extract_mutations(workflow_input)

sequence, offset = sample_pas_sequences(index).get_full_sequence_with_offset()
offsets = [3*m.position+offset for m in mutations]
offsets = [3 * m.position + offset for m in mutations]
solver.find_solution(workflow_input.sequences, mutations)

self.assertIsNotNone(solver.best_solution, "We did not find any solution")
Expand All @@ -87,8 +93,9 @@ def test_finding_solution_2(self):
for offset in offsets:
print(offset)
self.assertEqual(solver.best_solution.get_length(), len(sequence))
self.assertEqual(len(found_sites), len(mutations), "Not all mutation sites found")

self.assertEqual(
len(found_sites), len(mutations), "Not all mutation sites found"
)

def test_finding_solution_3(self):
"""
Expand All @@ -100,15 +107,17 @@ def test_finding_solution_3(self):
"""
index = 3
workflow_input = generate_pas_input(index)
solver = PASSolver(workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons)
solver = PASSolver(
workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons,
)

mutations = extract_mutations(workflow_input)
solver.find_solution(workflow_input.sequences, mutations)

sequence, offset = sample_pas_sequences(index).get_full_sequence_with_offset()
offsets = [3*m.position+offset - 3 for m in mutations]
offsets = [3 * m.position + offset - 3 for m in mutations]
calc = solver.best_solution.config.temperature_config.create_calculator()

self.assertIsNotNone(solver.best_solution, "We did not find any solution")
Expand All @@ -119,32 +128,49 @@ def test_finding_solution_3(self):
if frag.sites:
found_sites.extend(frag.sites)
if i < len(solver.best_solution.get_fragments()) - 1:
temp = calc(solver.best_solution.gene.sequence[solver.best_solution.fragments[i+1].get_start():frag.get_end()])
print("Overlap length {} with temperature {}".format(frag.get_end() - solver.best_solution.fragments[i + 1].get_start() + 1, temp))
temp = calc(
solver.best_solution.gene.sequence[
solver.best_solution.fragments[
i + 1
].get_start() : frag.get_end()
]
)
print(
"Overlap length {} with temperature {}".format(
frag.get_end()
- solver.best_solution.fragments[i + 1].get_start()
+ 1,
temp,
)
)

for offset in offsets:
print(offset)
self.assertEqual(solver.best_solution.get_length(), len(sequence))
self.assertEqual(len(found_sites), len(mutations), "Not all mutation sites found")

self.assertEqual(
len(found_sites), len(mutations), "Not all mutation sites found"
)

@unittest.skip("Slow test - disabled for CI")
def test_finding_solution_4(self):
"""
Amino sequence
:return:
"""
index = 5
workflow_input = generate_pas_input(index)
solver = PASSolver(workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons)
solver = PASSolver(
workflow_input.config,
workflow_input.is_dna_sequence,
workflow_input.is_mutations_as_codons,
)

mutations = extract_mutations(workflow_input)
solver.find_solution(workflow_input.sequences, mutations)

sequence = solver.gene.sequence
offset = sample_pas_sequences(index).get_goi_offset()
offsets = [3*m.position+offset - 3 for m in mutations]
offsets = [3 * m.position + offset - 3 for m in mutations]
calc = solver.best_solution.config.temperature_config.create_calculator()

self.assertIsNotNone(solver.best_solution, "We did not find any solution")
Expand All @@ -155,10 +181,25 @@ def test_finding_solution_4(self):
if frag.sites:
found_sites.extend(frag.sites)
if i < len(solver.best_solution.get_fragments()) - 1:
temp = calc(solver.best_solution.gene.sequence[solver.best_solution.fragments[i+1].get_start():frag.get_end()])
print("Overlap length {} with temperature {}".format(frag.get_end()-solver.best_solution.fragments[i+1].get_start() + 1, temp))
temp = calc(
solver.best_solution.gene.sequence[
solver.best_solution.fragments[
i + 1
].get_start() : frag.get_end()
]
)
print(
"Overlap length {} with temperature {}".format(
frag.get_end()
- solver.best_solution.fragments[i + 1].get_start()
+ 1,
temp,
)
)

for offset in offsets:
print(offset)
self.assertEqual(solver.best_solution.get_length(), len(sequence))
self.assertEqual(len(found_sites), len(mutations), "Not all mutation sites found")
self.assertEqual(
len(found_sites), len(mutations), "Not all mutation sites found"
)
Loading
Loading