Compute PCA of gene expression for an assay, and plot samples coloring by outlier score
Usage
# S4 method for class 'list'
plotPCA(
object,
assays = names(object),
nPC = 2,
robust = FALSE,
...,
maxOutlierZ = 20,
nrow = 2,
size = 2,
fdr.cutoff = 0.05
)
Arguments
- object
dreamletProcessedData
fromprocessAssays()
or alist
fromresiduals()
- assays
assays / cell types to analyze
- nPC
number of PCs to uses for outlier score with
outlier()
- robust
use robust covariance method, defaults to
FALSE
- ...
arguments passed to
MASS::cov.rob()
- maxOutlierZ
cap outlier z-scores at this value for plotting to maintain consistent color scale
- nrow
number of rows in plot
- size
size passed to
geom_point()
- fdr.cutoff
FDR cutoff to determine outlier
Examples
library(muscat)
library(SingleCellExperiment)
data(example_sce)
# create pseudobulk for each sample and cell cluster
pb <- aggregateToPseudoBulk(example_sce,
assay = "counts",
cluster_id = "cluster_id",
sample_id = "sample_id",
verbose = FALSE
)
# voom-style normalization
res.proc <- processAssays(pb, ~group_id)
#> B cells...
#> 0.2 secs
#> CD14+ Monocytes...
#> 0.31 secs
#> CD4 T cells...
#> 0.24 secs
#> CD8 T cells...
#> 0.13 secs
#> FCGR3A+ Monocytes...
#> 0.27 secs
# PCA to identify outliers
# from normalized expression
plotPCA( res.proc, c("B cells", "CD14+ Monocytes"))
# Run on regression residuals
#-----------------------------
# Regression analysis
fit = dreamlet(res.proc, ~ group_id)
#> B cells...
#> 0.2 secs
#> CD14+ Monocytes...
#> 0.27 secs
#> CD4 T cells...
#> 0.21 secs
#> CD8 T cells...
#> 0.13 secs
#> FCGR3A+ Monocytes...
#> 0.25 secs
# Extract regression residuals
residsObj = residuals(fit)
# PCA on residuals
plotPCA( residsObj, c("B cells", "CD14+ Monocytes"))