|
4 | 4 | import os
|
5 | 5 | import pytest
|
6 | 6 |
|
7 |
| -from micall.core.contig_stitcher import split_contigs_with_gaps, stitch_contigs, GenotypedContig, merge_intervals, find_covered_contig, stitch_consensus, calculate_concordance, align_all_to_reference, main, AlignedContig |
| 7 | +from micall.core.contig_stitcher import split_contigs_with_gaps, stitch_contigs, GenotypedContig, merge_intervals, find_covered_contig, stitch_consensus, calculate_concordance, align_all_to_reference, main, AlignedContig, disambiguate_concordance |
8 | 8 | from micall.core.plot_contigs import plot_stitcher_coverage
|
9 | 9 | from micall.tests.utils import MockAligner, fixed_random_seed
|
10 | 10 | from micall.utils.structured_logger import add_structured_handler
|
@@ -974,6 +974,42 @@ def generate_random_string_pair(length):
|
974 | 974 | right = ''.join(random.choice('ACGT') for _ in range(length))
|
975 | 975 | return left, right
|
976 | 976 |
|
| 977 | + |
| 978 | +@pytest.mark.parametrize( |
| 979 | + 'left, right, expected', |
| 980 | + [("aaaaa", "aaaaa", [0.1] * 5), |
| 981 | + ("abcdd", "abcdd", [0.1] * 5), |
| 982 | + ("aaaaaaaa", "baaaaaab", [0.1, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.1]), |
| 983 | + ("aaaaaaaa", "aaaaaaab", [0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.12]), |
| 984 | + ("aaaaaaaa", "aaaaaaab", [0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.12]), |
| 985 | + ("aaaaaaaa", "aaaaabbb", [0.1, 0.1, 0.1, 0.1, 0.1, 0.08, 0.08, 0.08]), |
| 986 | + ("aaaaaaaa", "aaabbaaa", [0.12, 0.12, 0.12, 0.1, 0.1, 0.12, 0.12, 0.12]), |
| 987 | + ("aaaaa", "bbbbb", [0] * 5), |
| 988 | + ] |
| 989 | +) |
| 990 | +def test_concordance_simple(left, right, expected): |
| 991 | + result = [round(x, 2) for x in calculate_concordance(left, right)] |
| 992 | + assert result == expected |
| 993 | + |
| 994 | + |
| 995 | +@pytest.mark.parametrize( |
| 996 | + 'left, right, expected', |
| 997 | + [("a" * 128, "a" * 128, 64), |
| 998 | + ("a" * 128, "a" * 64 + "b" * 64, 32), |
| 999 | + ("a" * 128, "a" * 64 + "ba" * 32, 32), |
| 1000 | + ("a" * 128, "a" * 54 + "b" * 20 + "a" * 54, 28), # two peaks |
| 1001 | + ("a" * 128, "a" * 63 + "b" * 2 + "a" * 63, 32), # two peaks |
| 1002 | + ("a" * 1280, "b" * 640 + "a" * 640, 640 + 30), # the window is too small to account for all of the context |
| 1003 | + ] |
| 1004 | +) |
| 1005 | +def test_concordance_simple_index(left, right, expected): |
| 1006 | + concordance = calculate_concordance(left, right) |
| 1007 | + concordance_d = list(disambiguate_concordance(concordance)) |
| 1008 | + index = max(range(len(concordance)), key=lambda i: concordance_d[i]) |
| 1009 | + if abs(index - expected) > 3: |
| 1010 | + assert index == expected |
| 1011 | + |
| 1012 | + |
977 | 1013 | def generate_test_cases(num_cases):
|
978 | 1014 | with fixed_random_seed(42):
|
979 | 1015 | length = random.randint(1, 80)
|
|
0 commit comments