File size: 1,830 Bytes
23a728e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright 2026 Emile de Bruyn
# SPDX-License-Identifier: Apache-2.0

import pytest

from motifbench_prosite.normalisation import (
    _parse_segment,
    _format_segment,
    remap_segments_with_residue_map,
    remap_contig_string,
)


def test_parse_segment_range():
    chain, start, end = _parse_segment("L24-43")
    assert chain == "L"
    assert start == 24
    assert end == 43


def test_parse_segment_single():
    chain, start, end = _parse_segment("A5")
    assert chain == "A"
    assert start == end == 5


def test_format_segment_range():
    assert _format_segment("A", 1, 10) == "A1-10"


def test_format_segment_single():
    assert _format_segment("B", 7, 7) == "B7"


def test_remap_segments_with_residue_map_simple():
    residue_map = {
        ("L", 24): ("A", 1),
        ("L", 25): ("A", 2),
        ("L", 26): ("A", 3),
    }
    out = remap_segments_with_residue_map("L24-26", residue_map)
    assert out == "A1-3"


def test_remap_segments_with_residue_map_split_chain_and_range_break():
    residue_map = {
        ("L", 24): ("A", 1),
        ("L", 25): ("A", 2),
        ("L", 27): ("A", 4),
        ("H", 10): ("B", 1),
    }
    out = remap_segments_with_residue_map("L24-27;H10-10", residue_map)
    assert set(out.split(";")) == {"A1-2", "A4", "B1"}


def test_remap_segments_drops_unknown():
    residue_map = {("L", 24): ("A", 1)}
    out = remap_segments_with_residue_map("L24-25;H10", residue_map)
    assert out == "A1"


def test_remap_contig_string_motif_segments():
    segment_map = {"L24-43": "A1-20"}
    contig = "0-100;L24-43;10-20"
    out = remap_contig_string(contig, segment_map)
    assert out == "0-100;A1-20;10-20"


def test_remap_contig_string_leaves_numeric_unchanged():
    out = remap_contig_string("0-100;10-20", {"L24-43": "A1-20"})
    assert out == "0-100;10-20"