Skip to content

Commit 59a4c15

Browse files
committed
add testing coverage for copy_umi_from_read_name with and without removeUmi=True; add strict=True tests for extract_umis_from_read_name()
1 parent 569b1bc commit 59a4c15

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

fgpyo/sam/tests/test_umi_methods.py

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
2-
from fgpyo.sam import extract_umi_from_read_name, _is_valid_umi
2+
from fgpyo.sam import extract_umis_from_read_name, _is_valid_umi, copy_umi_from_read_name, AlignedSegment
3+
from fgpyo.sam.builder import SamBuilder
4+
35

46
@pytest.mark.parametrize(
57
"umi,validity",
@@ -30,7 +32,7 @@ def test_is_valid_umi(umi: str, validity: bool) -> None:
3032
)
3133
def test_extract_umi_from_read_name(read_name: str, umi: str) -> None:
3234
"""Test that we can extract UMI from a read name."""
33-
assert extract_umi_from_read_name(read_name) == umi
35+
assert extract_umis_from_read_name(read_name) == umi
3436

3537

3638
@pytest.mark.parametrize(
@@ -47,4 +49,41 @@ def test_extract_umi_from_read_name(read_name: str, umi: str) -> None:
4749
def test_extract_umi_from_read_name_raises(read_name: str) -> None:
4850
"""Test that we raise an error when the read name includes an invalid UMI."""
4951
with pytest.raises(ValueError):
50-
extract_umi_from_read_name(read_name)
52+
extract_umis_from_read_name(read_name)
53+
54+
@pytest.mark.parametrize(
55+
"read_name, extraction",
56+
[
57+
("abc:def:ghi:jfk:lmn:opq:ACGT",None), #colons == 6
58+
("abc:def:ghi:jfk:lmn:opq:rst:ACGT","ACGT"), #colons == 7
59+
],
60+
)
61+
def test_strict_extract_umi_from_read_name(read_name: str, extraction: str) -> None:
62+
"""Test that we raise an error when strict=True and number of colons is not 7 or 8."""
63+
assert extract_umis_from_read_name(read_name, strict=True) == extraction
64+
65+
@pytest.mark.parametrize(
66+
"read_name",
67+
[
68+
("abc:def:ghi:jfk"),
69+
("abc:def:ghi:jfk:lmn:opq:rst:uvw:xyz"),
70+
("abc:def:ghi:jfk:lmn:opq:rst:") #Invalid UMI
71+
],
72+
)
73+
def test_strict_extract_umi_from_read_name_raises(read_name: str) -> None:
74+
"""Test that we raise an error when strict=True and number of colons is not 7 or 8."""
75+
with pytest.raises(ValueError):
76+
extract_umis_from_read_name(read_name,strict=True)
77+
def test_copy_umi_from_read_name() -> None:
78+
builder = SamBuilder()
79+
read = builder.add_single(name="read_name:GATTACA")
80+
copy_umi_from_read_name(read, remove_umi=False)
81+
assert read.qname == "read_name:GATTACA"
82+
assert read.get_tag("RX") == "GATTACA"
83+
84+
def test_copy_remove_umi_from_read_name() -> None:
85+
builder = SamBuilder()
86+
read = builder.add_single(name="read_name:GATTACA")
87+
copy_umi_from_read_name(read, remove_umi=True)
88+
assert read.qname == "read_name"
89+
assert read.get_tag("RX") == "GATTACA"

0 commit comments

Comments
 (0)