Skip to content

Pipelines

Pipelines: the preprocessing calls you repeat on every subset, written once.

Chain steps with >> into a Pipeline and apply it. A step_* function wraps one module function (step_hvg is bv.pp.find_hvg, step_pca is bv.pp.calculate_pca, and so on) with its arguments bound; Step wraps any other function that takes the object first. Nothing runs until apply_pipeline. It checks the chain against the class of the object, then calls each step in order. Start with apply_pipeline_per_group when the point is sub-clustering or per-donor processing.

What lands where. A pipeline is inert, so building one touches nothing. apply_pipeline runs the steps on the object you pass and the results land where each wrapped function puts them: the HVGs and PCA in sc.map and sc.cache, the clusters in obs. apply_pipeline_per_group cuts one SingleCellsSubset per obs level over the kept cells, runs the pipeline on each and returns a dict keyed by group; the parent is left alone. step_metacells is the one step that changes the class: it takes a SingleCells or SingleCellsSubset and hands a MetaCells to the steps after it, so a pipeline ending on it gives you meta cells that never mix two groups. meta_cells_per_group does that in one call and merges them with merge_meta_cells.

pipe = (
    bv.pipeline.step_hvg(hvg_no=500)
    >> bv.pipeline.step_pca(20)
    >> bv.pipeline.step_neighbours()
    >> bv.pipeline.step_clusters(res=0.5, name="sub_leiden")
)
per_sample = bv.pipeline.apply_pipeline_per_group(pipe, sc, "sample_id")

# End on meta cells: one set per sample, never mixed
params = bv.params.BtMetacellsParams(target_no_metacells=50)
mc_pipe = pipe >> bv.pipeline.step_metacells("bootstrapped", params=params)
per_sample_mc = bv.pipeline.apply_pipeline_per_group(mc_pipe, sc, "sample_id")

Step also takes the bixverse_gpu twins:

import bixverse_gpu as bvg

gpu_pca = bv.pipeline.Step("gpu_pca", bvg.pp.calculate_pca, {"no_pcs": 20})
bv.pipeline.apply_pipeline(bv.pipeline.step_hvg(hvg_no=500) >> gpu_pca, sc)

Gotchas. Arguments are bound when the step is built, so a misspelt keyword fails there, and the class check runs before the first step does, so a bad chain fails before the expensive part. Order is on you otherwise: clusters and meta cells need step_neighbours first, which needs the PCA. The integration steps (step_harmony, step_harmony_v1, step_bbknn, step_fast_mnn) take a SingleCells or a subset, not MetaCells, so they go before step_metacells. step_fast_mnn wants the batch-aware HVGs from bv.pp.find_hvg_batch_aware. After step_harmony, point step_neighbours at it with embd_to_use="harmony". Applied to a SingleCells, a pipeline writes into that object.

Worked through in Sub-clustering and per-group pipelines.

Applying a pipeline

Pipelines: the preprocessing calls you repeat on every subset, written once.

Chain steps with >> into a Pipeline and apply it. A step_* function wraps one module function (step_hvg is bv.pp.find_hvg, step_pca is bv.pp.calculate_pca, and so on) with its arguments bound; Step wraps any other function that takes the object first. Nothing runs until apply_pipeline. It checks the chain against the class of the object, then calls each step in order. Start with apply_pipeline_per_group when the point is sub-clustering or per-donor processing.

What lands where. A pipeline is inert, so building one touches nothing. apply_pipeline runs the steps on the object you pass and the results land where each wrapped function puts them: the HVGs and PCA in sc.map and sc.cache, the clusters in obs. apply_pipeline_per_group cuts one SingleCellsSubset per obs level over the kept cells, runs the pipeline on each and returns a dict keyed by group; the parent is left alone. step_metacells is the one step that changes the class: it takes a SingleCells or SingleCellsSubset and hands a MetaCells to the steps after it, so a pipeline ending on it gives you meta cells that never mix two groups. meta_cells_per_group does that in one call and merges them with merge_meta_cells.

pipe = (
    bv.pipeline.step_hvg(hvg_no=500)
    >> bv.pipeline.step_pca(20)
    >> bv.pipeline.step_neighbours()
    >> bv.pipeline.step_clusters(res=0.5, name="sub_leiden")
)
per_sample = bv.pipeline.apply_pipeline_per_group(pipe, sc, "sample_id")

# End on meta cells: one set per sample, never mixed
params = bv.params.BtMetacellsParams(target_no_metacells=50)
mc_pipe = pipe >> bv.pipeline.step_metacells("bootstrapped", params=params)
per_sample_mc = bv.pipeline.apply_pipeline_per_group(mc_pipe, sc, "sample_id")

Step also takes the bixverse_gpu twins:

import bixverse_gpu as bvg

gpu_pca = bv.pipeline.Step("gpu_pca", bvg.pp.calculate_pca, {"no_pcs": 20})
bv.pipeline.apply_pipeline(bv.pipeline.step_hvg(hvg_no=500) >> gpu_pca, sc)

Gotchas. Arguments are bound when the step is built, so a misspelt keyword fails there, and the class check runs before the first step does, so a bad chain fails before the expensive part. Order is on you otherwise: clusters and meta cells need step_neighbours first, which needs the PCA. The integration steps (step_harmony, step_harmony_v1, step_bbknn, step_fast_mnn) take a SingleCells or a subset, not MetaCells, so they go before step_metacells. step_fast_mnn wants the batch-aware HVGs from bv.pp.find_hvg_batch_aware. After step_harmony, point step_neighbours at it with embd_to_use="harmony". Applied to a SingleCells, a pipeline writes into that object.

Pipeline dataclass

Pipeline(steps: Sequence[Step] = ())

A linear chain of steps. Inert until applied.

Build it from a list of steps, Pipeline([step_hvg(), step_pca(30)]), or chain steps with >> as shorthand: step_hvg() >> step_pca(30).

Attributes:

Name Type Description
steps Sequence[Step]

The steps, in order. Any sequence; stored as a tuple.

Step dataclass

Step(
    name: str,
    fn: Callable[..., object],
    kwargs: dict[str, object] = dict(),
    accepts: tuple[type, ...] = (
        SingleCells,
        SingleCellsSubset,
    ),
    returns: type | None = None,
)

One pipeline step.

The keyword arguments are bound against the function's signature, the object standing in first, so a misspelt or missing argument fails here rather than after the expensive steps before it ran.

Attributes:

Name Type Description
name str

Short identifier shown when printing the pipeline.

fn Callable[..., object]

Takes the object first. Its return value is ignored unless returns is set.

kwargs dict[str, object]

Keyword arguments passed to fn at apply time.

accepts tuple[type, ...]

The classes fn can take.

returns type | None

The class fn returns, None if it modifies the object in place and hands nothing back.

Raises:

Type Description
TypeError

If kwargs do not bind to fn.

ValueError

If accepts or returns is not a step class.

Examples:

>>> fit = {"method": "analytic_pearson"}
>>> step = bv.pipeline.Step("residuals", bv.pp.fit_residuals, fit)

apply_pipeline

Run each step in order.

The chain is validated against the class of obj before anything runs. Steps modify the object in place; a meta cell step's result replaces it for the steps after.

Parameters:

Name Type Description Default
pipeline Pipeline

The pipeline.

required
obj SingleCells | SingleCellsSubset | MetaCells

The object the first step receives.

required

Returns:

Type Description
SingleCells | SingleCellsSubset | MetaCells

obj, or the object the last class-changing step returned.

Raises:

Type Description
TypeError

If the chain cannot run on obj, or a class-changing step returns something else, e.g. None from a generator without an embedding.

Examples:

>>> sc = bv.pipeline.apply_pipeline(pipe, sc)
>>> mc = bv.pipeline.apply_pipeline(mc_pipe, sc)

apply_pipeline_per_group

apply_pipeline_per_group(
    pipeline: Pipeline,
    sc: SingleCells,
    group_col: str,
    *,
    groups: Sequence[str] | None = None,
    progress: bool = False,
) -> dict[str, SingleCells | SingleCellsSubset | MetaCells]

Run a pipeline independently on each group.

Each group is cut as a SingleCellsSubset over the kept cells, so the parent is left alone. A pipeline ending on step_metacells gives source-pure meta cells, which merge_meta_cells puts back together.

Parameters:

Name Type Description Default
pipeline Pipeline

The pipeline.

required
sc SingleCells

The experiment.

required
group_col str

obs column to split on.

required
groups Sequence[str] | None

The levels to use; None for every level among the kept cells, in order of appearance.

None
progress bool

Log a line per group.

False

Returns:

Type Description
dict[str, SingleCells | SingleCellsSubset | MetaCells]

The processed objects, keyed by group.

Raises:

Type Description
TypeError

If the chain cannot run on a SingleCellsSubset.

ValueError

If group_col is not in obs.

Examples:

>>> per_group = bv.pipeline.apply_pipeline_per_group(pipe, sc, "sample_id")
>>> per_group = bv.pipeline.apply_pipeline_per_group(
...     pipe, sc, "sample_id", groups=["sample_1", "sample_2"]
... )

validate_pipeline

validate_pipeline(pipeline: Pipeline, cls: type) -> type

Check that a pipeline can run on an object of class cls.

Walks the chain tracking the class each step would receive: most steps hand back what they got, a meta cell step returns a MetaCells.

Parameters:

Name Type Description Default
pipeline Pipeline

The pipeline.

required
cls type

SingleCells, SingleCellsSubset or MetaCells.

required

Returns:

Type Description
type

The class the pipeline would return.

Raises:

Type Description
TypeError

If a step cannot take what the step before hands it.

ValueError

If cls is not a step class.

Examples:

>>> end = bv.pipeline.validate_pipeline(mc_pipe, bv.SingleCellsSubset)

Preprocessing steps

Pipelines: the preprocessing calls you repeat on every subset, written once.

Chain steps with >> into a Pipeline and apply it. A step_* function wraps one module function (step_hvg is bv.pp.find_hvg, step_pca is bv.pp.calculate_pca, and so on) with its arguments bound; Step wraps any other function that takes the object first. Nothing runs until apply_pipeline. It checks the chain against the class of the object, then calls each step in order. Start with apply_pipeline_per_group when the point is sub-clustering or per-donor processing.

What lands where. A pipeline is inert, so building one touches nothing. apply_pipeline runs the steps on the object you pass and the results land where each wrapped function puts them: the HVGs and PCA in sc.map and sc.cache, the clusters in obs. apply_pipeline_per_group cuts one SingleCellsSubset per obs level over the kept cells, runs the pipeline on each and returns a dict keyed by group; the parent is left alone. step_metacells is the one step that changes the class: it takes a SingleCells or SingleCellsSubset and hands a MetaCells to the steps after it, so a pipeline ending on it gives you meta cells that never mix two groups. meta_cells_per_group does that in one call and merges them with merge_meta_cells.

pipe = (
    bv.pipeline.step_hvg(hvg_no=500)
    >> bv.pipeline.step_pca(20)
    >> bv.pipeline.step_neighbours()
    >> bv.pipeline.step_clusters(res=0.5, name="sub_leiden")
)
per_sample = bv.pipeline.apply_pipeline_per_group(pipe, sc, "sample_id")

# End on meta cells: one set per sample, never mixed
params = bv.params.BtMetacellsParams(target_no_metacells=50)
mc_pipe = pipe >> bv.pipeline.step_metacells("bootstrapped", params=params)
per_sample_mc = bv.pipeline.apply_pipeline_per_group(mc_pipe, sc, "sample_id")

Step also takes the bixverse_gpu twins:

import bixverse_gpu as bvg

gpu_pca = bv.pipeline.Step("gpu_pca", bvg.pp.calculate_pca, {"no_pcs": 20})
bv.pipeline.apply_pipeline(bv.pipeline.step_hvg(hvg_no=500) >> gpu_pca, sc)

Gotchas. Arguments are bound when the step is built, so a misspelt keyword fails there, and the class check runs before the first step does, so a bad chain fails before the expensive part. Order is on you otherwise: clusters and meta cells need step_neighbours first, which needs the PCA. The integration steps (step_harmony, step_harmony_v1, step_bbknn, step_fast_mnn) take a SingleCells or a subset, not MetaCells, so they go before step_metacells. step_fast_mnn wants the batch-aware HVGs from bv.pp.find_hvg_batch_aware. After step_harmony, point step_neighbours at it with embd_to_use="harmony". Applied to a SingleCells, a pipeline writes into that object.

step_hvg

step_hvg(
    *,
    hvg_no: int = 2000,
    hvg_params: HvgParams | None = None,
    streaming: bool | None = None,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.pp.find_hvg.

Parameters:

Name Type Description Default
hvg_no int

Number of HVGs, forwarded.

2000
hvg_params HvgParams | None

The HVG parameters, forwarded.

None
streaming bool | None

Read the genes in batches, forwarded.

None
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

Examples:

>>> step = bv.pipeline.step_hvg(hvg_no=500)

step_pca

step_pca(
    no_pcs: int = 30,
    *,
    pca_params: PcaParams | None = None,
    sparse_svd: bool | None = None,
    hvg: ndarray
    | Sequence[int]
    | Sequence[str]
    | None = None,
    seed: int = 42,
    residuals: bool = False,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.pp.calculate_pca.

Parameters:

Name Type Description Default
no_pcs int

Number of components, forwarded.

30
pca_params PcaParams | None

The PCA parameters, forwarded.

None
sparse_svd bool | None

Solve on the sparse matrix, forwarded.

None
hvg ndarray | Sequence[int] | Sequence[str] | None

Gene indices or ids to use instead of the stored HVGs, forwarded.

None
seed int

Seed, forwarded.

42
residuals bool

PCA on the residuals of fit_residuals, forwarded.

False
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

Examples:

>>> step = bv.pipeline.step_pca(20, sparse_svd=False)

step_neighbours

step_neighbours(
    *,
    embd_to_use: str = "pca",
    no_embd_to_use: int | None = None,
    modality: CacheModality = "rna",
    neighbours_params: NeighboursParams | None = None,
    seed: int = 42,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.graph.find_neighbours.

Parameters:

Name Type Description Default
embd_to_use str

The embedding, forwarded.

'pca'
no_embd_to_use int | None

Number of leading dimensions, forwarded.

None
modality CacheModality

"rna", "adt" or "atac", forwarded.

'rna'
neighbours_params NeighboursParams | None

kNN and graph parameters, forwarded.

None
seed int

Seed, forwarded.

42
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

step_clusters

step_clusters(
    *,
    cluster_algorithm: ClusterAlgorithm = "leiden",
    res: float = 1.0,
    name: str = "leiden_clustering",
    modality: Modality = "rna",
    seed: int = 42,
    beta: float = 0.01,
    n_iterations: int | None = None,
    min_gain: float = 0.0,
    local_moving: LocalMoving | None = None,
    node_order: NodeOrder | None = None,
) -> Step

Pipeline step for bixverse.graph.find_clusters.

Parameters:

Name Type Description Default
cluster_algorithm ClusterAlgorithm

"leiden" or "louvain", forwarded.

'leiden'
res float

Modularity resolution, forwarded.

1.0
name str

The obs column to write, forwarded.

'leiden_clustering'
modality Modality

The graph to cluster, forwarded.

'rna'
seed int

Seed, forwarded.

42
beta float

Randomness of the Leiden refinement, forwarded.

0.01
n_iterations int | None

Full iterations, forwarded.

None
min_gain float

Stopping gain with a negative n_iterations, forwarded.

0.0
local_moving LocalMoving | None

"queue" or "coloured", forwarded.

None
node_order NodeOrder | None

"bfs" or "shuffle", forwarded.

None

Integration steps

Pipelines: the preprocessing calls you repeat on every subset, written once.

Chain steps with >> into a Pipeline and apply it. A step_* function wraps one module function (step_hvg is bv.pp.find_hvg, step_pca is bv.pp.calculate_pca, and so on) with its arguments bound; Step wraps any other function that takes the object first. Nothing runs until apply_pipeline. It checks the chain against the class of the object, then calls each step in order. Start with apply_pipeline_per_group when the point is sub-clustering or per-donor processing.

What lands where. A pipeline is inert, so building one touches nothing. apply_pipeline runs the steps on the object you pass and the results land where each wrapped function puts them: the HVGs and PCA in sc.map and sc.cache, the clusters in obs. apply_pipeline_per_group cuts one SingleCellsSubset per obs level over the kept cells, runs the pipeline on each and returns a dict keyed by group; the parent is left alone. step_metacells is the one step that changes the class: it takes a SingleCells or SingleCellsSubset and hands a MetaCells to the steps after it, so a pipeline ending on it gives you meta cells that never mix two groups. meta_cells_per_group does that in one call and merges them with merge_meta_cells.

pipe = (
    bv.pipeline.step_hvg(hvg_no=500)
    >> bv.pipeline.step_pca(20)
    >> bv.pipeline.step_neighbours()
    >> bv.pipeline.step_clusters(res=0.5, name="sub_leiden")
)
per_sample = bv.pipeline.apply_pipeline_per_group(pipe, sc, "sample_id")

# End on meta cells: one set per sample, never mixed
params = bv.params.BtMetacellsParams(target_no_metacells=50)
mc_pipe = pipe >> bv.pipeline.step_metacells("bootstrapped", params=params)
per_sample_mc = bv.pipeline.apply_pipeline_per_group(mc_pipe, sc, "sample_id")

Step also takes the bixverse_gpu twins:

import bixverse_gpu as bvg

gpu_pca = bv.pipeline.Step("gpu_pca", bvg.pp.calculate_pca, {"no_pcs": 20})
bv.pipeline.apply_pipeline(bv.pipeline.step_hvg(hvg_no=500) >> gpu_pca, sc)

Gotchas. Arguments are bound when the step is built, so a misspelt keyword fails there, and the class check runs before the first step does, so a bad chain fails before the expensive part. Order is on you otherwise: clusters and meta cells need step_neighbours first, which needs the PCA. The integration steps (step_harmony, step_harmony_v1, step_bbknn, step_fast_mnn) take a SingleCells or a subset, not MetaCells, so they go before step_metacells. step_fast_mnn wants the batch-aware HVGs from bv.pp.find_hvg_batch_aware. After step_harmony, point step_neighbours at it with embd_to_use="harmony". Applied to a SingleCells, a pipeline writes into that object.

step_harmony

step_harmony(
    batch_column: str,
    *,
    additional_batch_columns: Sequence[str] | None = None,
    embd_to_use: str = "pca",
    modality: CacheModality = "rna",
    harmony_params: HarmonyV2Params | None = None,
    seed: int = 42,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.integrate.harmony.

Parameters:

Name Type Description Default
batch_column str

obs column with the primary batch, forwarded.

required
additional_batch_columns Sequence[str] | None

Further obs columns to regress out, forwarded.

None
embd_to_use str

The embedding to correct, forwarded.

'pca'
modality CacheModality

The cache to read and write, forwarded.

'rna'
harmony_params HarmonyV2Params | None

The parameters, forwarded.

None
seed int

Seed, forwarded.

42
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

step_harmony_v1

step_harmony_v1(
    batch_column: str,
    *,
    additional_batch_columns: Sequence[str] | None = None,
    embd_to_use: str = "pca",
    modality: CacheModality = "rna",
    harmony_params: HarmonyParams | None = None,
    seed: int = 42,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.integrate.harmony_v1.

Parameters:

Name Type Description Default
batch_column str

obs column with the primary batch, forwarded.

required
additional_batch_columns Sequence[str] | None

Further obs columns to regress out, forwarded.

None
embd_to_use str

The embedding to correct, forwarded.

'pca'
modality CacheModality

The cache to read and write, forwarded.

'rna'
harmony_params HarmonyParams | None

The parameters, forwarded.

None
seed int

Seed, forwarded.

42
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

step_bbknn

step_bbknn(
    batch_column: str,
    *,
    no_neighbours_to_keep: int = 5,
    embd_to_use: Literal["pca"] = "pca",
    no_embd_to_use: int | None = None,
    bbknn_params: BbknnParams | None = None,
    seed: int = 42,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.integrate.bbknn.

Parameters:

Name Type Description Default
batch_column str

obs column with the batch, forwarded.

required
no_neighbours_to_keep int

Neighbours per cell in the stored kNN, forwarded.

5
embd_to_use Literal['pca']

The embedding, only "pca", forwarded.

'pca'
no_embd_to_use int | None

Number of leading dimensions, forwarded.

None
bbknn_params BbknnParams | None

The parameters, forwarded.

None
seed int

Seed, forwarded.

42
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

step_fast_mnn

step_fast_mnn(
    batch_column: str,
    batch_hvg_genes: ndarray
    | Sequence[int]
    | Sequence[str],
    *,
    fastmnn_params: FastmnnParams | None = None,
    use_precomputed_pca: bool = False,
    seed: int = 42,
    verbose: Verbose = True,
) -> Step

Pipeline step for bixverse.integrate.fast_mnn.

Parameters:

Name Type Description Default
batch_column str

obs column with the batch, forwarded.

required
batch_hvg_genes ndarray | Sequence[int] | Sequence[str]

Batch-aware HVG indices or ids, forwarded.

required
fastmnn_params FastmnnParams | None

The parameters, forwarded.

None
use_precomputed_pca bool

Use the cached PCA, forwarded.

False
seed int

Seed, forwarded.

42
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it, forwarded.

True

Meta cells

Pipelines: the preprocessing calls you repeat on every subset, written once.

Chain steps with >> into a Pipeline and apply it. A step_* function wraps one module function (step_hvg is bv.pp.find_hvg, step_pca is bv.pp.calculate_pca, and so on) with its arguments bound; Step wraps any other function that takes the object first. Nothing runs until apply_pipeline. It checks the chain against the class of the object, then calls each step in order. Start with apply_pipeline_per_group when the point is sub-clustering or per-donor processing.

What lands where. A pipeline is inert, so building one touches nothing. apply_pipeline runs the steps on the object you pass and the results land where each wrapped function puts them: the HVGs and PCA in sc.map and sc.cache, the clusters in obs. apply_pipeline_per_group cuts one SingleCellsSubset per obs level over the kept cells, runs the pipeline on each and returns a dict keyed by group; the parent is left alone. step_metacells is the one step that changes the class: it takes a SingleCells or SingleCellsSubset and hands a MetaCells to the steps after it, so a pipeline ending on it gives you meta cells that never mix two groups. meta_cells_per_group does that in one call and merges them with merge_meta_cells.

pipe = (
    bv.pipeline.step_hvg(hvg_no=500)
    >> bv.pipeline.step_pca(20)
    >> bv.pipeline.step_neighbours()
    >> bv.pipeline.step_clusters(res=0.5, name="sub_leiden")
)
per_sample = bv.pipeline.apply_pipeline_per_group(pipe, sc, "sample_id")

# End on meta cells: one set per sample, never mixed
params = bv.params.BtMetacellsParams(target_no_metacells=50)
mc_pipe = pipe >> bv.pipeline.step_metacells("bootstrapped", params=params)
per_sample_mc = bv.pipeline.apply_pipeline_per_group(mc_pipe, sc, "sample_id")

Step also takes the bixverse_gpu twins:

import bixverse_gpu as bvg

gpu_pca = bv.pipeline.Step("gpu_pca", bvg.pp.calculate_pca, {"no_pcs": 20})
bv.pipeline.apply_pipeline(bv.pipeline.step_hvg(hvg_no=500) >> gpu_pca, sc)

Gotchas. Arguments are bound when the step is built, so a misspelt keyword fails there, and the class check runs before the first step does, so a bad chain fails before the expensive part. Order is on you otherwise: clusters and meta cells need step_neighbours first, which needs the PCA. The integration steps (step_harmony, step_harmony_v1, step_bbknn, step_fast_mnn) take a SingleCells or a subset, not MetaCells, so they go before step_metacells. step_fast_mnn wants the batch-aware HVGs from bv.pp.find_hvg_batch_aware. After step_harmony, point step_neighbours at it with embd_to_use="harmony". Applied to a SingleCells, a pipeline writes into that object.

step_metacells

step_metacells(
    method: MetacellMethod = "bootstrapped",
    **kwargs: object,
) -> Step

Pipeline step for a meta cell generator.

Unlike the other steps it changes the class of the object: it takes a SingleCells or SingleCellsSubset and returns a MetaCells, which the steps after it receive. validate_pipeline checks they take one.

Parameters:

Name Type Description Default
method MetacellMethod

"bootstrapped" (bixverse.metacells.generate_bt_meta_cells), "seacells" (generate_seacells) or "supercells" (generate_supercells).

'bootstrapped'
**kwargs object

Keyword arguments for the generator, e.g. params, target_size or verbose; seacell_params for SEACells.

{}

Returns:

Type Description
Step

The step.

Raises:

Type Description
TypeError

If kwargs do not bind to the generator.

Examples:

>>> params = bv.params.BtMetacellsParams(target_no_metacells=50)
>>> step = bv.pipeline.step_metacells("bootstrapped", params=params)

meta_cells_per_group

meta_cells_per_group(
    sc: SingleCells,
    group_col: str,
    *,
    method: MetacellMethod = "bootstrapped",
    mc_params: Mapping[str, object] | None = None,
    pipeline: Pipeline | None = None,
    groups: Sequence[str] | None = None,
    feature_space: str = "intersect",
    verbose: Verbose = True,
) -> MetaCells

Source-pure meta cells: one generator run per group, merged.

Meta cells never mix two groups (patients, samples), yet end up in one object. The generators need an embedding and usually a kNN, so pipeline will normally be step_hvg() >> step_pca(30) >> step_neighbours().

Parameters:

Name Type Description Default
sc SingleCells

The experiment.

required
group_col str

obs column to split on.

required
method MetacellMethod

"bootstrapped", "seacells" or "supercells".

'bootstrapped'
mc_params Mapping[str, object] | None

Keyword arguments for the generator; SEACells needs seacell_params.

None
pipeline Pipeline | None

Run on each subset before its meta cells are generated. Must hand back the subset.

None
groups Sequence[str] | None

The levels to use; None for every level among the kept cells, in order of appearance.

None
feature_space str

Passed to merge_meta_cells.

'intersect'
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it.

True

Returns:

Type Description
MetaCells

The merged meta cells, a source_id column in obs.

Raises:

Type Description
TypeError

If pipeline cannot run on, or does not return, a SingleCellsSubset, or mc_params do not bind to the generator.

ValueError

On a missing column, or a group without meta cells.

Examples:

>>> pipeline = bv.pipeline.step_hvg(hvg_no=500) >> bv.pipeline.step_pca(20)
>>> pipeline = pipeline >> bv.pipeline.step_neighbours()
>>> mc = bv.metacells.meta_cells_per_group(sc, "batch_index", pipeline=pipeline)