Skip to content

Commit f28be59

Browse files
authored
feat: default to tie_correct=True in v2 (#4504)
1 parent 7f37356 commit f28be59

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎docs/release-notes/4504.feat.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add preset support to the `tie_correct` parameter of {func}`scanpy.tl.rank_genes_groups`: {attr}`~scanpy.Preset.ScanpyV2Preview` enables tie correction for `wilcoxon`, which changes its scores, p-values, and gene ranking on sparse data {smaller}`P Angerer`

‎src/scanpy/_settings/presets.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class BasicEmbeddingPreset(NamedTuple):
9797
class RankGenesGroupsPreset(NamedTuple):
9898
method: DETest
9999
mean_in_log_space: bool
100+
tie_correct: bool
100101

101102

102103
class ScalePreset(NamedTuple):
@@ -221,16 +222,16 @@ def pca() -> Mapping[Preset, PcaPreset]:
221222
def umap() -> Mapping[Preset, UmapPreset]:
222223
"""Settings for :func:`~scanpy.tl.umap`.""" # noqa: D401
223224
return {
224-
Preset.ScanpyV1: DiffmapPreset(key_added=None),
225-
Preset.ScanpyV2Preview: DiffmapPreset(key_added="umap"),
225+
Preset.ScanpyV1: UmapPreset(key_added=None),
226+
Preset.ScanpyV2Preview: UmapPreset(key_added="umap"),
226227
}
227228

228229
@preset_property
229230
def tsne() -> Mapping[Preset, UmapPreset]:
230231
"""Settings for :func:`~scanpy.tl.tsne`.""" # noqa: D401
231232
return {
232-
Preset.ScanpyV1: DiffmapPreset(key_added=None),
233-
Preset.ScanpyV2Preview: DiffmapPreset(key_added="tsne"),
233+
Preset.ScanpyV1: TsnePreset(key_added=None),
234+
Preset.ScanpyV2Preview: TsnePreset(key_added="tsne"),
234235
}
235236

236237
@preset_property
@@ -258,10 +259,10 @@ def rank_genes_groups() -> Mapping[Preset, RankGenesGroupsPreset]:
258259
"""
259260
return {
260261
Preset.ScanpyV1: RankGenesGroupsPreset(
261-
method="t-test", mean_in_log_space=True
262+
method="t-test", mean_in_log_space=True, tie_correct=False
262263
),
263264
Preset.ScanpyV2Preview: RankGenesGroupsPreset(
264-
method="wilcoxon", mean_in_log_space=False
265+
method="wilcoxon", mean_in_log_space=False, tie_correct=True
265266
),
266267
}
267268

‎src/scanpy/tools/_rank_genes_groups.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def rank_genes_groups( # noqa: PLR0912, PLR0913, PLR0915
801801
pts: bool = False,
802802
method: DETest | Default = Default(preset=("rank_genes_groups", "method")),
803803
corr_method: _CorrMethod = "benjamini-hochberg",
804-
tie_correct: bool = False,
804+
tie_correct: bool | Default = Default(preset=("rank_genes_groups", "tie_correct")),
805805
use: LayerAcc | str | None = None,
806806
mean_in_log_space: bool | Default = Default(
807807
preset=("rank_genes_groups", "mean_in_log_space")
@@ -939,6 +939,8 @@ def rank_genes_groups( # noqa: PLR0912, PLR0913, PLR0915
939939
mask = _mask_arg(mask, mask_var, dim="var")
940940
if isinstance(mean_in_log_space, Default):
941941
mean_in_log_space = settings.preset.rank_genes_groups.mean_in_log_space
942+
if isinstance(tie_correct, Default):
943+
tie_correct = settings.preset.rank_genes_groups.tie_correct
942944
# If scanpy presets are used for v2, use illico - prevents the presets from showing the `wilcoxon_illico` method and allows us to silently replace `wilcoxon`'s implementation.
943945
if method is None or isinstance(method, Default):
944946
method = settings.preset.rank_genes_groups.method

0 commit comments

Comments
 (0)