19.2 Exporting matrix-level data

ArchR provides the getMatrixFromProject() function which allows you to export any matrix from your project as a SummarizedExperiment. The information returned is on a per-cell basis. In most cases, that matrix will be stored as a sparse matrix of class dgCMatrix. Some matrices, especially for larger projects, may take up excessive memory and lead to crashes when trying to export and there is really no way around this. This is, in fact, why ArchR leverages the on-disk storage of these data in HDF5 format.

For example, we can export the GeneScoreMatrix from our project like so:

GSM_se <- getMatrixFromProject(
    ArchRProj = projHeme5,
    useMatrix <- "GeneScoreMatrix"
)
## ArchR logging to : ArchRLogs/ArchR-getMatrixFromProject-371b05f05ce3b-Date-2022-12-23_Time-09-19-02.log
## If there is an issue, please report to github with logFile!
## 2022-12-23 09:19:16 : Organizing colData, 0.231 mins elapsed.
## 2022-12-23 09:19:16 : Organizing rowData, 0.232 mins elapsed.
## 2022-12-23 09:19:16 : Organizing rowRanges, 0.232 mins elapsed.
## 2022-12-23 09:19:16 : Organizing Assays (1 of 1), 0.232 mins elapsed.
## 2022-12-23 09:19:17 : Constructing SummarizedExperiment, 0.243 mins elapsed.
## 2022-12-23 09:19:20 : Finished Matrix Creation, 0.288 mins elapsed.

When we inspect this object, we can see the various attributes stored in the SummarizedExperiment:

GSM_se
## class: SummarizedExperiment 
## dim: 23127 10250 
## metadata(0):
## assays(1): GeneScoreMatrix
## rownames: NULL
## rowData names(6): seqnames start ... name idx
## colnames(10250): scATAC_BMMC_R1#TTATGTCAGTGATTAG-1
##   scATAC_BMMC_R1#AAGATAGTCACCGCGA-1 ...
##   scATAC_PBMC_R1#TTCGTTACATTGAACC-1 scATAC_PBMC_R1#CGCTATCGTGAGGTCA-1
## colData names(39): BlacklistRatio DoubletEnrichment ...
##   Monocle_Lymphoid Slingshot_Lymphoid.Curve1

For various reasons, we do not provide a method for directly converting an ArchRProject into an object that can interface with other tools like Seurat. Given the large differences in how these different tools work, this is beyond the scope of what we aim to support. However, once a matrix is exported as a SummarizedExperiment object, it is relatively simple to reformat that object to something that can be imported into the Seurat ecosystem. Shown below is an example of how this might be accomplished using a GeneScoreMatrix but the same applies to other matrices:

library(SingleCellExperiment)
library(Seurat)
GSM_sce <- as(GSM_se, "SingleCellExperiment")
counts <- as.matrix(assay(GSM_sce, "GeneScoreMatrix"))
assays(GSM_sce)$counts <- counts
libSizes <- colSums(counts)
sizeFactors <- libSizes/mean(libSizes)
assays(GSM_sce)$logcounts <- log2(t(t(counts)/sizeFactors) + 1)
rownames(GSM_sce) <- rowData(GSM_sce)$name
seuratObj <- as.Seurat(GSM_sce, counts = "counts", data = "logcounts")
## Warning: Feature names cannot have underscores ('_'), replacing with dashes
## ('-')

## Warning: Feature names cannot have underscores ('_'), replacing with dashes
## ('-')

This gives us an object of class Seurat:

seuratObj
## An object of class Seurat 
## 23127 features across 10250 samples within 1 assay 
## Active assay: originalexp (23127 features, 0 variable features)

You can then manipulate this object as you would any other Seurat object. Other operations are possible, for example, you can take your dimensionality reduction results from ArchR and add them to this Seurat object:

seuratObj[["iterativeLSI"]] <- CreateDimReducObject(embeddings = getReducedDims(projHeme5), key = "ILSI_", assay = DefaultAssay(seuratObj))