diff --git a/htsinfer/get_library_type.py b/htsinfer/get_library_type.py index 545c4d2..cc4bb1e 100644 --- a/htsinfer/get_library_type.py +++ b/htsinfer/get_library_type.py @@ -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.""" @@ -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 @@ -199,7 +200,7 @@ def _align_mates(self): self.results.relationship = ( StatesTypeRelationship.not_mates ) - else: + except ZeroDivisionError: self.results.relationship = ( StatesTypeRelationship.not_available ) diff --git a/tests/test_get_library_type.py b/tests/test_get_library_type.py index dd52dfa..8555694 100644 --- a/tests/test_get_library_type.py +++ b/tests/test_get_library_type.py @@ -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. """ @@ -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):