Skip to content

Commit

Permalink
feat: Add end property on SupplementaryAlignment (#105)
Browse files Browse the repository at this point in the history
msto authored Apr 18, 2024
1 parent a41a565 commit 88aebeb
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
@@ -551,6 +551,11 @@ def __str__(self) -> str:
)
)

@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
9 changes: 9 additions & 0 deletions fgpyo/sam/tests/test_supplementary_alignments.py
Original file line number Diff line number Diff line change
@@ -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 88aebeb

Please sign in to comment.