czbenchmarks.tasks.single_cell.perturbation_expression_prediction

Attributes

logger

Classes

PerturbationExpressionPredictionTaskInput

Pydantic model for Perturbation task inputs.

PerturbationExpressionPredictionOutput

Output for perturbation task.

PerturbationExpressionPredictionTask

Abstract base class for all benchmark tasks.

Functions

build_task_input_from_predictions(...)

Create a task input from a predictions AnnData and the dataset AnnData.

Module Contents

czbenchmarks.tasks.single_cell.perturbation_expression_prediction.logger
class czbenchmarks.tasks.single_cell.perturbation_expression_prediction.PerturbationExpressionPredictionTaskInput(/, **data: Any)[source]

Bases: czbenchmarks.tasks.task.TaskInput

Pydantic model for Perturbation task inputs.

Dataclass to contain input parameters for the PerturbationExpressionPredictionTask. The row and column ordering of the model predictions can optionallybe provided as cell_index and gene_index, respectively, so the task can align a model matrix that is a subset of or re-ordered relative to the dataset adata.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

adata: anndata.AnnData
pred_effect_operation: Literal['difference', 'ratio'] = ('ratio',)
gene_index: pandas.Index | None = None
cell_index: pandas.Index | None = None
czbenchmarks.tasks.single_cell.perturbation_expression_prediction.build_task_input_from_predictions(predictions_adata: anndata.AnnData, dataset_adata: anndata.AnnData, pred_effect_operation: Literal['difference', 'ratio'] = 'ratio') PerturbationExpressionPredictionTaskInput[source]

Create a task input from a predictions AnnData and the dataset AnnData.

This preserves the predictions’ obs/var order so the task can align matrices without forcing the caller to reorder arrays.

Parameters:
  • predictions_adata (ad.AnnData) – The anndata containing model predictions.

  • dataset_adata (ad.AnnData) – The anndata object from SingleCellPerturbationDataset.

  • pred_effect_operation (Literal["difference", "ratio"]) – How to compute predicted effect between treated and control mean predictions over genes. “difference” uses mean(treated) - mean(control) and is generally safe across scales (probabilities, z-scores, raw expression). “ratio” uses log((mean(treated)+eps)/(mean(control)+eps)) when means are positive. Default is “ratio”.

  • gene_index (Optional[pd.Index]) – The index of the genes in the predictions AnnData.

  • cell_index (Optional[pd.Index]) – The index of the cells in the predictions AnnData.

class czbenchmarks.tasks.single_cell.perturbation_expression_prediction.PerturbationExpressionPredictionOutput(/, **data: Any)[source]

Bases: czbenchmarks.tasks.task.TaskOutput

Output for perturbation task.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

pred_mean_change_dict: Dict[str, numpy.ndarray]
true_mean_change_dict: Dict[str, numpy.ndarray]
class czbenchmarks.tasks.single_cell.perturbation_expression_prediction.PerturbationExpressionPredictionTask(*, random_seed: int = RANDOM_SEED)[source]

Bases: czbenchmarks.tasks.task.Task

Abstract base class for all benchmark tasks.

Defines the interface that all tasks must implement. Tasks are responsible for: 1. Declaring their required input/output data types 2. Running task-specific computations 3. Computing evaluation metrics

Tasks should store any intermediate results as instance variables to be used in metric computation.

Parameters:

random_seed (int) – Random seed for reproducibility

Perturbation Expression Prediction Task.

This task evaluates perturbation-induced expression predictions against their ground truth values. This is done by calculating metrics derived from predicted and ground truth log fold change values for each condition. Currently, Spearman rank correlation is supported.

The following arguments are required and must be supplied by the task input class (PerturbationExpressionPredictionTaskInput) when running the task. These parameters are described below for documentation purposes:

  • predictions_adata (ad.AnnData):

    The anndata containing model predictions

  • dataset_adata (ad.AnnData):

    The anndata object from SingleCellPerturbationDataset.

  • pred_effect_operation (Literal[“difference”, “ratio”]):

    How to compute predicted effect between treated and control mean predictions over genes.

    • “ratio” uses \(\log\left(\frac{\text{mean}(\text{treated}) + \varepsilon}{\text{mean}(\text{control}) + \varepsilon}\right)\) when means are positive.

    • “difference” uses \(\text{mean}(\text{treated}) - \text{mean}(\text{control})\) and is generally safe across scales (probabilities, z-scores, raw expression).

    Default is “ratio”.

  • gene_index (Optional[pd.Index]):

    The index of the genes in the predictions AnnData.

  • cell_index (Optional[pd.Index]):

    The index of the cells in the predictions AnnData.

Parameters:

random_seed (int) – Random seed for reproducibility.

Returns:

dictionary of mean predicted and ground truth changes in gene expression values for each condition.

Return type:

PerturbationExpressionPredictionTask

display_name = 'Perturbation Expression Prediction'
description = 'Evaluate the quality of predicted changes in expression levels for genes that are...
input_model
condition_key = None
abstract compute_baseline(**kwargs)[source]

Set a baseline embedding for perturbation expression prediction.

This method is not implemented for perturbation expression prediction tasks.

Raises:

NotImplementedError – Always raised as baseline is not implemented