From 4eefaad0e69718682b9fbe904548d025ea887240 Mon Sep 17 00:00:00 2001 From: kedhammar Date: Fri, 31 May 2024 09:09:58 +0000 Subject: [PATCH] add tests and safeguard --- anglerfish/demux/adaptor.py | 4 ++ .../test_demux/test_adaptor.py | 54 +++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/anglerfish/demux/adaptor.py b/anglerfish/demux/adaptor.py index 041c729..4d9db5a 100644 --- a/anglerfish/demux/adaptor.py +++ b/anglerfish/demux/adaptor.py @@ -76,6 +76,10 @@ def __init__(self, sequence_token: str, name: str, index_seq: str | None): self.len_index = len(index_seq) if index_seq else None else: + if self.index_seq is not None: + raise UserWarning( + "Index sequence specified, but no index token found in adaptor sequence." + ) self.has_index = False self.len_index = 0 diff --git a/tests/test_anglerfish/test_demux/test_adaptor.py b/tests/test_anglerfish/test_demux/test_adaptor.py index ccc301e..8745d8a 100644 --- a/tests/test_anglerfish/test_demux/test_adaptor.py +++ b/tests/test_anglerfish/test_demux/test_adaptor.py @@ -48,11 +48,22 @@ def test_load_adaptors(): class TestAdaptorPart: """Explicit combinatorial testing, ugly but effective and readable. - + Here-in are contained test cases for a variety of instantiated AdaptorPart objects. All attributes and methods are tested for correctness. """ + def test_should_fail(self): + """Specifying an index on an adaptor without an index should raise a UserWarning.""" + try: + to_test.AdaptorPart( + sequence_token="ATCG", name="should_fail", index_seq="AAA" + ) + except UserWarning as e: + assert e + else: + raise AssertionError("UserWarning not raised") + def test_simple(self): adaptor_part = to_test.AdaptorPart( sequence_token="ATCG", name="simple", index_seq=None @@ -183,6 +194,43 @@ def test_umi_known_index(self): 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 + def test_adaptor(self): + adaptors = { + "simple_and_index_umi": { + "i5": "AAA", + "i7": "AAACCC", + } + } + + adaptor = to_test.Adaptor( + "simple_and_index_umi", adaptors, i5_index=None, i7_index="TTT" + ) + assert adaptor.name == "simple_and_index_umi" + assert isinstance(adaptor.i5, to_test.AdaptorPart) + assert isinstance(adaptor.i7, to_test.AdaptorPart) + assert ( + adaptor.get_fastastring(insert_Ns=True) + == "\n".join( + [ + ">simple_and_index_umi_i5", + "AAA", + ">simple_and_index_umi_i7", + "AAANNNNNNNCCC", + ] + ) + + "\n" + ) + assert ( + adaptor.get_fastastring(insert_Ns=False) + == "\n".join( + [ + ">simple_and_index_umi_i5", + "AAA", + ">simple_and_index_umi_i7", + "AAACCC", + ] + ) + + "\n" + )