Coverage for tests/test_utils.py: 93%
51 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-07-11 14:46 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-07-11 14:46 +0200
1import unittest
4import yaml
5import numpy as np
6from pathlib import Path
7import MPP
8import MPP.run as run_module
11config_dir = "/data/evaluation/MPP/stochastic_MPP_Felix/data_production/sm/config/"
12root = "/data/evaluation/MPP/stochastic_MPP_Felix/data_production/sm/results/"
14SYSTEMS = [
15 "HP35",
16 "PDZ3_7",
17 "aSyn_rdc_200ns",
18 "HP35_stoch",
19]
20SETUPS = [
21 "t",
22 "kl",
23 "t_js",
24 "kl_js",
25 "gpcca",
26]
28with open(f"{config_dir}lumpings.yaml") as f:
29 lumpings = yaml.safe_load(f)
32def get_d(system, setup, rmsd=False):
33 d = run_module.Data(
34 f"/data/evaluation/MPP/stochastic_MPP_Felix/data_production/sm/config/{system}.yaml"
35 )
36 d.setup_mpp(
37 lumpings[setup]["kernel similarity"],
38 lumpings[setup]["feature kernel"],
39 )
40 if setup == "gpcca": 40 ↛ 41line 40 didn't jump to line 41 because the condition on line 40 was never true
41 d.perform_gpcca("ref", f"{root}{system}/{setup}/Z.npy")
42 else:
43 d.perform_mpp(f"{root}{system}/{setup}/Z.npy")
44 if rmsd: 44 ↛ 45line 44 didn't jump to line 45 because the condition on line 44 was never true
45 d.mpp.load_rmsd(f"{root}{system}/{setup}/rmsd.npy")
46 return d
49class TestProperties(unittest.TestCase):
50 def setUp(self):
51 self.d = get_d("HP35", "t")
52 self.mpp = self.d.mpp
54 def test_Z_to_linkage(self):
55 linkage = MPP.utils.Z_to_linkage(self.mpp.Z[self.mpp.n_i])
56 expected_linkage = np.load(
57 Path(__file__).parent
58 / "data"
59 / "HP35"
60 / "expected_output"
61 / "t"
62 / "linkage.npy"
63 )
64 np.testing.assert_allclose(linkage, expected_linkage)
66 def test_linkage_to_Z(self):
67 expected_linkage = np.load(
68 Path(__file__).parent
69 / "data"
70 / "HP35"
71 / "expected_output"
72 / "t"
73 / "linkage.npy"
74 )
75 z_i, full_pop = MPP.utils.linkage_to_Z(expected_linkage, self.mpp.pop)
76 expected_z = np.load(
77 Path(__file__).parent / "data" / "HP35" / "expected_output" / "t" / "Z.npy"
78 )
79 np.testing.assert_allclose(z_i, expected_z[0])
81 def test_calc_full_tmat(self):
82 expected_tmat = np.load(
83 Path(__file__).parent
84 / "data"
85 / "HP35"
86 / "expected_output"
87 / "t"
88 / "full_tmat.npy"
89 )
90 expected_pop = np.load(
91 Path(__file__).parent
92 / "data"
93 / "HP35"
94 / "expected_output"
95 / "t"
96 / "full_pop.npy"
97 )
98 full_tmat, full_pop = MPP.utils.calc_full_tmat(
99 self.mpp.tmat, self.mpp.pop, self.mpp.Z
100 )
101 np.testing.assert_allclose(full_tmat, expected_tmat)
102 np.testing.assert_allclose(full_pop, expected_pop)
104 def test_Z_to_mask(self):
105 expected_mask = np.load(
106 Path(__file__).parent
107 / "data"
108 / "HP35"
109 / "expected_output"
110 / "t"
111 / "full_mask.npy"
112 )
113 full_mask = MPP.utils.Z_to_mask(self.mpp.Z[0])
114 np.testing.assert_allclose(full_mask, expected_mask)
117class TestFullFeature(unittest.TestCase):
118 def setUp(self):
119 self.d = get_d("HP35", "t_js")
121 def test_full_feature_from_Z(self):
122 expected_full_feature = np.load(
123 Path(__file__).parent
124 / "data"
125 / "HP35"
126 / "expected_output"
127 / "t_js"
128 / "full_feature.npy"
129 )
130 full_feature = self.d.feature_kernel.full_feature_from_Z(self.d.mpp.Z)
131 np.testing.assert_allclose(full_feature, expected_full_feature)