HelenaLC / CATALYST

Cytometry dATa anALYsis Tools
67 stars 30 forks source link

plotExprHeatmap using mean values across conditions #316

Closed Tregwiz closed 1 year ago

Tregwiz commented 1 year ago

Hi Helena, Apologies for asking a number of questions recently - this should hopefully be my last for a while! I was just wondering whether it is possible to use plotExprHeatmap to plot a heatmap of the mean expression of the markers across conditions ie instead of showing the marker expression from individual patients within the conditions, just show the mean marker expression value from each of the patients within the condition? Thanks.

HelenaLC commented 1 year ago

Hm. I'm not sure I fully understand the question. These two statements are conflicting:

  1. "instead of showing the marker expression from individual patients"
  2. "just show the mean marker expression value from each of the patients within the condition"

...if you mean averages per patient (with multiple samples each) instead of per sample, then CATALYST does not support / provide a function for this directory, because differential testing will account for inter-sample variability, and I think such a plot would not be informative... If you really want to do this, you'll have to manually compute marker means/medians, get the annotations you're interested in, and visualize with ComplexHeatmap or, alternatively, ggplot2; e.g., something like:

library(CATALYST)
library(ComplexHeatmap)

data(PBMC_fs, PBMC_panel, PBMC_md)
sce <- prepData(PBMC_fs, PBMC_panel, PBMC_md)

idx <- split(seq(ncol(sce)), sce$patient_id)
pbs <- sapply(idx, \(.) {
  es <- assay(sce[, .], "exprs")
  setNames(rowMeans(es), rownames(sce))
})

idx <- match(colnames(pbs), sce$patient_id)
cd <- data.frame(
  patient_id = colnames(pbs),
  condition = sce$condition[idx])

anno <- columnAnnotation(df = cd)
Heatmap(pbs, top_annotation = anno)