26
26
27
27
def test_niche_calc_nhood (adata_seqfish : AnnData ):
28
28
"""Check whether niche calculation using neighborhood profile approach works as intended."""
29
- spatial_neighbors (
30
- adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS
31
- )
29
+ spatial_neighbors (adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS )
32
30
calculate_niche (
33
31
adata_seqfish ,
34
32
groups = GROUPS ,
@@ -50,12 +48,8 @@ def test_niche_calc_nhood(adata_seqfish: AnnData):
50
48
matrix = adata_seqfish .obsp [SPATIAL_CONNECTIVITIES_KEY ].tocoo ()
51
49
52
50
# get obs x category matrix where each column is the absolute/relative frequency of a category in the neighborhood
53
- rel_nhood_profile = _calculate_neighborhood_profile (
54
- adata_seqfish , groups = GROUPS , matrix = matrix , abs_nhood = False
55
- )
56
- abs_nhood_profile = _calculate_neighborhood_profile (
57
- adata_seqfish , groups = GROUPS , matrix = matrix , abs_nhood = True
58
- )
51
+ rel_nhood_profile = _calculate_neighborhood_profile (adata_seqfish , groups = GROUPS , matrix = matrix , abs_nhood = False )
52
+ abs_nhood_profile = _calculate_neighborhood_profile (adata_seqfish , groups = GROUPS , matrix = matrix , abs_nhood = True )
59
53
# assert shape obs x groups
60
54
assert rel_nhood_profile .shape == (
61
55
adata_seqfish .n_obs ,
@@ -71,12 +65,8 @@ def test_niche_calc_nhood(adata_seqfish: AnnData):
71
65
72
66
def test_niche_calc_utag (adata_seqfish : AnnData ):
73
67
"""Check whether niche calculation using UTAG approach works as intended."""
74
- spatial_neighbors (
75
- adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS
76
- )
77
- calculate_niche (
78
- adata_seqfish , flavor = "utag" , n_neighbors = N_NEIGHBORS , resolutions = [0.1 , 1.0 ]
79
- )
68
+ spatial_neighbors (adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS )
69
+ calculate_niche (adata_seqfish , flavor = "utag" , n_neighbors = N_NEIGHBORS , resolutions = [0.1 , 1.0 ])
80
70
81
71
niches = adata_seqfish .obs ["utag_niche_res=1.0" ]
82
72
niches_low_res = adata_seqfish .obs ["utag_niche_res=0.1" ]
@@ -112,12 +102,8 @@ def test_niche_calc_utag(adata_seqfish: AnnData):
112
102
def test_niche_calc_cellcharter (adata_seqfish : AnnData ):
113
103
"""Check whether niche calculation using CellCharter approach works as intended."""
114
104
115
- spatial_neighbors (
116
- adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS
117
- )
118
- calculate_niche (
119
- adata_seqfish , groups = GROUPS , flavor = "cellcharter" , distance = 3 , n_components = 5
120
- )
105
+ spatial_neighbors (adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS )
106
+ calculate_niche (adata_seqfish , groups = GROUPS , flavor = "cellcharter" , distance = 3 , n_components = 5 )
121
107
niches = adata_seqfish .obs ["cellcharter_niche" ]
122
108
123
109
assert niches .nunique () == 5
@@ -148,12 +134,8 @@ def test_niche_calc_cellcharter(adata_seqfish: AnnData):
148
134
149
135
class TestNiches (PlotTester , metaclass = PlotTesterMeta ):
150
136
def test_plot_utag_niche (self , adata_seqfish : AnnData ):
151
- spatial_neighbors (
152
- adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS
153
- )
154
- calculate_niche (
155
- adata_seqfish , flavor = "utag" , n_neighbors = N_NEIGHBORS , resolutions = 0.5
156
- )
137
+ spatial_neighbors (adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS )
138
+ calculate_niche (adata_seqfish , flavor = "utag" , n_neighbors = N_NEIGHBORS , resolutions = 0.5 )
157
139
158
140
sq .pl .spatial_scatter (
159
141
adata_seqfish ,
@@ -162,9 +144,7 @@ def test_plot_utag_niche(self, adata_seqfish: AnnData):
162
144
)
163
145
164
146
def test_plot_neighborhood_niche (self , adata_seqfish : AnnData ):
165
- spatial_neighbors (
166
- adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS
167
- )
147
+ spatial_neighbors (adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS )
168
148
169
149
calculate_niche (
170
150
adata_seqfish ,
@@ -182,9 +162,7 @@ def test_plot_neighborhood_niche(self, adata_seqfish: AnnData):
182
162
)
183
163
184
164
def test_plot_cellcharter_niche (self , adata_seqfish : AnnData ):
185
- spatial_neighbors (
186
- adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS
187
- )
165
+ spatial_neighbors (adata_seqfish , coord_type = "generic" , delaunay = False , n_neighs = N_NEIGHBORS )
188
166
calculate_niche (
189
167
adata_seqfish ,
190
168
groups = GROUPS ,
0 commit comments