From 9bd123c0a1f2fbc32685110d552d6aaba9212ff8 Mon Sep 17 00:00:00 2001 From: kedhammar Date: Thu, 30 May 2024 15:11:14 +0000 Subject: [PATCH] add lots of tests --- .../test_demux/test_adaptor.py | 156 ++++++++++++++++-- 1 file changed, 146 insertions(+), 10 deletions(-) diff --git a/tests/test_anglerfish/test_demux/test_adaptor.py b/tests/test_anglerfish/test_demux/test_adaptor.py index 95bd0b0..f5b0b61 100644 --- a/tests/test_anglerfish/test_demux/test_adaptor.py +++ b/tests/test_anglerfish/test_demux/test_adaptor.py @@ -1,15 +1,13 @@ import re -import pytest - -from anglerfish.demux import adaptor as adaptor_to_test +from anglerfish.demux import adaptor as to_test def test_has_match(): assert ( - adaptor_to_test.has_match(re.compile("pattern"), "thereisapatterninthisstring") is True + to_test.has_match(re.compile("pattern"), "thereisapatterninthisstring") is True ) - assert adaptor_to_test.has_match(re.compile("pattern"), "nothinghere") is False + assert to_test.has_match(re.compile("pattern"), "nothinghere") is False def test_validate_adaptors(): @@ -19,7 +17,7 @@ def test_validate_adaptors(): "i7": "CAGTGGAA", }, } - assert adaptor_to_test.validate_adaptors(valid_adaptors_dict) is None + assert to_test.validate_adaptors(valid_adaptors_dict) is None invalid_adaptors_dict = { "falseq_umi": { @@ -28,7 +26,7 @@ def test_validate_adaptors(): }, } try: - adaptor_to_test.validate_adaptors(invalid_adaptors_dict) + to_test.validate_adaptors(invalid_adaptors_dict) except UserWarning as e: assert e else: @@ -36,13 +34,151 @@ def test_validate_adaptors(): def test_load_adaptors(): - adaptors = adaptor_to_test.load_adaptors() + adaptors = to_test.load_adaptors() assert adaptors assert isinstance(adaptors, list) for adaptor in adaptors: - assert isinstance(adaptor, adaptor_to_test.Adaptor) + assert isinstance(adaptor, to_test.Adaptor) - adaptors_raw = adaptor_to_test.load_adaptors(raw = True) + adaptors_raw = to_test.load_adaptors(raw=True) assert isinstance(adaptors_raw, dict) for adaptor in adaptors_raw: assert isinstance(adaptors_raw[adaptor], dict) + + +class TestAdaptorPart: + """Explicit combinatorial testing, ugly but effective and readable.""" + + def test_simple(self): + adaptor_part = to_test.AdaptorPart( + sequence_token="ATCG", name="simple", index_seq=None + ) + assert adaptor_part.sequence_token == "ATCG" + assert adaptor_part.name == "simple" + assert adaptor_part.index_seq is None + assert adaptor_part.has_index is False + assert adaptor_part.len_index == 0 + assert adaptor_part.has_umi is False + assert adaptor_part.len_umi == 0 + assert adaptor_part.len_before_index is None + assert adaptor_part.len_after_index is None + assert adaptor_part.len_umi_before_index is None + assert adaptor_part.len_umi_after_index is None + assert adaptor_part.len_total == 4 + assert adaptor_part.len_constant == 4 + assert adaptor_part.get_mask(insert_Ns=True) == "ATCG" + assert adaptor_part.get_mask(insert_Ns=False) == "ATCG" + + def test_unknown_index(self): + adaptor_part = to_test.AdaptorPart( + sequence_token="ATCGATC", name="unknown_index", index_seq=None + ) + assert adaptor_part.sequence_token == "ATCGATC" + assert adaptor_part.name == "unknown_index" + assert adaptor_part.index_seq is None + assert adaptor_part.has_index is True + assert adaptor_part.len_index is None + assert adaptor_part.has_umi is False + assert adaptor_part.len_umi == 0 + assert adaptor_part.len_before_index == 4 + assert adaptor_part.len_after_index == 3 + assert adaptor_part.len_umi_before_index == 0 + assert adaptor_part.len_umi_after_index == 0 + assert adaptor_part.len_total is None + assert adaptor_part.len_constant == 7 + try: + adaptor_part.get_mask(insert_Ns=True) + except UserWarning as e: + assert e + else: + raise AssertionError("UserWarning not raised") + assert adaptor_part.get_mask(insert_Ns=False) == "ATCGATC" + + def test_known_index(self): + adaptor_part = to_test.AdaptorPart( + sequence_token="ATCGATC", name="known_index", index_seq="GGG" + ) + assert adaptor_part.sequence_token == "ATCGATC" + assert adaptor_part.name == "known_index" + assert adaptor_part.index_seq == "GGG" + assert adaptor_part.has_index is True + assert adaptor_part.len_index == 3 + assert adaptor_part.has_umi is False + assert adaptor_part.len_umi == 0 + assert adaptor_part.len_before_index == 4 + assert adaptor_part.len_after_index == 3 + assert adaptor_part.len_umi_before_index == 0 + assert adaptor_part.len_umi_after_index == 0 + assert adaptor_part.len_total == 10 + assert adaptor_part.len_constant == 7 + assert adaptor_part.get_mask(insert_Ns=True) == "ATCGNNNATC" + assert adaptor_part.get_mask(insert_Ns=False) == "ATCGATC" + + def test_unknown_index_umi(self): + adaptor_part = to_test.AdaptorPart( + sequence_token="ATCGATC", name="unknown_index_umi", index_seq=None + ) + assert adaptor_part.sequence_token == "ATCGATC" + assert adaptor_part.name == "unknown_index_umi" + assert adaptor_part.index_seq is None + assert adaptor_part.has_index is True + assert adaptor_part.len_index is None + assert adaptor_part.has_umi is True + assert adaptor_part.len_umi == 5 + assert adaptor_part.len_before_index == 4 + assert adaptor_part.len_after_index == 8 + assert adaptor_part.len_umi_before_index == 0 + assert adaptor_part.len_umi_after_index == 5 + assert adaptor_part.len_total is None + assert adaptor_part.len_constant == 7 + try: + adaptor_part.get_mask(insert_Ns=True) + except UserWarning as e: + assert e + else: + raise AssertionError("UserWarning not raised") + assert adaptor_part.get_mask(insert_Ns=False) == "ATCGATC" + + def test_known_index_umi(self): + adaptor_part = to_test.AdaptorPart( + sequence_token="ATCGATC", name="known_index_umi", index_seq="GGG" + ) + assert adaptor_part.sequence_token == "ATCGATC" + assert adaptor_part.name == "known_index_umi" + assert adaptor_part.index_seq == "GGG" + assert adaptor_part.has_index is True + assert adaptor_part.len_index == 3 + assert adaptor_part.has_umi is True + assert adaptor_part.len_umi == 5 + assert adaptor_part.len_before_index == 4 + assert adaptor_part.len_after_index == 8 + assert adaptor_part.len_umi_before_index == 0 + assert adaptor_part.len_umi_after_index == 5 + assert adaptor_part.len_total == 15 + assert adaptor_part.len_constant == 7 + assert adaptor_part.get_mask(insert_Ns=True) == "ATCGNNNNNNNNATC" + assert adaptor_part.get_mask(insert_Ns=False) == "ATCGATC" + + def test_umi_known_index(self): + adaptor_part = to_test.AdaptorPart( + sequence_token="ATCGATC", name="umi_known_index", index_seq="GGG" + ) + assert adaptor_part.sequence_token == "ATCGATC" + assert adaptor_part.name == "umi_known_index" + assert adaptor_part.index_seq == "GGG" + assert adaptor_part.has_index is True + assert adaptor_part.len_index == 3 + assert adaptor_part.has_umi is True + assert adaptor_part.len_umi == 5 + assert adaptor_part.len_before_index == 9 + assert adaptor_part.len_after_index == 3 + assert adaptor_part.len_umi_before_index == 5 + assert adaptor_part.len_umi_after_index == 0 + assert adaptor_part.len_total == 15 + assert adaptor_part.len_constant == 7 + assert adaptor_part.get_mask(insert_Ns=True) == "ATCGNNNNNNNNATC" + assert adaptor_part.get_mask(insert_Ns=False) == "ATCGATC" + +class TestAdaptor: + + raise AssertionError("WIP") \ No newline at end of file