BILBY-PRO / construction /tests /test_normalisation_helpers.py
EdeBruyn's picture
Initial upload for camera-ready version of NeurIPS paper.
23a728e verified
Raw History Blame Contribute Delete
1.83 kB
# 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"