Skip to content

Commit

Permalink
feat: add assumed mates #160
Browse files Browse the repository at this point in the history
  • Loading branch information
balajtimate committed Jan 19, 2024
1 parent 10e44bd commit 93a0d33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
18 changes: 15 additions & 3 deletions htsinfer/get_library_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ def _align_mates(self):
LOGGER.debug(f"Number of aligned reads file 2: {aligned_mate2}")
LOGGER.debug(f"Number of concordant reads: {concordant}")

self._update_relationship(
self._update_relationship_type(
concordant, min(aligned_mate1, aligned_mate2)
)

samfile1.close()
samfile2.close()

def _update_relationship(self, concordant, aligned_reads):
"""Helper function to update relationship based on alignment."""
def _update_relationship_type(self, concordant, aligned_reads):
"""Helper function to update relationship and type."""
try:
ratio = concordant / aligned_reads
except ZeroDivisionError:
Expand All @@ -253,6 +253,18 @@ def _update_relationship(self, concordant, aligned_reads):
self.results.relationship = (
StatesTypeRelationship.not_mates
)
if self.results.relationship == (
StatesTypeRelationship.split_mates
) and (
self.results.file_1 == StatesType.single and
self.results.file_2 == StatesType.single
) or (
self.results.file_1 == StatesType.not_available and
self.results.file_2 == StatesType.not_available
):
# Update first and second relationship
self.results.file_1 = StatesType.first_mate_assumed
self.results.file_2 = StatesType.second_mate_assumed

class AlignedSegment:
"""Placeholder class for mypy "Missing attribute"
Expand Down
2 changes: 2 additions & 0 deletions htsinfer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ class StatesType(Enum):
that the library represents a single-end library.
"""
first_mate = "first_mate"
first_mate_assumed = "first_mate_assumed"
mixed_mates = "mixed_mates"
not_available = None
second_mate = "second_mate"
second_mate_assumed = "second_mate_assumed"
single = "single"


Expand Down
6 changes: 3 additions & 3 deletions tests/test_get_library_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_evaluate_mate_relationship_not_available(self, tmpdir):
StatesTypeRelationship.not_available
)

def test_update_relationship_not_mates(self, tmpdir):
def test_update_relationship_type_not_mates(self, tmpdir):
"""Test update_relationship logic."""
CONFIG.args.path_1_processed = FILE_IDS_NOT_MATCH_1
CONFIG.args.path_2_processed = FILE_MATE_2
Expand All @@ -185,8 +185,8 @@ def test_update_relationship_not_mates(self, tmpdir):
concordant = 0
read_counter = 20

# Call the _update_relationship method
test_instance._update_relationship(concordant, read_counter)
# Call the _update_relationship_type method
test_instance._update_relationship_type(concordant, read_counter)

assert (
test_instance.results.relationship ==
Expand Down

0 comments on commit 93a0d33

Please sign in to comment.