Skip to contents

Introduction

CITE-seq data provide RNA and surface protein counts for the same cells. This tutorial shows how MuData can be integrated into with Bioconductor workflows to analyse CITE-seq data.

Installation

The most recent dev build can be installed from GitHub:

library(remotes)
remotes::install_github("ilia-kats/MuData")

Stable version of MuData will be available in future bioconductor versions.

Loading libraries

library(MuData)
library(SingleCellExperiment)
library(MultiAssayExperiment)
library(SingleCellMultiModal)
library(scater)

library(rhdf5)

Loading data

We will use CITE-seq data accessible with the SingleCellMultiModal Bioconductor package, which was originally described in Stoeckius et al., 2017.

mae <- CITEseq(
    DataType="cord_blood", modes="*", dry.run=FALSE, version="1.0.0"
)
#> Dataset: cord_blood
#> Working on: scADT_Counts
#> Working on: scRNAseq_Counts
#> Working on: coldata_scRNAseq
#> Working on: scADT_clrCounts
#> see ?SingleCellMultiModal and browseVignettes('SingleCellMultiModal') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> see ?SingleCellMultiModal and browseVignettes('SingleCellMultiModal') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> see ?SingleCellMultiModal and browseVignettes('SingleCellMultiModal') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> see ?SingleCellMultiModal and browseVignettes('SingleCellMultiModal') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> Warning: 'ExperimentList' contains 'data.frame' or 'DataFrame',
#>   potential for errors with mixed data types
#> harmonizing input:
#>   removing 2277 sampleMap rows with 'primary' not in colData

mae
#> A MultiAssayExperiment object of 3 listed
#>  experiments with user-defined names and respective classes.
#>  Containing an ExperimentList class object of length 3:
#>  [1] scADT_clr: matrix with 13 rows and 7858 columns
#>  [2] scADT: matrix with 13 rows and 7858 columns
#>  [3] scRNAseq: matrix with 36280 rows and 7858 columns
#> Functionality:
#>  experiments() - obtain the ExperimentList instance
#>  colData() - the primary/phenotype DataFrame
#>  sampleMap() - the sample coordination DataFrame
#>  `$`, `[`, `[[` - extract colData columns, subset, or experiment
#>  *Format() - convert into a long or wide DataFrame
#>  assays() - convert ExperimentList to a SimpleList of matrices
#>  exportClass() - save data to flat files

We see two modalities in the object — scRNAseq and scADT, the latter providing counts for antibody-derived tags. Notably, each experiment is a matrix.

Processing ADT data

While CITE-seq analysis workflows such as CiteFuse should be consulted for more details, below we exemplify simple data transformation in order to demonstrate how their output can be saved to an H5MU file later on.

For ADT counts, we will apply CLR transformation following Hao et al., 2020:

# Define CLR transformation as in the Seurat workflow
clr <- function(data) t(
  apply(data, 1, function(x) log1p(
    x / (exp(sum(log1p(x[x > 0]), na.rm = TRUE) / length(x)))
  ))
)

We will make the ADT modality a SingleCellExperiment object and add an assay with CLR-transformed counts:

adt_counts <- mae[["scADT"]]

mae[["scADT"]] <- SingleCellExperiment(adt_counts)
assay(mae[["scADT"]], "clr") <- clr(adt_counts)

We will also generate reduced dimensions taking advantage of the functionality in the scater package:

mae[["scADT"]] <- runPCA(
  mae[["scADT"]], exprs_values = "clr", ncomponents = 20
)
#> Warning in check_numbers(k = k, nu = nu, nv = nv, limit = min(dim(x)) - : more
#> singular values/vectors requested than available
#> Warning in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth =
#> TRUE, : You're computing too large a percentage of total singular values, use a
#> standard svd instead.
plotReducedDim(mae[["scADT"]], dimred = "PCA",
               by_exprs_values = "clr", colour_by = "CD3")

plotReducedDim(mae[["scADT"]], dimred = "PCA",
               by_exprs_values = "clr", colour_by = "CD14")

Writing H5MU files

We can write the contents of the MultiAssayExperiment object into an H5MU file:

writeH5MU(mae, "cord_blood_citeseq.h5mu")

We can check that both modalities were written to the file, whether it was a matrix for RNA or SingleCellExperiment for ADT:

h5 <- rhdf5::H5Fopen("cord_blood_citeseq.h5mu")
h5ls(H5Gopen(h5, "mod"), recursive = FALSE)
#>   group      name     otype dclass dim
#> 0     /     scADT H5I_GROUP           
#> 1     / scADT_clr H5I_GROUP           
#> 2     /  scRNAseq H5I_GROUP

… both assays for ADT — raw counts are stored in X and CLR-transformed counts are in the corresponding layer:

h5ls(H5Gopen(h5, "mod/scADT"), recursive = FALSE)
#>   group   name       otype  dclass       dim
#> 0     /      X H5I_DATASET INTEGER 13 x 7858
#> 1     / layers   H5I_GROUP                  
#> 2     /    obs   H5I_GROUP                  
#> 3     /   obsm   H5I_GROUP                  
#> 4     /    var   H5I_GROUP
h5ls(H5Gopen(h5, "mod/scADT/layers"), recursive = FALSE)
#>   group name       otype dclass       dim
#> 0     /  clr H5I_DATASET  FLOAT 13 x 7858

… as well as reduced dimensions (PCA):

h5ls(H5Gopen(h5, "mod/scADT/obsm"), recursive = FALSE)
#>   group name       otype dclass       dim
#> 0     /  PCA H5I_DATASET  FLOAT 12 x 7858
# There is an alternative way to access groups:
# h5&'mod'&'scADT'&'obsm'
rhdf5::H5close()

References

  • Muon: multimodal omics analysis framework preprint

  • mudata (Python) documentation

  • muon documentation and web page

  • Stoeckius, M., Hafemeister, C., Stephenson, W., Houck-Loomis, B., Chattopadhyay, P.K., Swerdlow, H., Satija, R. and Smibert, P., 2017. Simultaneous epitope and transcriptome measurement in single cells. Nature methods, 14(9), pp.865-868.

  • Hao, Y., Hao, S., Andersen-Nissen, E., Mauck III, W.M., Zheng, S., Butler, A., Lee, M.J., Wilk, A.J., Darby, C., Zager, M. and Hoffman, P., 2021. Integrated analysis of multimodal single-cell data. Cell.

Session Info

sessionInfo()
#> R Under development (unstable) (2023-10-10 r85312)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] scater_1.29.4                ggplot2_3.4.3               
#>  [3] scuttle_1.11.3               SingleCellMultiModal_1.13.15
#>  [5] MultiAssayExperiment_1.27.5  SingleCellExperiment_1.23.0 
#>  [7] SummarizedExperiment_1.31.1  Biobase_2.61.0              
#>  [9] GenomicRanges_1.53.2         GenomeInfoDb_1.37.6         
#> [11] IRanges_2.35.2               MatrixGenerics_1.13.1       
#> [13] matrixStats_1.0.0            MuData_0.99.9               
#> [15] rhdf5_2.45.1                 S4Vectors_0.39.2            
#> [17] BiocGenerics_0.47.0          Matrix_1.6-1.1              
#> [19] BiocStyle_2.29.2            
#> 
#> loaded via a namespace (and not attached):
#>   [1] jsonlite_1.8.7                magrittr_2.0.3               
#>   [3] ggbeeswarm_0.7.2              magick_2.8.0                 
#>   [5] farver_2.1.1                  rmarkdown_2.25               
#>   [7] fs_1.6.3                      zlibbioc_1.47.0              
#>   [9] ragg_1.2.6                    vctrs_0.6.3                  
#>  [11] memoise_2.0.1                 DelayedMatrixStats_1.23.4    
#>  [13] RCurl_1.98-1.12               htmltools_0.5.6.1            
#>  [15] S4Arrays_1.1.6                BiocBaseUtils_1.3.2          
#>  [17] AnnotationHub_3.9.2           curl_5.1.0                   
#>  [19] BiocNeighbors_1.19.0          Rhdf5lib_1.23.2              
#>  [21] SparseArray_1.1.12            sass_0.4.7                   
#>  [23] bslib_0.5.1                   desc_1.4.2                   
#>  [25] cachem_1.0.8                  mime_0.12                    
#>  [27] lifecycle_1.0.3               pkgconfig_2.0.3              
#>  [29] rsvd_1.0.5                    R6_2.5.1                     
#>  [31] fastmap_1.1.1                 GenomeInfoDbData_1.2.10      
#>  [33] shiny_1.7.5                   digest_0.6.33                
#>  [35] colorspace_2.1-0              AnnotationDbi_1.63.2         
#>  [37] rprojroot_2.0.3               irlba_2.3.5.1                
#>  [39] ExperimentHub_2.9.1           textshaping_0.3.7            
#>  [41] RSQLite_2.3.1                 beachmat_2.17.16             
#>  [43] labeling_0.4.3                filelock_1.0.2               
#>  [45] fansi_1.0.5                   httr_1.4.7                   
#>  [47] abind_1.4-5                   compiler_4.4.0               
#>  [49] bit64_4.0.5                   withr_2.5.1                  
#>  [51] BiocParallel_1.35.4           viridis_0.6.4                
#>  [53] DBI_1.1.3                     rappdirs_0.3.3               
#>  [55] DelayedArray_0.27.10          rjson_0.2.21                 
#>  [57] tools_4.4.0                   vipor_0.4.5                  
#>  [59] beeswarm_0.4.0                interactiveDisplayBase_1.39.0
#>  [61] httpuv_1.6.11                 glue_1.6.2                   
#>  [63] rhdf5filters_1.13.5           promises_1.2.1               
#>  [65] grid_4.4.0                    generics_0.1.3               
#>  [67] gtable_0.3.4                  BiocSingular_1.17.1          
#>  [69] ScaledMatrix_1.9.1            utf8_1.2.3                   
#>  [71] XVector_0.41.1                ggrepel_0.9.3                
#>  [73] BiocVersion_3.18.0            pillar_1.9.0                 
#>  [75] stringr_1.5.0                 later_1.3.1                  
#>  [77] dplyr_1.1.3                   BiocFileCache_2.9.1          
#>  [79] lattice_0.21-9                bit_4.0.5                    
#>  [81] tidyselect_1.2.0              Biostrings_2.69.2            
#>  [83] knitr_1.44                    gridExtra_2.3                
#>  [85] bookdown_0.35                 xfun_0.40                    
#>  [87] stringi_1.7.12                yaml_2.3.7                   
#>  [89] evaluate_0.22                 codetools_0.2-19             
#>  [91] tibble_3.2.1                  BiocManager_1.30.22          
#>  [93] cli_3.6.1                     xtable_1.8-4                 
#>  [95] systemfonts_1.0.5             munsell_0.5.0                
#>  [97] jquerylib_0.1.4               Rcpp_1.0.11                  
#>  [99] dbplyr_2.3.4                  png_0.1-8                    
#> [101] parallel_4.4.0                ellipsis_0.3.2               
#> [103] pkgdown_2.0.7                 blob_1.2.4                   
#> [105] sparseMatrixStats_1.13.4      bitops_1.0-7                 
#> [107] SpatialExperiment_1.11.2      viridisLite_0.4.2            
#> [109] scales_1.2.1                  purrr_1.0.2                  
#> [111] crayon_1.5.2                  rlang_1.1.1                  
#> [113] cowplot_1.1.1                 KEGGREST_1.41.4