Skip to content

Commit 5fe547d

Browse files
committed
feat: Add end property on SupplementaryAlignment
1 parent a41a565 commit 5fe547d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

fgpyo/sam/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ def __str__(self) -> str:
551551
)
552552
)
553553

554+
@property
555+
def end(self) -> int:
556+
"""The 0-based exclusive end position of the alignment."""
557+
return self.start + self.cigar.length_on_target()
558+
554559
@staticmethod
555560
def parse(string: str) -> "SupplementaryAlignment":
556561
"""Returns a supplementary alignment parsed from the given string. The various fields

fgpyo/sam/tests/test_supplementary_alignments.py

+9
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ def test_from_read() -> None:
6969

7070
read = builder.add_single(attrs={"SA": f"{s1};{s2};"})
7171
assert SupplementaryAlignment.from_read(read) == [sa1, sa2]
72+
73+
74+
def test_end() -> None:
75+
"""Test that we can get the end of a SupplementaryAlignment."""
76+
77+
s1 = SupplementaryAlignment.parse("chr1,123,+,50S100M,60,0")
78+
79+
# NB: the SA tag is one-based, but SupplementaryAlignment is zero-based
80+
assert s1.end == 222

0 commit comments

Comments
 (0)