Skip to content

Commit

Permalink
Merge pull request #133 from sudlab/ns-rse/131-expand-test-fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-rse authored Jan 10, 2025
2 parents c0259a9 + 6b6a354 commit 83bb05c
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 9 deletions.
3 changes: 3 additions & 0 deletions isoslam/all_introns_counts_and_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def fragment_iterator(read_iterator):

# Extract features
pair_features = isoslam.extract_features_from_pair(pair)
# DEBUGGING - Get information on features
if i_total_progress in (484):
print(f"{pair_features=}")
# Temporary code sets up variables from the returned dictionary to match those currently used
read1_start = pair_features["read1"]["start"]
read1_end = pair_features["read1"]["end"]
Expand Down
50 changes: 43 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,60 @@ def aligned_segment_unassigned_18029(bam_unaligned_file1: AlignmentFile) -> Alig


@pytest.fixture()
def bam_sorted_assigned_file() -> list[AlignedSegment]:
def bam_sorted_assigned_file_no4sU() -> list[AlignedSegment]:
"""Return a list of a ``AlignedSegment`` from a ``.bam`` file that has been sorted and assigned."""
return list(io.load_file(BAM_SORTED_ASSIGNED_DIR / "d0_no4sU_filtered_remapped_sorted.sorted.assigned.bam"))


@pytest.fixture()
def aligned_segment_assigned_15967(bam_sorted_assigned_file: list[AlignedSegment]) -> AlignedSegment:
def aligned_segment_assigned_15967(bam_sorted_assigned_file_no4sU: list[AlignedSegment]) -> AlignedSegment:
"""Return a single assigned AlignedSegment where start is 15967."""
return [x for x in bam_sorted_assigned_file if x.reference_start == 15967][0]
return [x for x in bam_sorted_assigned_file_no4sU if x.reference_start == 15967][0]


@pytest.fixture()
def aligned_segment_assigned_14770(bam_sorted_assigned_file: list[AlignedSegment]) -> AlignedSegment:
def aligned_segment_assigned_14770(bam_sorted_assigned_file_no4sU: list[AlignedSegment]) -> AlignedSegment:
"""Return a single assigned AlignedSegment where start is 14770."""
return [x for x in bam_sorted_assigned_file if x.reference_start == 14770][0]
return [x for x in bam_sorted_assigned_file_no4sU if x.reference_start == 14770][0]


@pytest.fixture()
def aligned_segment_assigned_17814(bam_sorted_assigned_file: list[AlignedSegment]) -> AlignedSegment:
def aligned_segment_assigned_17814(bam_sorted_assigned_file_no4sU: list[AlignedSegment]) -> AlignedSegment:
"""Return a single assigned AlignedSegment where start is 17814."""
return [x for x in bam_sorted_assigned_file if x.reference_start == 17814][0]
return [x for x in bam_sorted_assigned_file_no4sU if x.reference_start == 17814][0]


@pytest.fixture()
def bam_sorted_assigned_file_0hr1() -> list[AlignedSegment]:
"""Return a list of a ``AlignedSegment`` from a ``.bam`` file that has been sorted and assigned."""
return list(io.load_file(BAM_SORTED_ASSIGNED_DIR / "d0_0hr1_filtered_remapped_sorted.sorted.assigned.bam"))


@pytest.fixture()
def aligned_segment_assigned_21051(bam_sorted_assigned_file_0hr1: list[AlignedSegment]) -> AlignedSegment:
"""
Return a single assigned AlignedSegment where start is 21051.
Along with the next fixture (20906) this was the 484th pair of reads that caused some early problems with regression
tests which is why they have been pulled out and added to the parameterised tests.
The reason these problems occurred is because initially 9 alignments are found at this location but 6 of these
should be filtered out subsequently, a mistake in refactoring used the wrong length. But this will serve as a useful
aligned segment to be testing because of this filtering.
"""
return [x for x in bam_sorted_assigned_file_0hr1 if x.reference_start == 21051][0]


@pytest.fixture()
def aligned_segment_assigned_20906(bam_sorted_assigned_file_0hr1: list[AlignedSegment]) -> AlignedSegment:
"""
Return a single assigned AlignedSegment where start is 20906.
Along with the previous fixture (21051) this was the 484th pair of reads that cause some early problems with
regression tests which is why they have been pulled out and added to the parameterised tests.
The reason these problems occurred is because initially 9 alignments are found at this location but 6 of these
should be filtered out subsequently, a mistake in refactoring used the wrong length. But this will serve as a useful
aligned segment to be testing because of this filtering.
"""
return [x for x in bam_sorted_assigned_file_0hr1 if x.reference_start == 20906][0]
75 changes: 73 additions & 2 deletions tests/test_isoslam.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ def test_extract_segment_pairs(bam_file: str | Path, expected_length: int) -> No
(16117,),
id="15967 - Assigned to MSTRG.63147",
),
pytest.param(
"aligned_segment_assigned_21051",
21051,
21201,
150,
"Unassigned_NoFeatures",
None,
(21051,),
(21201,),
id="21051 - Unassigned",
),
pytest.param(
"aligned_segment_assigned_20906",
20906,
21056,
150,
"Unassigned_NoFeatures",
None,
(20906,),
(21056,),
id="20906 - Unassigned",
),
],
)
def test_extract_features_from_read(
Expand All @@ -177,7 +199,7 @@ def test_extract_features_from_read(
) -> None:
"""Test extract of features from an unassigned and assigned segment reads."""
segment = isoslam.extract_features_from_read(request.getfixturevalue(aligned_segment))
print(f"{segment['length']}")
print(f"{segment=}")
assert isinstance(segment, dict)
assert segment["start"] == start
assert segment["end"] == end
Expand Down Expand Up @@ -214,7 +236,32 @@ def test_extract_features_from_read(
"block_end": (14876,),
},
},
id="28584 and 17416 - Assignment and Transcript are None",
id="28584 and 17416 - Assigned and transcript MSTRG.63147",
),
pytest.param(
"aligned_segment_assigned_21051",
"aligned_segment_assigned_20906",
{
"read1": {
"start": 21051,
"end": 21201,
"length": 150,
"status": "Unassigned_NoFeatures",
"transcript": None,
"block_start": (21051,),
"block_end": (21201,),
},
"read2": {
"start": 20906,
"end": 21056,
"length": 150,
"status": "Unassigned_NoFeatures",
"transcript": None,
"block_start": (20906,),
"block_end": (21056,),
},
},
id="21051 and 21056 - Assignment and Transcript are None",
),
],
)
Expand Down Expand Up @@ -262,6 +309,18 @@ def test_extract_features_from_pair(
10,
id="15967 - Assigned to MSTRG.63147",
),
pytest.param(
"aligned_segment_assigned_21051",
None,
0,
id="21051 - Unassigned",
),
pytest.param(
"aligned_segment_assigned_20906",
None,
0,
id="20906 - Unassigned",
),
],
)
def test_extract_utron(
Expand Down Expand Up @@ -309,6 +368,18 @@ def test_extract_utron(
(16117,),
id="15967 - Assigned to MSTRG.63147",
),
pytest.param(
"aligned_segment_assigned_21051",
(21051,),
(21201,),
id="21051 - Unassigned",
),
pytest.param(
"aligned_segment_assigned_20906",
(20906,),
(21056,),
id="20906 - Unassigned",
),
],
)
def test_zip_blocks(
Expand Down

0 comments on commit 83bb05c

Please sign in to comment.