SCE-combine {SingleCellExperiment} | R Documentation

## Combining or subsetting SingleCellExperiment objects

### Description

An overview of methods to combine multiple SingleCellExperiment objects by row or column, or to subset a SingleCellExperiment by row or column. These methods are useful for ensuring that all data fields remain synchronized when cells or genes are added or removed.

### Combining

In the following code snippets, `...` contains one or more SingleCellExperiment objects.

`rbind(..., deparse.level=1)`:

  Returns a SingleCellExperiment where all objects in `...` are combined row-wise, i.e., rows in successive objects are appended to the first object.

  Refer to `?"rbind,SummarizedExperiment-method"` for details on how metadata is combined in the output object. Refer to `?rbind` for the interpretation of `deparse.level`.

  Note that all objects in `...` must have the exact same values for `reducedDims` and `altExps`. Any `sizeFactors` should either be `NULL` or contain the same values across objects.

`cbind(..., deparse.level=1)`:

  Returns a SingleCellExperiment where all objects in `...` are combined column-wise, i.e., columns in successive objects are appended to the first object.

  Each object `x` in `...` must have the same values of `reducedDimNames(x)` (though they can be unordered). Dimensionality reduction results with the same name across objects will be combined row-wise to create the corresponding entry in the output object.

  Each object `x` in `...` must have the same values of `altExpNames(x)` (though they can be unordered). Alternative Experiments with the same name across objects will be combined column-wise to create the corresponding entry in the output object.

  `sizeFactors` should be either set to `NULL` in all objects, or set to a numeric vector in all objects.

  Refer to `?"cbind,SummarizedExperiment-method"` for details on how metadata is combined in the output object. Refer to `?cbind` for the interpretation of `deparse.level`.

### Subsetting

In the following code snippets, `x` is a SingleCellExperiment object.

`x[i, j, ..., drop=TRUE]`:

  Returns a SingleCellExperiment containing the specified rows `i` and columns `j`.

  `i` and `j` can be a logical, integer or character vector of subscripts, indicating the rows and columns respectively to retain. Either can be missing, in which case subsetting is only performed in the specified dimension. If both are missing, no subsetting is performed.

  Arguments in `...` and `drop` are passed to to `[,SummarizedExperiment-method`.

`x[i, j, ...] <- value`:

  Replaces all data for rows `i` and columns j with the corresponding fields in a SingleCellExperiment `value`.

  `i` and `j` can be a logical, integer or character vector of subscripts, indicating the rows and columns respectively to replace. Either can be missing, in which case replacement is only performed in the specified dimension. If both are missing, `x` is replaced entirely with `value`.

  If `j` is specified, `value` is expected to have the same name and order of `reducedDimNames` and `altExpNames` as `x`. If `sizeFactors` is set for `x`, it should also be set for `value`.

  Arguments in `...` are passed to the corresponding SummarizedExperiment method.

### Author(s)

Aaron Lun

### Examples

    example(SingleCellExperiment, echo=FALSE) # using the class example

    # Combining:
    rbind(sce, sce)
    cbind(sce, sce)

    # Subsetting:
    sce[1:10,]
    sce[,1:5]

    sce2 <- sce
    sce2[1:10,] <- sce[11:20,]

    # Can also use subset()
    sce$WHEE <- sample(LETTERS, ncol(sce), replace=TRUE)
    subset(sce, , WHEE=="A")

    # Can also use split()
    split(sce, sample(LETTERS, nrow(sce), replace=TRUE))

[Package SingleCellExperiment version 1.9.3 Index]