
Plot conformal clustering results on the LEMUR embedding
Source:R/plotter.R
plotter_conformal_clustering.RdVisualizes 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.
Arguments
- conformer_output
A
SingleCellExperimentreturned byconformeRwith"conf_clustering"inwhat. 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_interestpassed toconformeR().- 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
Infto 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"
)
)
#> Select cells that are considered close with 'harmony'
#> Storing 20% of the data (600 cells) as test data.
#> Regress out global effects using linear method.
#> Find base point for differential embedding
#> Fit differential embedding model
#> Initial error: 4.55e+05
#> ---Fit Grassmann linear model
#> Final error: 1.38e+05
#> Find optimal neighborhood using zscore.
#> Validate neighborhoods using test data
#> Form pseudobulk (summing counts)
#> Calculate size factors for each gene
#> Fit edgeR model on pseudobulk data
#> Fit diff-in-diff effect
#> Find optimal neighborhood using zscore.
#> Validate neighborhoods using test data
#> Form pseudobulk (summing counts)
#> Calculate size factors for each gene
#> Fit edgeR model on pseudobulk data
#> Fit diff-in-diff effect
#> Find optimal neighborhood using zscore.
#> Validate neighborhoods using test data
#> Form pseudobulk (summing counts)
#> Calculate size factors for each gene
#> Fit edgeR model on pseudobulk data
#> Fit diff-in-diff effect
#> Running conformal procedures on 2 gene(s).
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
plotter_conformal_clustering(sce_conformer,
genes_to_plot = c(
"ENSG00000163453",
"ENSG00000163734"
)
)
#> Warning: `stat_contour()`: Zero contours were generated
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: `stat_contour()`: Zero contours were generated
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: `stat_contour()`: Zero contours were generated
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: `stat_contour()`: Zero contours were generated
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf