Getting Started with conformeR

Introduction

Overview

LEMUR fits a low-dimensional embedding and assigns cells to neighborhoods based on similar responses to a given contrast and gene. Because these neighborhood assignments are themselves derived from a fitted model, they are subject to sampling variability: refitting the model on a different sample of cells can shift the neighborhood boundaries.

conformeR quantifies this uncertainty by wrapping the neighborhood construction step in a conformal prediction framework. It is designed to integrate naturally into existing Bioconductor workflows for single-cell data analysis, operating downstream of SingleCellExperiment-based preprocessing and LEMUR analyses to provide uncertainty-aware inference for neighborhood assignments.

It provides two complementary views of that uncertainty:

  • Conformal selection asks, for a given gene, which cells can we confidently say belong to the affected neighborhood? It returns a subset of neighborhood cells with a guaranteed bound on the proportion of false inclusions.
  • Conformal clustering asks, for each cell, how uncertain are we about its neighborhood assignment? It returns a prediction set of plausible neighborhoods per cell, which can contain zero, one, or several labels.

Why this matters. A single LEMUR fit gives you one particular neighborhood assignment, with no way to tell how much of it would survive resampling. conformeR turns that single assignment into a statement with a formal, finite-sample coverage guarantee.

Installation

conformeR is distributed through Bioconductor. Install it with BiocManager:

if (!requireNamespace("BiocManager", quietly = TRUE)) {
    install.packages("BiocManager")
}
BiocManager::install("conformeR")
library(conformeR)
library(SingleCellExperiment)
library(BiocParallel)
library(dplyr)
library(ggplot2)
library(tibble)
library(knitr)

theme_set(
    theme_minimal(base_size = 13) +
        theme(
            panel.grid.minor = element_blank(),
            plot.title = element_text(face = "bold"),
            legend.position = "bottom"
        )
)
conformer_palette <- c(
    "inside" = "#4472A8",
    "outside" = "#D9822B",
    "none" = "#B0B0B0"
)

Use-case of conformeR

Example dataset

This vignette runs conformeR on a reduced version of the single-cell RNA-seq dataset from Zhao, Dovas, Spinazzi, et al. (2021), “Deconvolution of cell type-specific drug responses in human tumor tissue with single-cell RNA-seq,” published in Genome Medicine (GEO accession GSE148842). As with any input to conformeR, the data have already been preprocessed and quality-checked upstream.

data("sce_reduced")
sce_reduced
#> class: SingleCellExperiment 
#> dim: 100 3000 
#> metadata(0):
#> assays(2): counts logcounts
#> rownames(100): ENSG00000118785 ENSG00000210082 ... ENSG00000113070
#>   ENSG00000181218
#> rowData names(2): gid gene
#> colnames(3000): cell 6769 cell 6786 ... cell 27922 cell 11673
#> colData names(3): cell_type condition patient_id
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
rownames(sce_reduced) <- rowData(sce_reduced)$gene
head(colData(sce_reduced))
#> DataFrame with 6 rows and 3 columns
#>                   cell_type    condition  patient_id
#>                 <character>  <character> <character>
#> cell 6769  Oligodendrocytes         ctrl       PW030
#> cell 6786     Myeloid cells         ctrl       PW030
#> cell 27448    Myeloid cells panobinostat       PW030
#> cell 76998    Myeloid cells         ctrl       PW034
#> cell 92754    Myeloid cells panobinostat       PW034
#> cell 22521    Myeloid cells         ctrl       PW030

We restrict the analysis to three genes with distinct expected behavior, to illustrate a range of neighborhood sizes and uncertainty patterns: HIST3H2A, PTPRZ1, and HBEGF.

pan_affect_genes <- rowData(sce_reduced) |>
    as_tibble() |>
    dplyr::select(gid, gene) |>
    filter(gene %in% c("HIST3H2A", "PTPRZ1", "HBEGF"))

kable(pan_affect_genes, caption = "Genes of interest for this vignette")
Genes of interest for this vignette
gid gene
ENSG00000106278 PTPRZ1
ENSG00000113070 HBEGF
ENSG00000181218 HIST3H2A

Running conformeR

conformeR() fits LEMUR and layers both conformal procedures on top of it in one call. The key arguments are:

  • design_lemur — the LEMUR design formula; here we adjust for patient_id and estimate the effect of condition.
  • contrast_column — which column of the design defines the contrast of interest.
  • genes_of_interest — restrict the (more expensive) conformal layers to a gene subset; LEMUR itself is still fit genome-wide.
  • what — which conformal procedure(s) to run: "conf_selection", "conf_clustering", or both.

By default the data are split 50% training / 50% test, with the calibration set taking 25% of the training set (cp_train_frac and cp_cal_frac set these proportions). The split is stratified on the variables of design_lemur.

Gene chunks are processed in parallel with the BiocParallel back-end given in BPPARAM (serial by default). Use, for instance, MulticoreParam(workers = 4) on Linux and macOS or SnowParam(workers = 4) on Windows.

Interpretation of cp_alpha

cp_alpha is an error level; the corresponding confidence (or coverage) level is 1 - cp_alpha. With the default cp_alpha = 0.05:

  • Conformal selection: cp_alpha is the target false discovery rate. Among the cells selected as belonging to a gene’s neighborhood, the expected proportion of cells that are actually outside the neighborhood is at most 5%.
  • Conformal clustering: cp_alpha is the miscoverage level of the prediction sets. For a new cell, the prediction set contains the cell’s true neighborhood label with probability at least 95%.

Lowering cp_alpha makes both procedures more conservative: fewer cells are selected and more prediction sets are ambiguous.

set.seed(2002)
sce_res <- conformeR(
    sce_reduced,
    design_lemur = ~ patient_id + condition,
    contrast_column = "condition",
    genes_of_interest = pan_affect_genes$gene,
    what = c("conf_selection", "conf_clustering"),
    cp_alpha = 0.05,
    BPPARAM = SerialParam(),
    verbose = TRUE
)

Structure of the output

conformeR() returns the input SingleCellExperiment, with all its original assays and annotations, enriched with the results.

sce_res
#> class: SingleCellExperiment 
#> dim: 100 3000 
#> metadata(1): conformeR
#> assays(2): counts logcounts
#> rownames(100): SPP1 MT-RNR2 ... HBEGF HIST3H2A
#> rowData names(2): gid gene
#> colnames(3000): cell 6769 cell 6786 ... cell 27922 cell 11673
#> colData names(4): cell_type condition patient_id conformeR_split
#> reducedDimNames(3): LEMUR LEMUR_UMAP LEMUR_aligned_UMAP
#> mainExpName: NULL
#> altExpNames(1): conformeR
  • colData(sce_res)$conformeR_split records whether each cell was used for conformal training ("train"), calibration ("cal") or testing ("test"). Conformal results are reported for the test cells only.
  • reducedDim(sce_res, "LEMUR") holds the aligned LEMUR embedding, and "LEMUR_UMAP" / "LEMUR_aligned_UMAP" its UMAPs before and after Harmony alignment.
  • altExp(sce_res, "conformeR") has one row per gene of interest and one column per cell. Its assays contain the LEMUR predicted differential expression (DE), the LEMUR neighborhood membership (lemur_neighborhood), the conformal selection (conf_selection), and the conformal clustering prediction sets (conf_clustering_inside, conf_clustering_outside, conf_set_size). Non-test cells are NA.
  • metadata(sce_res)$conformeR stores the analysis parameters.
conf <- altExp(sce_res, "conformeR")
conf
#> class: SingleCellExperiment 
#> dim: 3 3000 
#> metadata(0):
#> assays(6): DE lemur_neighborhood ... conf_clustering_outside
#>   conf_set_size
#> rownames(3): PTPRZ1 HBEGF HIST3H2A
#> rowData names(15): lemur_n_cells lemur_sel_statistic ... conf_quantile
#>   cp_alpha
#> colnames(3000): cell 6769 cell 6786 ... cell 27922 cell 11673
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
table(sce_res$conformeR_split)
#> 
#> train   cal  test 
#>  1123   376  1501

The rowData of the alternative experiment gathers per-gene results: the LEMUR neighborhood statistics (prefixed with lemur_), the number of test cells in the LEMUR neighborhood, the number of conformally selected cells, and the conformal clustering score quantile.

rowData(conf)
#> DataFrame with 3 rows and 15 columns
#>          lemur_n_cells lemur_sel_statistic lemur_pval lemur_adj_pval
#>              <integer>           <numeric>  <numeric>      <numeric>
#> PTPRZ1             840              21.440  0.1115789       0.495948
#> HBEGF              778              10.726  0.1718821       0.566741
#> HIST3H2A           934             -26.690  0.0783046       0.495948
#>          lemur_f_statistic lemur_df1 lemur_df2 lemur_lfc lemur_did_pval
#>                  <numeric> <integer> <numeric> <numeric>      <numeric>
#> PTPRZ1             2.57702         1       100   1.79608       0.931927
#> HBEGF              1.89350         1       100  -1.77716       0.564617
#> HIST3H2A           3.16427         1       100  -3.18413       0.369776
#>          lemur_did_adj_pval lemur_did_lfc n_lemur_neighborhood n_conf_selection
#>                   <numeric>     <numeric>            <numeric>        <numeric>
#> PTPRZ1             0.999992     -0.145732                  840                0
#> HBEGF              0.984416      1.017745                  778                0
#> HIST3H2A           0.970914     -2.184362                  934              474
#>          conf_quantile  cp_alpha
#>              <numeric> <numeric>
#> PTPRZ1        0.422027      0.05
#> HBEGF         0.402994      0.05
#> HIST3H2A      0.432338      0.05

Conformal selection

For each gene, conformal selection returns the set of cells flagged as belonging to the neighborhood affected by condition, with the false discovery rate controlled at cp_alpha. The table below reports both the raw neighborhood size and its share of all cells in the test set.

test_cells <- sce_res$conformeR_split == "test"
selected <- assay(conf, "conf_selection")[, test_cells]

selection_summary <- tibble(
    gene = rownames(conf),
    `Neighborhood size` = rowSums(selected),
    `% of cells` = round(rowMeans(selected) * 100)
)

kable(selection_summary,
    caption =
        "Conformal selection: neighborhood size per gene (test cells)"
)
Conformal selection: neighborhood size per gene (test cells)
gene Neighborhood size % of cells
PTPRZ1 0 0
HBEGF 0 0
HIST3H2A 474 32

Conformal clustering

Conformal clustering instead reports, per cell, a prediction set: the neighborhoods that cell could plausibly belong to, with coverage 1 - cp_alpha. A prediction set of size zero or two means the procedure could not confidently assign that cell to any neighborhood. It is ambiguous.

inside <- assay(conf, "conf_clustering_inside")[, test_cells]
outside <- assay(conf, "conf_clustering_outside")[, test_cells]
set_size <- assay(conf, "conf_set_size")[, test_cells]

clustering_summary <- tibble(
    gene = rownames(conf),
    `Prediction set = inside` = rowSums(set_size == 1 & inside),
    `Prediction set = outside` = rowSums(set_size == 1 & outside),
    `Prediction set size 2 or empty` = rowSums(set_size != 1)
)

kable(clustering_summary,
    caption =
        "Conformal clustering: prediction set composition per gene"
)
Conformal clustering: prediction set composition per gene
gene Prediction set = inside Prediction set = outside Prediction set size 2 or empty
PTPRZ1 450 999 52
HBEGF 197 1260 44
HIST3H2A 975 488 38

Visualizing results on the LEMUR embedding

Conformal selection

plotter_conformal_selection(sce_res, pan_affect_genes$gene)
Conformal selection overlaid on LEMUR

Conformal selection overlaid on LEMUR

Cells shaded as part of the selected neighborhood are those the procedure can confidently attribute to the condition effect for that gene; unshaded cells fall outside the selection at the chosen false discovery rate.

Conformal clustering

plotter_conformal_clustering(sce_res, pan_affect_genes$gene)
Conformal prediction sets overlaid on LEMUR

Conformal prediction sets overlaid on LEMUR

Here color reflects the prediction set itself rather than a single hard assignment, making it easy to spot the boundary regions where neighborhood membership is genuinely uncertain versus the core regions where every resampling agrees.

Session info

sessionInfo()
#> R version 4.6.2 (2026-10-29)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] knitr_1.52                  tibble_3.3.1               
#>  [3] ggplot2_4.0.4               dplyr_1.2.1                
#>  [5] BiocParallel_1.49.0         SingleCellExperiment_1.37.0
#>  [7] SummarizedExperiment_1.45.0 Biobase_2.75.0             
#>  [9] GenomicRanges_1.67.0        Seqinfo_1.5.0              
#> [11] IRanges_2.49.0              S4Vectors_0.53.0           
#> [13] BiocGenerics_0.61.1         generics_0.1.4             
#> [15] MatrixGenerics_1.27.0       matrixStats_1.5.0          
#> [17] conformeR_0.99.4            BiocStyle_2.43.0           
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.2.1         farver_2.1.2             S7_1.0.0                
#>  [4] fastmap_1.2.0            digest_0.6.39            lifecycle_1.0.5         
#>  [7] statmod_1.5.2            lemur_1.13.0             magrittr_2.0.5          
#> [10] compiler_4.6.2           rlang_1.3.0              sass_0.5.0              
#> [13] tools_4.6.2              yaml_2.3.12              FNN_1.1.4.1             
#> [16] S4Arrays_1.15.0          labeling_0.4.3           DelayedArray_0.41.0     
#> [19] RColorBrewer_1.1-3       abind_1.4-8              withr_3.0.3             
#> [22] purrr_1.2.2              sys_3.4.3                grid_4.6.2              
#> [25] beachmat_2.31.1          future_1.82.0            edgeR_5.1.0             
#> [28] globals_0.20.0           scales_1.4.0             MASS_7.3-66             
#> [31] isoband_0.3.0            cli_3.6.6                rmarkdown_2.32          
#> [34] otel_0.3.0               RSpectra_0.16-2          glmGamPoi_1.27.0        
#> [37] cachem_1.1.0             splines_4.6.2            parallel_4.6.2          
#> [40] BiocManager_1.30.27      XVector_0.55.0           vctrs_0.7.3             
#> [43] Matrix_1.7-6             jsonlite_2.0.0           listenv_1.1.0           
#> [46] maketools_1.3.2          limma_4.1.0              ggnewscale_0.5.2        
#> [49] jquerylib_0.1.4          tidyr_1.3.2              glue_1.8.1              
#> [52] parallelly_1.50.0        codetools_0.2-20         cowplot_1.2.0           
#> [55] uwot_0.2.5               rsample_1.3.2            gtable_0.3.6            
#> [58] furrr_0.4.0              pillar_1.11.1            htmltools_0.5.9         
#> [61] R6_2.6.1                 sparseMatrixStats_1.27.0 evaluate_1.0.5          
#> [64] lattice_0.23-1           bslib_0.12.0             Rcpp_1.1.2              
#> [67] SparseArray_1.15.0       xfun_0.63                buildtools_1.0.0        
#> [70] pkgconfig_2.0.3