
Integration with dreamlet / SingleCellExperiment
Developed by Gabriel Hoffman
Run on 2025-02-17 21:03:03.848949
Source:vignettes/integration.Rmd
integration.Rmd
Load and process single cell data
Here we perform analysis of PBMCs from 8 individuals stimulated with
interferon-β Kang, et
al, 2018, Nature Biotech. We perform standard processing with dreamlet
to compute pseudobulk before applying crumblr
.
Here, single cell RNA-seq data is downloaded from ExperimentHub.
library(dreamlet)
library(muscat)
library(ExperimentHub)
library(scater)
# Download data, specifying EH2259 for the Kang, et al study
eh <- ExperimentHub()
sce <- eh[["EH2259"]]
sce$ind <- as.character(sce$ind)
# only keep singlet cells with sufficient reads
sce <- sce[rowSums(counts(sce) > 0) > 0, ]
sce <- sce[, colData(sce)$multiplets == "singlet"]
# compute QC metrics
qc <- perCellQCMetrics(sce)
# remove cells with few or many detected genes
ol <- isOutlier(metric = qc$detected, nmads = 2, log = TRUE)
sce <- sce[, !ol]
# set variable indicating stimulated (stim) or control (ctrl)
sce$StimStatus <- sce$stim
Aggregate to pseudobulk
Dreamlet creates the pseudobulk dataset:
# Since 'ind' is the individual and 'StimStatus' is the stimulus status,
# create unique identifier for each sample
sce$id <- paste0(sce$StimStatus, sce$ind)
# Create pseudobulk data by specifying cluster_id and sample_id for aggregating cells
pb <- aggregateToPseudoBulk(sce,
assay = "counts",
cluster_id = "cell",
sample_id = "id",
verbose = FALSE
)
Process data
Here we evaluate whether the observed cell proportions change in response to interferon-β.
library(crumblr)
# use dreamlet::cellCounts() to extract data
cellCounts(pb)[1:3, 1:3]
## B cells CD14+ Monocytes CD4 T cells
## ctrl101 101 136 288
## ctrl1015 424 644 819
## ctrl1016 119 315 413
# Apply crumblr transformation
# cobj is an EList object compatable with limma workflow
# cobj$E stores transformed values
# cobj$weights stores precision weights
cobj <- crumblr(cellCounts(pb))
Analysis
Now continue on with the downstream analysis
library(variancePartition)
fit <- dream(cobj, ~ StimStatus + ind, colData(pb))
fit <- eBayes(fit)
topTable(fit, coef = "StimStatusstim", number = Inf)
## logFC AveExpr t P.Value adj.P.Val B
## CD8 T cells -0.25085170 0.0857175 -4.0787416 0.002436375 0.01949100 -1.279815
## Dendritic cells 0.37386979 -2.1849234 3.1619195 0.010692544 0.02738587 -2.638507
## CD14+ Monocytes -0.10525402 1.2698117 -3.1226341 0.011413912 0.02738587 -2.709377
## B cells -0.10478652 0.5516882 -3.0134349 0.013692935 0.02738587 -2.940542
## CD4 T cells -0.07840101 2.0201947 -2.2318104 0.050869691 0.08139151 -4.128069
## FCGR3A+ Monocytes 0.07425165 -0.2567492 1.6647681 0.128337022 0.17111603 -4.935304
## NK cells 0.10270672 0.3797777 1.5181860 0.161321761 0.18436773 -5.247806
## Megakaryocytes 0.01377768 -1.8655172 0.1555131 0.879651456 0.87965146 -6.198336
Given the results here, we see that CD8 T cells at others change relative abundance following treatment with interferon-β.
Session Info
## R version 4.4.1 (2024-06-14)
## Platform: aarch64-apple-darwin23.5.0
## Running under: macOS Sonoma 14.7.1
##
## Matrix products: default
## BLAS: /Users/gabrielhoffman/prog/R-4.4.1/lib/libRblas.dylib
## LAPACK: /opt/homebrew/Cellar/r/4.4.2_2/lib/R/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] crumblr_0.99.14 muscData_1.20.0 scater_1.34.0
## [4] scuttle_1.16.0 zenith_1.8.0 ExperimentHub_2.14.0
## [7] AnnotationHub_3.14.0 BiocFileCache_2.14.0 dbplyr_2.5.0
## [10] muscat_1.20.0 dreamlet_1.4.1 SingleCellExperiment_1.28.1
## [13] SummarizedExperiment_1.36.0 Biobase_2.66.0 GenomicRanges_1.58.0
## [16] GenomeInfoDb_1.42.1 IRanges_2.40.1 S4Vectors_0.44.0
## [19] BiocGenerics_0.52.0 MatrixGenerics_1.18.0 matrixStats_1.4.1
## [22] variancePartition_1.36.3 BiocParallel_1.40.0 limma_3.62.1
## [25] ggplot2_3.5.1
##
## loaded via a namespace (and not attached):
## [1] fs_1.6.5 bitops_1.0-9 httr_1.4.7
## [4] RColorBrewer_1.1-3 doParallel_1.0.17 Rgraphviz_2.50.0
## [7] numDeriv_2016.8-1.1 tools_4.4.1 sctransform_0.4.1
## [10] backports_1.5.0 utf8_1.2.4 R6_2.5.1
## [13] metafor_4.6-0 lazyeval_0.2.2 mgcv_1.9-1
## [16] GetoptLong_1.0.5 withr_3.0.2 prettyunits_1.2.0
## [19] gridExtra_2.3 cli_3.6.3 textshaping_0.4.1
## [22] sass_0.4.9 KEGGgraph_1.66.0 SQUAREM_2021.1
## [25] mvtnorm_1.3-2 blme_1.0-6 pkgdown_2.1.1
## [28] mixsqp_0.3-54 yulab.utils_0.1.8 systemfonts_1.1.0
## [31] parallelly_1.40.1 invgamma_1.1 RSQLite_2.3.9
## [34] gridGraphics_0.5-1 generics_0.1.3 shape_1.4.6.1
## [37] gtools_3.9.5 dplyr_1.1.4 Matrix_1.7-1
## [40] metadat_1.2-0 ggbeeswarm_0.7.2 fansi_1.0.6
## [43] abind_1.4-8 lifecycle_1.0.4 yaml_2.3.10
## [46] edgeR_4.4.1 mathjaxr_1.6-0 gplots_3.2.0
## [49] SparseArray_1.6.0 grid_4.4.1 blob_1.2.4
## [52] crayon_1.5.3 lattice_0.22-6 beachmat_2.22.0
## [55] msigdbr_7.5.1 annotate_1.84.0 KEGGREST_1.46.0
## [58] pillar_1.9.0 knitr_1.49 ComplexHeatmap_2.22.0
## [61] rjson_0.2.23 boot_1.3-31 corpcor_1.6.10
## [64] future.apply_1.11.3 codetools_0.2-20 glue_1.8.0
## [67] ggfun_0.1.8 data.table_1.16.4 treeio_1.26.0
## [70] vctrs_0.6.5 png_0.1-8 Rdpack_2.6.2
## [73] gtable_0.3.6 assertthat_0.2.1 cachem_1.1.0
## [76] xfun_0.49 mime_0.12 rbibutils_2.3
## [79] S4Arrays_1.6.0 Rfast_2.1.0 reformulas_0.4.0
## [82] iterators_1.0.14 statmod_1.5.0 nlme_3.1-166
## [85] pbkrtest_0.5.3 ggtree_3.10.1 bit64_4.5.2
## [88] filelock_1.0.3 progress_1.2.3 EnvStats_3.0.0
## [91] bslib_0.8.0 TMB_1.9.15 irlba_2.3.5.1
## [94] vipor_0.4.7 KernSmooth_2.23-24 colorspace_2.1-1
## [97] rmeta_3.0 DBI_1.2.3 DESeq2_1.46.0
## [100] tidyselect_1.2.1 curl_6.0.1 bit_4.5.0.1
## [103] compiler_4.4.1 graph_1.84.0 BiocNeighbors_2.0.1
## [106] desc_1.4.3 DelayedArray_0.32.0 scales_1.3.0
## [109] caTools_1.18.3 remaCor_0.0.18 rappdirs_0.3.3
## [112] stringr_1.5.1 digest_0.6.37 minqa_1.2.8
## [115] rmarkdown_2.29 aod_1.3.3 XVector_0.46.0
## [118] RhpcBLASctl_0.23-42 htmltools_0.5.8.1 pkgconfig_2.0.3
## [121] lme4_1.1-35.5 sparseMatrixStats_1.18.0 mashr_0.2.79
## [124] fastmap_1.2.0 rlang_1.1.4 GlobalOptions_0.1.2
## [127] htmlwidgets_1.6.4 UCSC.utils_1.2.0 DelayedMatrixStats_1.28.0
## [130] farver_2.1.2 jquerylib_0.1.4 jsonlite_1.8.9
## [133] BiocSingular_1.22.0 RCurl_1.98-1.16 magrittr_2.0.3
## [136] ggplotify_0.1.2 GenomeInfoDbData_1.2.13 patchwork_1.3.0
## [139] munsell_0.5.1 Rcpp_1.0.13-1 ape_5.8-1
## [142] babelgene_22.9 viridis_0.6.5 EnrichmentBrowser_2.36.0
## [145] RcppZiggurat_0.1.6 stringi_1.8.4 zlibbioc_1.52.0
## [148] MASS_7.3-61 plyr_1.8.9 parallel_4.4.1
## [151] listenv_0.9.1 ggrepel_0.9.6 Biostrings_2.74.0
## [154] splines_4.4.1 hms_1.1.3 circlize_0.4.16
## [157] locfit_1.5-9.10 reshape2_1.4.4 ScaledMatrix_1.14.0
## [160] BiocVersion_3.20.0 XML_3.99-0.17 evaluate_1.0.1
## [163] BiocManager_1.30.25 RcppParallel_5.1.9 nloptr_2.1.1
## [166] foreach_1.5.2 tidyr_1.3.1 purrr_1.0.2
## [169] future_1.34.0 clue_0.3-66 scattermore_1.2
## [172] ashr_2.2-63 rsvd_1.0.5 broom_1.0.7
## [175] xtable_1.8-4 tidytree_0.4.6 fANCOVA_0.6-1
## [178] viridisLite_0.4.2 ragg_1.3.3 truncnorm_1.0-9
## [181] tibble_3.2.1 aplot_0.2.4 lmerTest_3.1-3
## [184] glmmTMB_1.1.10 memoise_2.0.1 beeswarm_0.4.0
## [187] AnnotationDbi_1.68.0 cluster_2.1.8 globals_0.16.3
## [190] GSEABase_1.68.0