Skip to contents

This function converts data stored in SingleCellExperiment (SCE), Seurat object or a merged sparse matrix (dgCMatrix) into a liger object. This is designed for a container object or matrix that already contains multiple datasets to be integerated with LIGER. For individual datasets, please use createLiger instead.

Usage

# S3 method for dgCMatrix
as.liger(object, datasetVar = NULL, modal = NULL, ...)

# S3 method for SingleCellExperiment
as.liger(object, datasetVar = NULL, modal = NULL, ...)

# S3 method for Seurat
as.liger(object, datasetVar = NULL, modal = NULL, assay = NULL, ...)

seuratToLiger(object, datasetVar = NULL, modal = NULL, assay = NULL, ...)

as.liger(object, ...)

Arguments

object

Object.

datasetVar

Specify the dataset belonging by: 1. Select a variable from existing metadata in the object (e.g. colData column); 2. Specify a vector/factor that assign the dataset belonging. 3. Give a single character string which means that all data is from one dataset (must not be a metadata variable, otherwise it is understood as 1.). Default NULL gathers things into one dataset and names it "sample" for dgCMatrix, attempts to find variable "sample" from SCE or "orig.ident" from Seurat.

modal

Modality setting for each dataset. See createLiger.

...

Additional arguments passed to createLiger

assay

Name of assay to use. Default NULL uses current active assay.

Value

a liger object.

Details

For Seurat V5 structure, it is highly recommended that users make use of its split layer feature, where things like "counts", "data", and "scale.data" can be held for each dataset in the same Seurat object, e.g. with "count.ctrl", "count.stim", not merged. If a Seurat object with split layers is given, datasetVar will be ignored and the layers will be directly used.

Examples

# dgCMatrix (common sparse matrix class), usually obtained from other
# container object, and contains multiple samples merged in one.
matList <- rawData(pbmc)
multiSampleMatrix <- mergeSparseAll(matList)
# The `datasetVar` argument expects the variable assigning the sample source
pbmc2 <- as.liger(multiSampleMatrix, datasetVar = pbmc$dataset)
#> ! No human mitochondrial gene found in the union of dataset "ctrl"
#>  calculating QC for dataset "ctrl"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "ctrl"

#>  calculating QC for dataset "ctrl" ... done
#> 
#> ! No human mitochondrial gene found in the union of dataset "stim"
#>  calculating QC for dataset "stim"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "stim"

#>  calculating QC for dataset "stim" ... done
#> 
pbmc2
#> An object of class liger with 600 cells
#> datasets(2): ctrl (300 cells), stim (300 cells) 
#> cellMeta(7): dataset, barcode, nUMI, ..., hemo 
#> varFeatures(0):  
#> dimReds(0):  

# \donttest{
if (requireNamespace("SingleCellExperiment", quietly = TRUE)) {
    sce <- SingleCellExperiment::SingleCellExperiment(
        assays = list(counts = multiSampleMatrix)
    )
    sce$sample <- pbmc$dataset
    pbmc3 <- as.liger(sce, datasetVar = "sample")
    pbmc3
}
#> ! No human mitochondrial gene found in the union of dataset "ctrl"
#>  calculating QC for dataset "ctrl"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "ctrl"

#>  calculating QC for dataset "ctrl" ... done
#> 
#> ! No human mitochondrial gene found in the union of dataset "stim"
#>  calculating QC for dataset "stim"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "stim"

#>  calculating QC for dataset "stim" ... done
#> 
#> An object of class liger with 600 cells
#> datasets(2): ctrl (300 cells), stim (300 cells) 
#> cellMeta(8): dataset, barcode, nUMI, ..., sample 
#> varFeatures(0):  
#> dimReds(0):  

if (requireNamespace("Seurat", quietly = TRUE)) {
    seu <- SeuratObject::CreateSeuratObject(multiSampleMatrix)
    # Seurat creates variable "orig.ident" by identifying the cell barcode
    # prefixes, which is indeed what we need in this case. Users might need
    # to be careful and have it confirmed first.
    pbmc4 <- as.liger(seu, datasetVar = "orig.ident")
    pbmc4

    # As per Seurat V5 updates with layered data, specifically helpful udner the
    # scenario of dataset integration. "counts" and etc for each datasets can be
    # split into layers.
    seu5 <- seu
    seu5[["RNA"]] <- split(seu5[["RNA"]], pbmc$dataset)
    print(SeuratObject::Layers(seu5))
    pbmc5 <- as.liger(seu5)
    pbmc5
}
#> ! No human mitochondrial gene found in the union of dataset "ctrl"
#>  calculating QC for dataset "ctrl"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "ctrl"

#>  calculating QC for dataset "ctrl" ... done
#> 
#> ! No human mitochondrial gene found in the union of dataset "stim"
#>  calculating QC for dataset "stim"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "stim"

#>  calculating QC for dataset "stim" ... done
#> 
#> [1] "counts.ctrl" "counts.stim"
#> ! No human mitochondrial gene found in the union of dataset "ctrl"
#>  calculating QC for dataset "ctrl"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "ctrl"

#>  calculating QC for dataset "ctrl" ... done
#> 
#> ! No human mitochondrial gene found in the union of dataset "stim"
#>  calculating QC for dataset "stim"
#>  Updated QC variables: "nUMI", "nGene", "mito", "ribo", and "hemo"
#>  calculating QC for dataset "stim"

#>  calculating QC for dataset "stim" ... done
#> 
#> An object of class liger with 600 cells
#> datasets(2): ctrl (300 cells), stim (300 cells) 
#> cellMeta(10): dataset, barcode, nUMI, ..., nFeature_RNA 
#> varFeatures(0):  
#> dimReds(0):  
# }