Package 'conformeR'

Title: Conformalized differential expression analysis of multi-condition single-cell data
Description: conformeR provides conformal prediction layers for the cell neighborhood construction step of the LEMUR framework. It implements two complementary approaches, conformal clustering and conformal selection, to quantify uncertainty in the resulting cell neighborhoods, together with tools for visualizing and interpreting the resulting uncertainty sets.
Authors: Justine Leclerc [cre, aut] (ORCID: <https://orcid.org/0009-0002-5667-0778>), Christof Seiler [aut] (ORCID: <https://orcid.org/0000-0001-8802-3642>), Digital Society Initiative - University of Zurich [fnd] (RAI - Reliable AI for Biomedicine)
Maintainer: Justine Leclerc <[email protected]>
License: MIT + file LICENSE
Version: 0.99.4
Built: 2026-12-02 04:49:04 UTC
Source: https://github.com/bioc/conformeR

Help Index


LEMUR analysis for neighborhoods on predicted gene differential expression with conformal methods

Description

Runs a LEMUR analysis, identifies differential-expression neighborhoods, and applies conformal procedures to a set of genes of interest. The data are split into training, calibration, and test sets based on the covariates specified in the LEMUR design formula. The results are added to the input SingleCellExperiment, which is returned with its original data and annotations preserved.

Usage

conformeR(
  sce,
  design_lemur = ~1,
  contrast_column,
  contrast_levels = NULL,
  n_embedding = 60,
  use_assay = "logcounts",
  test_fraction_lemur = 0.2,
  cp_train_frac = 0.5,
  cp_cal_frac = 0.25,
  cp_alpha = 0.05,
  genes_of_interest,
  what = c("conf_selection", "conf_clustering"),
  BPPARAM = BiocParallel::SerialParam(),
  verbose = TRUE
)

Arguments

sce

A SingleCellExperiment object containing the single-cell expression data. It must have unique, non-missing row and column names.

design_lemur

A formula specifying the design used by LEMUR. All variables must be columns of colData(sce) and contrast_column must be one of them.

contrast_column

A column name of colData(sce) specifying the comparison used for differential-expression testing in LEMUR.

contrast_levels

NULL or a character vector of length two, c(level_of_interest, reference_level). Required when contrast_column has more than two levels.

n_embedding

Number of dimensions in the LEMUR embedding.

use_assay

Character string specifying the assay to use.

test_fraction_lemur

Fraction of cells used as the LEMUR test set.

cp_train_frac

Fraction of cells used for conformal training (the remaining cells form the conformal test set).

cp_cal_frac

Fraction of the training cells set aside for conformal calibration.

cp_alpha

Error level of the conformal procedures, in (0, 1): target false discovery rate for conformal selection and miscoverage level for conformal clustering (target coverage 1−α1 - \alpha). See the section Interpretation of cp_alpha.

genes_of_interest

Character vector containing the names of genes to include in the conformal analysis. They need to correspond to the row names of sce.

what

Character vector specifying the conformal procedure(s) to run: "conf_selection", "conf_clustering", or both.

BPPARAM

A BiocParallelParam object specifying the parallel back-end used to process the gene chunks. Defaults to SerialParam(). Use, e.g., MulticoreParam() on Linux/macOS or SnowParam() on Windows.

verbose

Logical indicating whether to display progress information.

Details

The conformal procedures are applied to a subset of genes of interest. Genes are processed in chunks of five, which are distributed over the workers of BPPARAM.

Value

The input SingleCellExperiment with its original assays, rowData, colData and reduced dimensions retained, enriched with:

colData(sce)$conformeR_split

Factor with levels "train", "cal" and "test" giving the set each cell was assigned to. Conformal results are only defined for test cells.

reducedDim(sce, "LEMUR")

The aligned LEMUR embedding (cells x n_embedding).

reducedDim(sce, "LEMUR_UMAP"), reducedDim(sce, "LEMUR_aligned_UMAP")

UMAPs of the LEMUR embedding before and after Harmony alignment.

altExp(sce, "conformeR")

A SingleCellExperiment with one row per gene of interest and the same columns as sce. Its assays are:

DE

Numeric, the LEMUR predicted differential expression for every cell.

lemur_neighborhood

Logical, TRUE if the test cell belongs to the LEMUR differential-expression neighborhood of the gene.

conf_selection

Logical, TRUE if the test cell is selected by conformal selection, i.e. confidently belongs to the neighborhood at FDR level cp_alpha (only if "conf_selection" is in what).

conf_clustering_inside, conf_clustering_outside

Logical, TRUE if the label "inside the neighborhood" (respectively "outside") belongs to the conformal prediction set of the test cell (only if "conf_clustering" is in what).

conf_set_size

Integer in {0, 1, 2}, the size of the conformal clustering prediction set. Size 1 means an unambiguous assignment; sizes 0 and 2 mean the assignment is ambiguous at level cp_alpha.

All logical and set-size assays are NA for training and calibration cells. The rowData contains the LEMUR neighborhood statistics of the test set (prefixed with lemur_), the number of cells in the LEMUR neighborhood (n_lemur_neighborhood), the number of conformally selected cells (n_conf_selection), the score quantile of conformal clustering (conf_quantile) and cp_alpha.

metadata(sce)$conformeR

A list with the analysis parameters, the contrast and the number of cells in each split.

Because all results are stored in the object, they stay synchronized when the object is subset.

Interpretation of cp_alpha

cp_alpha is an error level, not a coverage level: the target coverage is 1−α1 - \alpha.

Conformal selection

cp_alpha is the target false discovery rate (FDR). Conformal p-values are computed for every test cell and the Benjamini-Hochberg procedure is applied at level cp_alpha. The expected proportion of selected cells that do not truly belong to the LEMUR neighborhood is at most cp_alpha. With cp_alpha = 0.05, at most 5 percent of the selected cells are expected to be false inclusions.

Conformal clustering

cp_alpha is the miscoverage level of the prediction sets. For a new cell, the prediction set (inside and/or outside the neighborhood) contains the true neighborhood label with probability at least 1−α1 - \alpha (marginal coverage). With cp_alpha = 0.05, the prediction sets have 95 percent coverage.

Smaller values of cp_alpha give more conservative results: fewer selected cells and larger (more often ambiguous) prediction sets.

See Also

plotter_conformal_selection, plotter_conformal_clustering, lemur

Examples

data("sce_reduced")
sce_conformer <- conformeR(sce_reduced,
    design_lemur = ~ patient_id + condition,
    contrast_column = "condition",
    n_embedding = 15,
    genes_of_interest = c(
        "ENSG00000163453",
        "ENSG00000163734"
    )
)
sce_conformer
## conformal results
SingleCellExperiment::altExp(sce_conformer, "conformeR")
SummarizedExperiment::rowData(
    SingleCellExperiment::altExp(sce_conformer, "conformeR")
)
## number of conformally selected test cells per gene
rowSums(SummarizedExperiment::assay(
    SingleCellExperiment::altExp(sce_conformer, "conformeR"),
    "conf_selection"
), na.rm = TRUE)

Plot conformal clustering results on the LEMUR embedding

Description

Visualizes gene-level differential expression and conformal clustering results on the aligned LEMUR UMAP embedding. Each gene gets two panels, stacked in an "Inside" and an "Outside" row. In each row, the cells of the LEMUR neighborhood (respectively outside it) are colored by their predicted differential expression. The conformal prediction sets are overlaid in two groups:

Confident cells (black)

Prediction set of size 1 matching the row, i.e. confidently inside (or outside) the neighborhood.

Ambiguous cells (grey)

Prediction set of size 0 or 2: the assignment is uncertain at level cp_alpha. They are the same in both rows.

A group is drawn as density contours when it has at least min_cells_contour cells, and as circled cells otherwise. Contours are scaled by the number of cells, so their size and number of levels can be compared between the two groups of a panel. The number of cells in each group is given in each panel title.

Usage

plotter_conformal_clustering(
    conformer_output,
    genes_to_plot,
    min_cells_contour = 30
)

Arguments

conformer_output

A SingleCellExperiment returned by conformeR with "conf_clustering" in what. Only the test cells (conformeR_split == "test") are plotted.

genes_to_plot

Character vector specifying the genes to plot. They must be among the genes_of_interest passed to conformeR().

min_cells_contour

Minimum number of cells in a group (confident or ambiguous) before it is drawn as density contours rather than individual cells (default 30). Use Inf to never draw contours.

Value

A single combined ggplot/cowplot object: the "Inside" panel row stacked above the "Outside" panel row, each row labeled accordingly, with one shared "Prediction set" legend (black = confident, set size 1; grey = ambiguous, set size 0 or 2) below the combined grid.

Examples

data("sce_reduced")
sce_conformer <- conformeR(sce_reduced,
    design_lemur = ~ patient_id + condition,
    contrast_column = "condition",
    n_embedding = 15,
    genes_of_interest = c(
        "ENSG00000163453",
        "ENSG00000163734"
    )
)
plotter_conformal_clustering(sce_conformer,
    genes_to_plot = c(
        "ENSG00000163453",
        "ENSG00000163734"
    )
)

Plot conformal selection results on the LEMUR embedding

Description

Visualizes gene-level differential expression and conformal selection results on the aligned LEMUR UMAP embedding. For each gene, the cells of the LEMUR neighborhood are colored by their predicted differential expression. When a gene has at least min_cells_contour selected cells, green density contours show where the selected cells concentrate. The number of selected cells is given in each panel title.

Usage

plotter_conformal_selection(
    conformer_output,
    genes_to_plot,
    min_cells_contour = 30
)

Arguments

conformer_output

A SingleCellExperiment returned by conformeR with "conf_selection" in what. Only the test cells (conformeR_split == "test") are plotted.

genes_to_plot

Character vector specifying the genes to plot. They must be among the genes_of_interest passed to conformeR().

min_cells_contour

Minimum number of selected cells for a gene before density contours are drawn (default 30). Use Inf to never draw contours.

Details

Density contours are normalized to their maximum, so they look the same whether they summarise six cells or six hundred. They are therefore only drawn for genes with enough selected cells; for the other genes only the number of selected cells is reported.

Value

A single combined ggplot/cowplot object showing differential expression and conformal selection results for all requested genes on the aligned LEMUR UMAP embedding. When contours are drawn, a shared legend is added below the grid of gene panels.

Examples

data("sce_reduced")
sce_conformer <- conformeR(sce_reduced,
    design_lemur = ~ patient_id + condition,
    contrast_column = "condition",
    n_embedding = 15,
    genes_of_interest = c(
        "ENSG00000163453",
        "ENSG00000163734"
    )
)
plotter_conformal_selection(sce_conformer,
    genes_to_plot = c(
        "ENSG00000163453",
        "ENSG00000163734"
    )
)

Example single-cell dataset

Description

A small SingleCellExperiment object used to demonstrate the conformeR workflow. Random subset from a real dataset (see source). Code for reproducing from original dataset at: https://github.com/juslecl/conformeR-paper/tree/main/data_preparation 3k cells and 100 genes for 2 patients, 2 conditions, 3 cell-types.

Usage

data("sce_reduced")

Format

A SingleCellExperiment object.

Details

This object is a subset of the dataset from Zhao et al. (2021), processed for use as an example dataset in conformeR.

Source

Zhao, W., Dovas, A., Spinazzi, E., et al. (2021). Deconvolution of cell type-specific drug responses in human tumor tissue with single-cell RNA-seq. Genome Medicine, 13, 82. GEO accession: GSE148842.