Skip to content

Commit

Permalink
fix: update get lib type test
Browse files Browse the repository at this point in the history
  • Loading branch information
balajtimate committed Jan 3, 2024
1 parent 04fcab2 commit 455e983
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
5 changes: 3 additions & 2 deletions htsinfer/get_library_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def _evaluate_mate_relationship(
self.mapping.evaluate()
self._align_mates()

# pylint: disable=R0912
def _align_mates(self):
"""Decide mate relationship by alignment."""

Expand Down Expand Up @@ -186,7 +187,7 @@ def _align_mates(self):
if self._compare_alignments(mate1[read_counter], reads2):
concordant += 1

if read_counter > 0:
try:
if (concordant / read_counter) >= self.cutoff:
self.results.relationship = (
StatesTypeRelationship.split_mates
Expand All @@ -199,7 +200,7 @@ def _align_mates(self):
self.results.relationship = (
StatesTypeRelationship.not_mates
)
else:
except ZeroDivisionError:
self.results.relationship = (
StatesTypeRelationship.not_available
)
Expand Down
35 changes: 32 additions & 3 deletions tests/test_get_library_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ def test_evaluate_mate_relationship_split_mates(self):
)

def test_evaluate_mate_relationship_not_mates(self, tmpdir):
"""Test mate relationship evaluation logic with input files that are
mates, but the relationship is not enough to trigger split_mates.
"""
CONFIG.args.path_1_processed = FILE_MATE_1
CONFIG.args.path_2_processed = FILE_MATE_2
CONFIG.args.t_file_processed = FILE_TRANSCRIPTS
CONFIG.args.tmp_dir = tmpdir
MAPPING.paths = (FILE_MATE_1, FILE_MATE_2)
MAPPING.transcripts_file = FILE_TRANSCRIPTS
MAPPING.tmp_dir = tmpdir

test_instance = GetLibType(config=CONFIG, mapping=MAPPING)
test_instance.results.file_1 = StatesType.not_available
test_instance.results.file_2 = StatesType.not_available

# Set the cutoff such that it's not enough to trigger split_mates
test_instance.cutoff = 300

# Call the _evaluate_mate_relationship method
test_instance._evaluate_mate_relationship(
ids_1=["A", "B", "C"], ids_2=["A", "B", "C"]
)

assert (
test_instance.results.relationship ==
StatesTypeRelationship.not_mates
)

def test_evaluate_mate_relationship_not_available(self, tmpdir):
"""Test mate relationship evaluation logic with input files that are
not mates from a paired-end library.
"""
Expand All @@ -124,12 +153,12 @@ def test_evaluate_mate_relationship_not_mates(self, tmpdir):
MAPPING.tmp_dir = tmpdir
test_instance = GetLibType(config=CONFIG,
mapping=MAPPING)
test_instance.results.file_1 = StatesType.first_mate
test_instance.results.file_2 = StatesType.second_mate
test_instance.results.file_1 = StatesType.not_available
test_instance.results.file_2 = StatesType.not_available
test_instance.evaluate()
assert (
test_instance.results.relationship ==
StatesTypeRelationship.not_mates
StatesTypeRelationship.not_available
)

def test_evaluate_split_mates_not_matching_ids(self, tmpdir):
Expand Down

0 comments on commit 455e983

Please sign in to comment.