Skip to content

Commit

Permalink
add lots of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kedhammar committed May 30, 2024
1 parent 656d710 commit 9bd123c
Showing 1 changed file with 146 additions and 10 deletions.
156 changes: 146 additions & 10 deletions tests/test_anglerfish/test_demux/test_adaptor.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -19,7 +17,7 @@ def test_validate_adaptors():
"i7": "CAGT<N><U9>GGAA",
},
}
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": {
Expand All @@ -28,21 +26,159 @@ 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:
raise AssertionError("UserWarning not raised")


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="ATCG<N>ATC", name="unknown_index", index_seq=None
)
assert adaptor_part.sequence_token == "ATCG<N>ATC"
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="ATCG<N>ATC", name="known_index", index_seq="GGG"
)
assert adaptor_part.sequence_token == "ATCG<N>ATC"
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="ATCG<N><U5>ATC", name="unknown_index_umi", index_seq=None
)
assert adaptor_part.sequence_token == "ATCG<N><U5>ATC"
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="ATCG<N><U5>ATC", name="known_index_umi", index_seq="GGG"
)
assert adaptor_part.sequence_token == "ATCG<N><U5>ATC"
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="ATCG<U5><N>ATC", name="umi_known_index", index_seq="GGG"
)
assert adaptor_part.sequence_token == "ATCG<U5><N>ATC"
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")

0 comments on commit 9bd123c

Please sign in to comment.