Table of Contents
This tutorial provides an illustrative analysis of the hPSC dataset from Chu et al. using MeDuSA.
In this tutorial, we estimate cell-state abundance along the hPSC differentiation trajectory in bulk RNA-seq data using MeDuSA v2.0 and validate the estimates against scRNA-seq ground truth.
Prior to running the analysis, ensure that MeDuSA v2.0 is installed (see Installation).
Input Data #
MeDuSA requires two inputs:
- Bulk RNA-seq expression matrix (genes × samples).
- Reference scRNA-seq
Seuratobject (v3, v4, v5, or v6) withcell_typeandcell_trajectorymetadata columns.
The processed tutorial dataset can be downloaded from hPSC.tar.gz.
1. Bulk RNA-seq Data #
bulk = readRDS("../hPSC_bulk.rds")
2. Reference scRNA-seq Data #
sce = readRDS("./hPSC_sce.rds")
class(sce)
SeuratObject::LayerData(sce, assay = "RNA", layer = "counts")[1:3, 1:3]
sce$cell_trajectory[1:3]
sce$cell_type[1:3]
Example output:
[1] "Seurat"
attr(,"package")
[1] "SeuratObject"
H1_Exp1.001 H1_Exp1.002 H1_Exp1.003
MKL2 0.006680284 0.074591629 0.001734291
CD109 0.004262021 0.001206358 0.096426585
ABTB1 0.000000000 0.012892380 0.000000000
H1_Exp1.001 H1_Exp1.002 H1_Exp1.003
0.8623402 0.7571288 0.6784661
H1_Exp1.001 H1_Exp1.002 H1_Exp1.003
"embry" "embry" "embry"
MeDuSA supports Seurat v3, v4, v5, and v6 (Assay5) (including split layers without requiring JoinLayers()). Reference counts are read from the counts slot/layer (configurable via assay and layer), pseudotime from sce$cell_trajectory, and cell types from sce$cell_type.
Cell-State Deconvolution Analysis #
library(MeDuSA)
help(MeDuSA)
1. Basic Usage of MeDuSA (v2.0) #
bulk: Numeric matrix of bulk RNA-seq data (genes × samples).sce:Seuratobject (v3, v4, v5, or v6) of reference scRNA-seq data.select.ct: Character scalar indicating the focal cell type insce$cell_type.markerGene: Optional character vector of signature genes; ifNULL, MeDuSA callsMeDuSA_marker().resolution: Integer number of cell-state bins along the trajectory (default50).model: Default"gp_map"(REML-calibrated non-negative two-component GP-LMM), which learns trajectory smoothness automatically without manual LOESSspantuning ("gp_blup"and legacy"lmm_gls"remain available).fractional: Logical; normalize abundances to sum to 1 per sample.ncpu: Number of CPU cores.
For all parameters, see About.
# MeDuSA v2.0 default (model = "gp_map", automatic REML smoothness calibration)
MeDuSA_obj = MeDuSA(
bulk, sce,
select.ct = "embry",
resolution = 50,
fractional = TRUE,
ncpu = 4
)
Results are stored in MeDuSA_obj@Estimation:
- Estimated cell-state abundance:
MeDuSA_obj@Estimation$cell_state_abundance - Median pseudotime of cell-state bins:
MeDuSA_obj@Estimation$TimeBin - Marker genes used:
MeDuSA_obj@Estimation$markerGene - Model diagnostics and REML-selected hyperparameters:
MeDuSA_obj@Estimation$ModelInfo
2. Variance Explained & Finite-Sample RLRT P-Values #
MeDuSA_VarExplain() tests the random-effect variance component of the reference trajectory on the selected genes via finite-sample spectral RLRT (test = "rlrt"). Supply independently chosen indep_markers (rather than bulk-filtered automatic markers) for valid null p-value calibration:
res_ve = MeDuSA(bulk, sce, select.ct = "embry", markerGene = indep_markers, resolution = 50)
res_ve = MeDuSA_VarExplain(res_ve, test = "rlrt", n_rlrt_sim = 2000)
res_ve@VarianceExplain
Preparing Reference Data #
Cell-state trajectories can be inferred using tools such as Slingshot, CytoTRACE, Monocle3, or scVelo. Here we use CytoTRACE.
1. Download Raw scRNA-seq Data #
wget https://ftp.ncbi.nlm.nih.gov/geo/series/GSE75nnn/GSE75748/suppl/GSE75748_sc_cell_type_ec.csv.gz
2. Processing Raw scRNA-seq Data #
library(Seurat)
library(CytoTRACE)
library(data.table)
# 1. Load raw count matrix
cnt = as.data.frame(fread("./GSE75748_sc_cell_type_ec.csv.gz"))
rownames(cnt) = cnt[, 1]
cnt = as.matrix(cnt[, -1])
# 2. Infer cell-state trajectory
cyto = CytoTRACE::CytoTRACE(cnt, enableFast = FALSE, ncores = 4)
pseudotime = cyto$CytoTRACE
# 3. Normalize cell size before constructing the Seurat object (works on Seurat v3-v6)
cnt_norm = sweep(cnt, 2, colSums(cnt), "/") * 1e+3
sce = CreateSeuratObject(counts = cnt_norm)
sce$cell_type = "embry"
sce$cell_trajectory = pseudotime[colnames(sce)]
sce$sample = as.character(Idents(sce))
Validation of the MeDuSA Method #
This hPSC dataset provides paired bulk RNA-seq and scRNA-seq across the same differentiation states. Below we compare MeDuSA v2.0 estimates against scRNA-seq ground-truth cell-state proportions:
library(ggplot2)
bulk = readRDS("../hPSC_bulk.rds")
sce = readRDS("./hPSC_sce.rds")
# Ground-truth cell-state abundance from scRNA-seq
pseudotime = sce$cell_trajectory
sampleID = sce$sample
pseudotime = pseudotime[names(sampleID)]
abundance_expect = sapply(unique(sampleID), function(id) {
pt_sub = sort(pseudotime[which(sampleID == id)])
cnt_bin = hist(pt_sub, breaks = seq(0, 1, 1 / 50), plot = FALSE)$counts
cnt_bin / sum(cnt_bin)
})
rownames(abundance_expect) = paste0("bin", seq_len(nrow(abundance_expect)))
# Run MeDuSA v2.0 (default GP-MAP+)
MeDuSA_obj = MeDuSA(
bulk, sce,
select.ct = "embry",
resolution = 50,
fractional = TRUE,
ncpu = 4
)
abundance_estimate = MeDuSA_obj@Estimation$cell_state_abundance
commonId = intersect(colnames(abundance_expect), colnames(abundance_estimate))
obs_v = as.numeric(abundance_expect[, commonId])
est_v = as.numeric(abundance_estimate[, commonId])
ccc_val = 2 * cov(obs_v, est_v) / (var(obs_v) + var(est_v) + (mean(obs_v) - mean(est_v))^2)
r_val = cor(obs_v, est_v)
dat = data.frame(CytoTRACE = obs_v, MeDuSA = est_v)
p1 = ggplot(dat, aes(x = CytoTRACE, y = MeDuSA)) +
geom_point(colour = "#feb24c", size = 2.0, alpha = 0.88) +
geom_smooth(method = "lm", colour = "black", se = FALSE, linewidth = 0.8) +
annotate("text", x = max(dat$CytoTRACE) * 0.04, y = max(dat$MeDuSA) * 0.96,
label = sprintf("CCC = %.2f\nR = %.2f", ccc_val, r_val),
hjust = 0, vjust = 1, size = 4.2) +
labs(x = "CytoTRACE (scRNA-seq)", y = "MeDuSA v2.0") +
theme_bw() +
theme(panel.grid = element_blank(), panel.border = element_blank(),
axis.line = element_line(linewidth = 0.5))
print(p1)
