Skip to content

Commit

Permalink
feat: Add end property on SupplementaryAlignment
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Apr 17, 2024
1 parent a41a565 commit 8849c30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@

import enum
import io
from functools import cached_property
from pathlib import Path
from typing import IO
from typing import Any
Expand Down Expand Up @@ -551,6 +552,11 @@ def __str__(self) -> str:
)
)

@cached_property
def end(self) -> int:
"""The 0-based exclusive end position of the alignment."""
return self.start + self.cigar.length_on_target()

@staticmethod
def parse(string: str) -> "SupplementaryAlignment":
"""Returns a supplementary alignment parsed from the given string. The various fields
Expand Down
9 changes: 9 additions & 0 deletions fgpyo/sam/tests/test_supplementary_alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ def test_from_read() -> None:

read = builder.add_single(attrs={"SA": f"{s1};{s2};"})
assert SupplementaryAlignment.from_read(read) == [sa1, sa2]


def test_end() -> None:
"""Test that we can get the end of a SupplementaryAlignment."""

s1 = SupplementaryAlignment.parse("chr1,123,+,50S100M,60,0")

# NB: the SA tag is one-based, but SupplementaryAlignment is zero-based
assert s1.end == 222

0 comments on commit 8849c30

Please sign in to comment.