Skip to content

Commit

Permalink
Backport PR #2782: Fix Seurat n_top_genes default (#2783)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Dec 19, 2023
1 parent 4058e36 commit 1daae5b
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 145 deletions.
2 changes: 2 additions & 0 deletions docs/release-notes/1.9.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- Specify correct version of `matplotlib` dependency {pr}`2733` {smaller}`P Fisher`
- Fix {func}`scanpy.pl.violin` usage of `seaborn.catplot` {pr}`2739` {smaller}`E Roellin`
- Fix {func}`scanpy.pp.highly_variable_genes` to handle the combinations of `inplace` and `subset` consistently {pr}`2757` {smaller}`E Roellin`
- Replace usage of various deprecated functionality from {mod}`anndata` and {mod}`pandas` {pr}`2678` {pr}`2779` {smaller}`P Angerer`
- Allow to use default `n_top_genes` when using {func}`scanpy.pp.highly_variable_genes` flavor `'seurat_v3'` {pr}`2782` {smaller}`P Angerer`
22 changes: 14 additions & 8 deletions scanpy/preprocessing/_highly_variable_genes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import warnings
from typing import Literal, Optional
from inspect import signature
from typing import Literal, Optional, cast

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -301,13 +304,13 @@ def _highly_variable_genes_single_batch(

def highly_variable_genes(
adata: AnnData,
layer: Optional[str] = None,
n_top_genes: Optional[int] = None,
min_disp: Optional[float] = 0.5,
max_disp: Optional[float] = np.inf,
min_mean: Optional[float] = 0.0125,
max_mean: Optional[float] = 3,
span: Optional[float] = 0.3,
layer: str | None = None,
n_top_genes: int | None = None,
min_disp: float | None = 0.5,
max_disp: float | None = np.inf,
min_mean: float | None = 0.0125,
max_mean: float | None = 3,
span: float = 0.3,
n_bins: int = 20,
flavor: Literal["seurat", "cell_ranger", "seurat_v3"] = "seurat",
subset: bool = False,
Expand Down Expand Up @@ -432,6 +435,9 @@ def highly_variable_genes(
)

if flavor == "seurat_v3":
if n_top_genes is None:
sig = signature(_highly_variable_genes_seurat_v3)
n_top_genes = cast(int, sig.parameters["n_top_genes"].default)
return _highly_variable_genes_seurat_v3(
adata,
layer=layer,
Expand Down
Loading

0 comments on commit 1daae5b

Please sign in to comment.