Skip to content

Commit

Permalink
Merge pull request #132 from sudlab/ns-rse/90-zip-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-rse authored Jan 10, 2025
2 parents 910159b + d977138 commit c0259a9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
4 changes: 2 additions & 2 deletions isoslam/all_introns_counts_and_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def fragment_iterator(read_iterator):
## If not, we should cull assignment to those events
## We are comparing ret vs spliced, so instead of adding 1 to both
## we will just ignore those few
block_starts1, block_ends1 = zip(*read1.get_blocks())
block_starts2, block_ends2 = zip(*read2.get_blocks())
block_starts1, block_ends1 = isoslam.zip_blocks(read1)
block_starts2, block_ends2 = isoslam.zip_blocks(read2)
# RETAINED
read1_within_intron = {}

Expand Down
19 changes: 18 additions & 1 deletion isoslam/isoslam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""IsoSLAM module."""

from collections import defaultdict
from collections.abc import Generator
from collections.abc import Generator, Iterator
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -179,3 +179,20 @@ def extract_utron(features: dict[str, Any], gene_transcript: Any, coordinates: A
untranslated_regions = [coordinates[transcript] for transcript in gene_transcript[features["transcript"]]]
return sum(untranslated_regions, [])
return []


def zip_blocks(read: AlignedSegment) -> Iterator[tuple[Any, ...]]:
"""
Zip the block starts and ends into two lists.
Parameters
----------
read : AlignedSegment
An individual aligned segment read from a ''.bam'' file.
Returns
-------
tuple[list[int], list[int]]
Tuple of two lists of integers the first is start location, the second is the end location.
"""
return zip(*read.get_blocks())
41 changes: 41 additions & 0 deletions tests/test_isoslam.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,44 @@ def test_extract_utron(
assert len(untranslated_region) == length
if len(untranslated_region):
assert untranslated_region[0][3] == transcript_id # type: ignore[misc]


@pytest.mark.parametrize(
("aligned_segment", "expected_start", "expected_end"),
[
pytest.param( # type: ignore[misc]
"aligned_segment_unassigned_28584",
(28584, 28704),
(28704, 28733),
id="28584 - Assignment and Transcript are None",
),
pytest.param(
"aligned_segment_assigned_17814",
(17814, 18027),
(17855, 18136),
id="17814 - Assigned to MSTRG.63147",
),
pytest.param(
"aligned_segment_assigned_14770",
(14770,),
(14876,),
id="14770 - Assigned to MSTRG.63147",
),
pytest.param(
"aligned_segment_assigned_15967",
(15967,),
(16117,),
id="15967 - Assigned to MSTRG.63147",
),
],
)
def test_zip_blocks(
aligned_segment: str,
expected_start: tuple[int],
expected_end: tuple[int],
request: pytest.FixtureRequest,
) -> None:
"""Test that block starts and ends are zipped correctly."""
start_blocks, end_blocks = isoslam.zip_blocks(request.getfixturevalue(aligned_segment))
assert start_blocks == expected_start
assert end_blocks == expected_end

0 comments on commit c0259a9

Please sign in to comment.