From 42d8ead14e4c726eab2c9cea72595d0b454b20a3 Mon Sep 17 00:00:00 2001 From: Can Kockan <122313882+kockan@users.noreply.github.com> Date: Mon, 28 Aug 2023 19:07:31 -0400 Subject: [PATCH] Add method is_clipping to CigarOp (#54) * Added is_clipping() to CigarOp --- fgpyo/sam/__init__.py | 5 +++++ fgpyo/sam/tests/test_sam.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/fgpyo/sam/__init__.py b/fgpyo/sam/__init__.py index 508aa96d..c1277f02 100644 --- a/fgpyo/sam/__init__.py +++ b/fgpyo/sam/__init__.py @@ -374,6 +374,11 @@ def is_indel(self) -> bool: """Returns true if the operator is an indel, false otherwise.""" return self == CigarOp.I or self == CigarOp.D + @property + def is_clipping(self) -> bool: + """Returns true if the operator is a soft/hard clip, false otherwise.""" + return self == CigarOp.S or self == CigarOp.H + @attr.s(frozen=True, slots=True) class CigarElement: diff --git a/fgpyo/sam/tests/test_sam.py b/fgpyo/sam/tests/test_sam.py index 80463b1d..03c6b192 100755 --- a/fgpyo/sam/tests/test_sam.py +++ b/fgpyo/sam/tests/test_sam.py @@ -280,6 +280,9 @@ def test_is_indel() -> None: indels = [op for op in CigarOp if op.is_indel] assert indels == [CigarOp.I, CigarOp.D] +def test_is_clipping() -> None: + clips = [op for op in CigarOp if op.is_clipping] + assert clips == [CigarOp.S, CigarOp.H] def test_isize() -> None: builder = SamBuilder()