1
1
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
+
3
5
4
6
@pytest .mark .parametrize (
5
7
"umi,validity" ,
@@ -30,7 +32,7 @@ def test_is_valid_umi(umi: str, validity: bool) -> None:
30
32
)
31
33
def test_extract_umi_from_read_name (read_name : str , umi : str ) -> None :
32
34
"""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
34
36
35
37
36
38
@pytest .mark .parametrize (
@@ -47,4 +49,41 @@ def test_extract_umi_from_read_name(read_name: str, umi: str) -> None:
47
49
def test_extract_umi_from_read_name_raises (read_name : str ) -> None :
48
50
"""Test that we raise an error when the read name includes an invalid UMI."""
49
51
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