1+ import numpy as np
2+ import pandas as pd
13import pytest
24
35
@@ -15,3 +17,34 @@ def test_evaluate_expression_transfer_layers_and_methods(self, cmap, eval_layer,
1517 assert cmap .query .var [f"metric_{ method } " ] is not None
1618 if groupby == "batch" :
1719 assert cmap .query .varm [f"metric_{ method } " ] is not None
20+
21+ @pytest .mark .parametrize (
22+ "log,percentile" ,
23+ [
24+ (False , (0 , 100 )),
25+ (True , (0 , 100 )),
26+ (False , (5 , 95 )),
27+ (True , (1 , 99 )),
28+ ],
29+ )
30+ def test_presence_score_overall (self , cmap , log , percentile ):
31+ cmap .estimate_presence_score (log = log , percentile = percentile )
32+ assert "presence_score" in cmap .ref .obs
33+ scores = cmap .ref .obs ["presence_score" ]
34+ assert isinstance (scores , pd .Series | np .ndarray )
35+ assert np .all ((scores >= 0 ) & (scores <= 1 ))
36+ assert not np .all (scores == 0 ) # Should not be all zeros
37+
38+ @pytest .mark .parametrize ("groupby" , ["batch" , "modality" ])
39+ def test_presence_score_groupby (self , cmap , groupby ):
40+ cmap .estimate_presence_score (groupby = groupby )
41+ # Overall score should always be present in .obs
42+ assert "presence_score" in cmap .ref .obs
43+ # Per-group scores should be present in .obsm
44+ assert "presence_score" in cmap .ref .obsm
45+ df = cmap .ref .obsm ["presence_score" ]
46+ assert isinstance (df , pd .DataFrame )
47+ assert all (np .all ((df [col ] >= 0 ) & (df [col ] <= 1 )) for col in df .columns )
48+ # Columns should match group names
49+ groups = cmap .query .obs [groupby ].unique ()
50+ assert set (df .columns ) == set (groups )
0 commit comments