Skip to content

Commit

Permalink
fix test failures: formatting, use of deprecated qname instead of rec…
Browse files Browse the repository at this point in the history
….query_name
  • Loading branch information
emmcauley committed May 20, 2024
1 parent 37dd872 commit 4d8bc23
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions fgpyo/sam/tests/test_umi_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest
from fgpyo.sam import extract_umis_from_read_name, _is_valid_umi, copy_umi_from_read_name, AlignedSegment

from fgpyo.sam import _is_valid_umi
from fgpyo.sam import copy_umi_from_read_name
from fgpyo.sam import extract_umis_from_read_name
from fgpyo.sam.builder import SamBuilder


Expand Down Expand Up @@ -51,39 +54,44 @@ def test_extract_umi_from_read_name_raises(read_name: str) -> None:
with pytest.raises(ValueError):
extract_umis_from_read_name(read_name)


@pytest.mark.parametrize(
"read_name, extraction",
[
("abc:def:ghi:jfk:lmn:opq:ACGT",None), #colons == 6
("abc:def:ghi:jfk:lmn:opq:rst:ACGT","ACGT"), #colons == 7
("abc:def:ghi:jfk:lmn:opq:ACGT", None), # colons == 6
("abc:def:ghi:jfk:lmn:opq:rst:ACGT", "ACGT"), # colons == 7
],
)
def test_strict_extract_umi_from_read_name(read_name: str, extraction: str) -> None:
"""Test that we raise an error when strict=True and number of colons is not 7 or 8."""
assert extract_umis_from_read_name(read_name, strict=True) == extraction


@pytest.mark.parametrize(
"read_name",
[
("abc:def:ghi:jfk"),
("abc:def:ghi:jfk:lmn:opq:rst:uvw:xyz"),
("abc:def:ghi:jfk:lmn:opq:rst:") #Invalid UMI
("abc:def:ghi:jfk:lmn:opq:rst:"), # Invalid UMI
],
)
def test_strict_extract_umi_from_read_name_raises(read_name: str) -> None:
"""Test that we raise an error when strict=True and number of colons is not 7 or 8."""
with pytest.raises(ValueError):
extract_umis_from_read_name(read_name,strict=True)
extract_umis_from_read_name(read_name, strict=True)


def test_copy_umi_from_read_name() -> None:
builder = SamBuilder()
read = builder.add_single(name="read_name:GATTACA")
copy_umi_from_read_name(read, remove_umi=False)
assert read.qname == "read_name:GATTACA"
assert read.query_name == "read_name:GATTACA"
assert read.get_tag("RX") == "GATTACA"


def test_copy_remove_umi_from_read_name() -> None:
builder = SamBuilder()
read = builder.add_single(name="read_name:GATTACA")
copy_umi_from_read_name(read, remove_umi=True)
assert read.qname == "read_name"
assert read.get_tag("RX") == "GATTACA"
assert read.query_name == "read_name"
assert read.get_tag("RX") == "GATTACA"

0 comments on commit 4d8bc23

Please sign in to comment.