R: Seurat Methods

Seurat-methods {SeuratObject} | R Documentation

## Seurat Methods

### Description

Methods for `Seurat` objects for generics defined in other packages

### Usage

    ## S3 method for class 'Seurat'
    .DollarNames(x, pattern = "")

    ## S3 method for class 'Seurat'
    x$i, ...

    ## S3 replacement method for class 'Seurat'
    x$i, ... <- value

    ## S3 method for class 'Seurat'
    x[i, j, ...]

    ## S3 method for class 'Seurat'
    x[[i, ..., drop = FALSE]]

    ## S3 method for class 'Seurat'
    dim(x)

    ## S3 method for class 'Seurat'
    dimnames(x)

    ## S3 method for class 'Seurat'
    head(x, n = 10L, ...)

    ## S3 method for class 'Seurat'
    merge(
      x = NULL,
      y = NULL,
      add.cell.ids = NULL,
      merge.data = TRUE,
      merge.dr = NULL,
      project = "SeuratProject",
      ...
    )

    ## S3 method for class 'Seurat'
    names(x)

    ## S3 method for class 'Seurat'
    subset(
      x,
      subset,
      cells = NULL,
      features = NULL,
      idents = NULL,
      return.null = FALSE,
      ...
    )

    ## S3 method for class 'Seurat'
    tail(x, n = 10L, ...)

    ## S4 replacement method for signature 'Seurat'
    x[[i, j, ...]] <- value

    ## S4 method for signature 'Seurat'
    colMeans(x, na.rm = FALSE, dims = 1, ..., slot = "data")

    ## S4 method for signature 'Seurat'
    colSums(x, na.rm = FALSE, dims = 1, ..., slot = "data")

    ## S4 method for signature 'Seurat'
    rowMeans(x, na.rm = FALSE, dims = 1, ..., slot = "data")

    ## S4 method for signature 'Seurat'
    rowSums(x, na.rm = FALSE, dims = 1, ..., slot = "data")

    ## S4 method for signature 'Seurat'
    show(object)

### Arguments

`x, object` | A `Seurat` object
`pattern` | A regular expression. Only matching names are returned.
`i, features` | Depends on the method `[`, `subset` Feature names or indices `$`, `$<-` Name of a single metadata column `[[`, `[[<-` Name of one or more metadata columns or an associated object; associated objects include `Assay`, `DimReduc`, `Graph`, `SeuratCommand`, or `SpatialImage` objects
`...` | Arguments passed to other methods
`value` | Additional metadata or associated objects to add; note: can pass `NULL` to remove metadata or an associated object
`j, cells` | Cell names or indices
`drop` | See `drop`
`n` | The number of rows of metadata to return
`y` | A single `Seurat` object or a list of `Seurat` objects
`add.cell.ids` | A character vector of `length(x = c(x, y))`; appends the corresponding values to the start of each objects' cell names
`merge.data` | Merge the data slots instead of just merging the counts (which requires renormalization); this is recommended if the same normalization approach was applied to all objects
`merge.dr` | Merge specified DimReducs that are present in all objects; will only merge the embeddings slots for the first `N` dimensions that are shared across all objects.
`project` | Project name for the `Seurat` object
`subset` | Logical expression indicating features/variables to keep
`idents` | A vector of identity classes to keep
`return.null` | If no cells are request, return a `NULL`; by default, throws an error
`na.rm` | logical. Should missing values (including `NaN`) be omitted from the calculations?
`dims` | completely ignored by the `Matrix` methods.
`slot` | Name of assay expression matrix to calculate column/row means/sums on

### Value

`$`: metadata column `i` for object `x`; note: unlike `[[`, `$` drops the shape of the metadata to return a vector instead of a data frame

`$<-`: object `x` with metadata `value` saved as `i`

`[`: object `x` with features `i` and cells `j`

`[[`: If `i` is missing, the metadata data frame; if `i` is a vector of metadata names, a data frame with the requested metadata, otherwise, the requested associated object

`dim`: The number of features (`nrow`) and cells (`ncol`) for the default assay; note: while the number of features changes depending on the active assay, the number of cells remains the same across all assays

`dimnames`: The feature (row) and cell (column) names; note: while the features change depending on the active assay, the cell names remain the same across all assays

`head`: The first `n` rows of cell-level metadata

`merge`: Merged object

`names`: The names of all `Assay`, `DimReduc`, `Graph`, and `SpatialImage` objects in the `Seurat` object

`subset`: A subsetted `Seurat` object

`tail`: The last `n` rows of cell-level metadata

`[[<-`: `x` with the metadata or associated objects added as `i`; if `value` is `NULL`, removes metadata or associated object `i` from object `x`

`show`: Prints summary to `stdout` and invisibly returns `NULL`

### Functions

- `.DollarNames.Seurat`: Autocompletion for `$` access on a `Seurat` object

- `$.Seurat`: Metadata access for `Seurat` objects

- `$<-.Seurat`: Metadata setter for `Seurat` objects

- `[.Seurat`: Simple subsetter for `Seurat` objects

- `[[.Seurat`: Metadata and associated object accessor

- `dim.Seurat`: Number of cells and features for the active assay

- `dimnames.Seurat`: The cell and feature names for the active assay

- `head.Seurat`: Get the first rows of cell-level metadata

- `merge.Seurat`: Merge two or more `Seurat` objects together

- `names.Seurat`: Common associated objects

- `subset.Seurat`: Subset a `Seurat` object

- `tail.Seurat`: Get the last rows of cell-level metadata

- `[[<-,Seurat-method`: Add cell-level metadata or associated objects

- `colMeans,Seurat-method`: Calculate `colMeans` on a `Seurat` object

- `colSums,Seurat-method`: Calculate `colSums` on a `Seurat` object

- `rowMeans,Seurat-method`: Calculate `rowMeans` on a `rowMeans` object

- `rowSums,Seurat-method`: Calculate `rowSums` on a `Seurat` object

- `show,Seurat-method`: Overview of a `Seurat` object

### Merge Details

When merging Seurat objects, the merge procedure will merge the Assay level counts and potentially the data slots (depending on the merge.data parameter). It will also merge the cell-level meta data that was stored with each object and preserve the cell identities that were active in the objects pre-merge. The merge will optionally merge reductions depending on the values passed to `merge.dr` if they have the same name across objects. Here the embeddings slots will be merged and if there are differing numbers of dimensions across objects, only the first N shared dimensions will be merged. The feature loadings slots will be filled by the values present in the first object.The merge will not preserve graphs, logged commands, or feature-level metadata that were present in the original objects. If add.cell.ids isn't specified and any cell names are duplicated, cell names will be appended with _X, where X is the numeric index of the object in c(x, y).

### See Also

`subset` `WhichCells`

### Examples

    # Get metadata using `$'
    head(pbmc_small$groups)

    # Add metadata using the `$' operator
    set.seed(42)
    pbmc_small$value <- sample(1:3, size = ncol(pbmc_small), replace = TRUE)
    head(pbmc_small[["value"]])

    # `[' examples
    pbmc_small[VariableFeatures(object = pbmc_small), ]
    pbmc_small[, 1:10]

    # Get the cell-level metadata data frame
    head(pbmc_small[[]])

    # Pull specific metadata information
    head(pbmc_small[[c("letter.idents", "groups")]])
    head(pbmc_small[["groups", drop = TRUE]])

    # Get a sub-object (eg. an `Assay' or `DimReduc')
    pbmc_small[["RNA"]]
    pbmc_small[["pca"]]

    # Get the number of features in an object
    nrow(pbmc_small)

    # Get the number of cells in an object
    ncol(pbmc_small)

    # Get the feature names of an object
    rownames(pbmc_small)

    # Get the cell names of an object
    colnames(pbmc_small)

    # Get the first 10 rows of cell-level metadata
    head(pbmc_small)

    # `merge' examples
    # merge two objects
    merge(pbmc_small, y = pbmc_small)
    # to merge more than two objects, pass one to x and a list of objects to y
    merge(pbmc_small, y = c(pbmc_small, pbmc_small))

    names(pbmc_small)

    # `subset' examples
    subset(pbmc_small, subset = MS4A1 > 4)
    subset(pbmc_small, subset = `DLGAP1-AS1` > 2)
    subset(pbmc_small, idents = '0', invert = TRUE)
    subset(pbmc_small, subset = MS4A1 > 3, slot = 'counts')
    subset(pbmc_small, features = VariableFeatures(object = pbmc_small))

    # Get the last 10 rows of cell-level metadata
    tail(pbmc_small)

    head(colMeans(pbmc_small))

    head(colSums(pbmc_small))

    head(rowMeans(pbmc_small))

    head(rowSums(pbmc_small))

[Package SeuratObject version 4.0.3 Index]