Skip to content

Commit

Permalink
add tests and safeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
kedhammar committed May 31, 2024
1 parent d7a8a14 commit 4eefaad
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions anglerfish/demux/adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 51 additions & 3 deletions tests/test_anglerfish/test_demux/test_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
def test_adaptor(self):
adaptors = {
"simple_and_index_umi": {
"i5": "AAA",
"i7": "AAA<N><U4>CCC",
}
}

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"
)

0 comments on commit 4eefaad

Please sign in to comment.