Skip to content

Commit 24181af

Browse files
committed
fixup! informed horseshoe: rename annotations_varm_key to annotations_mkey
also rename public API methods to contain the axis name
1 parent 9792b43 commit 24181af

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/mofaflex/_core/priors/horseshoe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def n_informed_factors(self) -> int:
296296
return self._n_informed_factors
297297

298298
@Prior._api(has_factors=False)
299-
def get_significant_annotations(self) -> Mapping[str, pd.DataFrame]:
299+
def get_significant_a̲x̲i̲s̲_annotations(self) -> Mapping[str, pd.DataFrame]:
300300
"""Get the results of significance testing of annotations against factors.
301301
302302
The significance testing is an implementation of PCGSE :cite:p:`pmid26300978`. While
@@ -310,6 +310,6 @@ def get_significant_annotations(self) -> Mapping[str, pd.DataFrame]:
310310

311311
@Prior._api(has_factors=True, factors_subset="factors_subset")
312312
@property
313-
def annotations(self) -> Mapping[str, pd.DataFrame]:
313+
def a̲x̲i̲s̲_annotations(self) -> Mapping[str, pd.DataFrame]:
314314
"""Annotation matrices for each view."""
315315
return MappingProxyType(self._annotations)

src/mofaflex/pl/_plotting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def factor_significance(
548548
alpha: False discovery rate threshold.
549549
figsize: Figure size in inches.
550550
"""
551-
pcgse_results = model.get_significant_annotations()
551+
pcgse_results = model.get_significant_weight_annotations()
552552
if pcgse_results is None:
553553
raise ValueError("PCGSE results not available.")
554554

@@ -581,7 +581,7 @@ def factor_significance(
581581
)
582582
r2 = model.get_r2("term")
583583
annotations = pd.concat(
584-
{view_name: vannot.sum(axis=0) for view_name, vannot in model.get_annotations().items()}, axis=0
584+
{view_name: vannot.sum(axis=0) for view_name, vannot in model.get_weight_annotations().items()}, axis=0
585585
).rename_axis(index=("view", "annotation"))
586586
# Rank factors by the variance they explain within the selected views/groups, rather than overall, so that
587587
# restricting `views` reorders the plot accordingly.
@@ -1056,7 +1056,7 @@ def _prepare_weights_df(
10561056
):
10571057
weights = model.get_weights(ordered=False)
10581058
try:
1059-
annotations = model.get_annotations(ordered=False)
1059+
annotations = model.get_weight_annotations(ordered=False)
10601060
except AttributeError:
10611061
annotations = {}
10621062
if views is None:

tests/test_mofaflex_integration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def test_integration(
208208
assert model.n_informed_factors > 0
209209
assert model.terms["_"].n_informed_factors > 0
210210
assert model.n_informed_factors == model.terms["_"].n_informed_factors
211-
assert "get_annotations" in dir(model)
212-
assert all(isinstance(annot, pd.DataFrame) for annot in model.get_annotations().values())
211+
assert "get_weight_annotations" in dir(model)
212+
assert all(isinstance(annot, pd.DataFrame) for annot in model.get_weight_annotations().values())
213213
elif argname == "guiding_vars_obs_keys":
214214
assert model.n_guided_factors == model.terms["_"].n_guided_factors == 3
215215
else:
@@ -220,9 +220,9 @@ def test_integration(
220220
== model.terms["_"].n_total_factors
221221
== 5
222222
)
223-
assert "get_annotations" not in dir(model)
223+
assert "get_weight_annotations" not in dir(model)
224224
with pytest.raises(AttributeError, match="is only available when using the 'InformedHorseshoe' prior"):
225-
model.get_annotations()
225+
model.get_weight_annotations()
226226

227227
if fitargs.get("save_path") is not False:
228228
loaded_model = MOFAFLEX.load(path=next(iter(tmp_path.glob("*.h5"))))
@@ -330,14 +330,14 @@ def test_integration_dynamicapi_multiple_priors(anndata_dict, tmp_path, n_partic
330330
n_particles=n_particles,
331331
save_path=save_path,
332332
)
333-
signif = model.get_significant_annotations()
333+
signif = model.get_significant_weight_annotations()
334334
assert len(signif) == 1
335335
assert next(iter(signif.keys())) == "view_normal"
336336
assert signif["view_normal"]["factor"].cat.categories.size == 11
337337

338338
# Loading without an explicit map_location uses the serialized training device.
339339
reloaded = MOFAFLEX.load(save_path)
340-
assert reloaded.get_significant_annotations().keys() == signif.keys()
340+
assert reloaded.get_significant_weight_annotations().keys() == signif.keys()
341341

342342

343343
def test_load_uses_training_device_for_gp(anndata_dict, tmp_path, monkeypatch):

tests/test_pcgse.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def test_test_annotation_significance_data_None_corr_True(mousebrain_model):
99
with pytest.raises(ValueError):
1010
mfl.tl.test_annotation_significance(
11-
mousebrain_model, mousebrain_model.get_annotations(), data=None, corr_adjust=True
11+
mousebrain_model, mousebrain_model.get_weight_annotations(), data=None, corr_adjust=True
1212
)
1313

1414

@@ -19,7 +19,7 @@ def test_test_annotation_significance_annotations_empty(mousebrain_model):
1919

2020
def test_test_annotation_significance(mousebrain_model):
2121
results = mfl.tl.test_annotation_significance(
22-
mousebrain_model, mousebrain_model.get_annotations(), data=None, corr_adjust=False
22+
mousebrain_model, mousebrain_model.get_weight_annotations(), data=None, corr_adjust=False
2323
)
2424

2525
assert isinstance(results, dict)
@@ -33,7 +33,7 @@ def test_pcgse_test(mousebrain_model):
3333
results = pcgse_test(
3434
data=None,
3535
nonnegative_weights={"view_1": True},
36-
annotations=mousebrain_model.get_annotations(),
36+
annotations=mousebrain_model.get_weight_annotations(),
3737
weights=mousebrain_model.get_weights(),
3838
corr_adjust=False,
3939
)
@@ -48,7 +48,7 @@ def test_test_single_view_nonnegative(mousebrain_model):
4848
_test_single_view(
4949
"view_1",
5050
nonnegative_weights=True,
51-
feature_sets=mousebrain_model.get_annotations()["view_1"],
51+
feature_sets=mousebrain_model.get_weight_annotations()["view_1"],
5252
factor_loadings=mousebrain_model.get_weights()["view_1"],
5353
y=None,
5454
sign="neg",
@@ -59,7 +59,7 @@ def test_test_single_view_nonnegative(mousebrain_model):
5959

6060

6161
def test_test_single_view_empty(mousebrain_model):
62-
feature_sets_empty = mousebrain_model.get_annotations()["view_1"] & False
62+
feature_sets_empty = mousebrain_model.get_weight_annotations()["view_1"] & False
6363

6464
assert (
6565
_test_single_view(
@@ -80,7 +80,7 @@ def test_test_single_view_repeated_factor_names(mousebrain_model):
8080
result = _test_single_view(
8181
"view_1",
8282
nonnegative_weights=True,
83-
feature_sets=mousebrain_model.get_annotations()["view_1"],
83+
feature_sets=mousebrain_model.get_weight_annotations()["view_1"],
8484
factor_loadings=pd.concat((factors, factors), axis=1),
8585
y=None,
8686
sign="pos",
@@ -95,7 +95,7 @@ def test_test_single_view(mousebrain_model, sign):
9595
results = _test_single_view(
9696
"view_1",
9797
nonnegative_weights=False,
98-
feature_sets=mousebrain_model.get_annotations()["view_1"],
98+
feature_sets=mousebrain_model.get_weight_annotations()["view_1"],
9999
factor_loadings=mousebrain_model.get_weights()["view_1"],
100100
y=None,
101101
sign=sign,
@@ -112,7 +112,7 @@ def test_single_guided_factor(mousebrain_model):
112112
results = _test_single_view(
113113
"view_1",
114114
nonnegative_weights=False,
115-
feature_sets=mousebrain_model.get_annotations()["view_1"].iloc[:, :1],
115+
feature_sets=mousebrain_model.get_weight_annotations()["view_1"].iloc[:, :1],
116116
factor_loadings=mousebrain_model.get_weights()["view_1"],
117117
y=None,
118118
sign="all",

0 commit comments

Comments
 (0)