-
Notifications
You must be signed in to change notification settings - Fork 919
Seurat
The Seurat
object ...
Slot | Function |
---|---|
assays |
A list of assays within this object |
meta.data |
Cell-level meta data |
active.assay |
Name of active, or default, assay |
active.ident |
Identity classes for the current object |
graphs |
A list of nearest neighbor graphs |
reductions |
A list of DimReduc objects |
project.name |
User-defined project name (optional) |
tools |
Empty list. Tool developers can store any internal data from their methods here |
misc |
Empty slot. User can store additional information here |
version |
Seurat version used when creating the object |
Summary information about Seurat
objects can be had quickly and easily using standard R functions. Object shape/dimensions can be found using the dim
, ncol
, and nrow
functions; cell and feature names can be found using the colnames
and rownames
functions, respectively, or the dimnames
function. A vector of names of Assay
, DimReduc
, and Graph
objects contained in a Seurat
object can be had by using names
.
# The following examples use the PBMC 3k dataset
> pbmc
An object of class Seurat
13714 features across 2638 samples within 1 assay
2 dimensional reductions calculated: pca, tsne
# nrow and ncol provide the number of features and cells in the active assay, respectively
# dim provides both nrow and ncol at the same time
> dim(x = pbmc)
[1] 13714 2638
# In addtion to rownames and colnames, one can use dimnames
# which provides a two-length list with both rownames and colnames
> head(x = rownames(x = pbmc))
[1] "AL627309.1" "AP006222.2" "RP11-206L10.2" "RP11-206L10.9"
[5] "LINC00115" "NOC2L"
> head(x = colnames(x = pbmc))
[1] "AAACATACAACCAC" "AAACATTGAGCTAC" "AAACATTGATCAGC" "AAACCGTGCTTCCG"
[5] "AAACCGTGTATGCG" "AAACGCACTGGTAC"
# A vector of names of associated objects can be had with the names function
# These can be passed to the double [[ extract operator to pull them from the Seurat object
> names(x = pbmc)
[1] "RNA" "pca" "tsne"
Pulling specific Assay
, DimReduc
, or Graph
objects can be done with the double [[
extract operator. Adding new objects to a Seurat
object is also done with the double [[
extract operator; Seurat will figure out where in the Seurat
object a new associated object belongs.
> pbmc[['RNA']]
Assay data with 13714 features for 2638 cells
Top 10 variable features:
PPBP, DOK3, NFE2L2, ARVCF, YPEL2, UBE2D4, FAM210B, CTB-113I20.2, GBGT1,
GMPPA
> pbmc[['tsne']]
A dimensional reduction object with key tSNE_
Number of dimensions: 2
Projected dimensional reduction calculated: FALSE
Jackstraw run: FALSE
Accessing data from an Seurat
object is done with the GetAssayData
function. Adding expression data to either the counts
, data
, or scale.data
slots can be done with SetAssayData
. New data must have the same cells in the same order as the current expression data. Data added to counts
or data
must have the same features as the current expression data.
> GetAssayData(object = pbmc, slot = 'scale.data')[1:3, 1:3]
AAACATACAACCAC AAACATTGAGCTAC AAACATTGATCAGC
AL627309.1 -0.06547546 -0.10052277 -0.05804007
AP006222.2 -0.02690776 -0.02820169 -0.04508318
RP11-206L10.2 -0.03596234 -0.17689415 -0.09997719
# SetAssayData example...
Cell-level meta data can be accessed with the single [[
extract operator or using the $
sigil. Pulling with the $
sigil means only one bit of meta data can be pulled at a time, though tab-autocompletion has been enabled for it, making it ideal for interactive use. Adding cell-level meta data can be set using the single [[
extract operator as well, or by using AddMetaData
.
# Cell-level meta data is stored as a data frame
# Standard data frame functions work on the meta data data frame
> colnames(x = pbmc[[]])
[1] "nGene" "nUMI" "orig.ident" "percent.mito" "res.0.6"
# One can pull multiple values from the data frame at any time
> head(x = pbmc[[c('nUMI', 'percent.mito')]])
nUMI percent.mito
AAACATACAACCAC 2421 0.030177759
AAACATTGAGCTAC 4903 0.037935958
AAACATTGATCAGC 3149 0.008897363
AAACCGTGCTTCCG 2639 0.017430845
AAACCGTGTATGCG 981 0.012244898
AAACGCACTGGTAC 2164 0.016643551
# The $ sigil can only pull bit of meta data at a time; however, tab-autocompletion
# has been enabled for the $ sigil, making it ideal for interactive use
> head(x = pbmc$percent.mito)
percent.mito
AAACATACAACCAC 0.030177759
AAACATTGAGCTAC 0.037935958
AAACATTGATCAGC 0.008897363
AAACCGTGCTTCCG 0.017430845
AAACCGTGTATGCG 0.012244898
AAACGCACTGGTAC 0.016643551
# Passing `drop = TRUE` will turn the meta data into a names vector
# with each entry being named for the cell it corresponds to
> head(x = pbmc[['res.0.6', drop = TRUE]])
AAACATACAACCAC AAACATTGAGCTAC AAACATTGATCAGC AAACCGTGCTTCCG AAACCGTGTATGCG
"0" "2" "0" "1" "5"
AAACGCACTGGTAC
"0"
# Add meta data example
The HVFInfo
function pulls feature mean and dispersion from an Assay
object. The vector of variable features can be pulled with the VariableFeatures
function. VariableFeatures
can also set the vector of variable features.
# HVFInfo pulls mean, dispersion, and dispersion scaled
# Useful for viewing the results of FindVariableFeatures
> head(x = HVFInfo(object = pbmc))
mean dispersion dispersion.scaled
AL627309.1 0.013555659 1.432845 -0.6236875
AP006222.2 0.004695980 1.458631 -0.5728009
RP11-206L10.2 0.005672517 1.325459 -0.8356099
RP11-206L10.9 0.002644177 0.859264 -1.7556304
LINC00115 0.027437275 1.457477 -0.5750770
NOC2L 0.376037723 1.876440 -0.4162432
# VariableFeatures both accesses and sets the vector of variable features
> head(x = VariableFeatures(object = pbmc))
[1] "PPBP" "DOK3" "NFE2L2" "ARVCF" "YPEL2" "UBE2D4"
# Set variable features example
A vector of standard deviations for a DimReduc
stored within the Seurat object can be found with Stdev
.
> Stdev(object = pbmc, reduction.use = 'pca')
[1] 5.666584 4.326466 3.952192 3.638124 2.191529 1.996551 1.877891 1.798251
[9] 1.766873 1.753684 1.731568 1.720525 1.718079 1.715879 1.707009 1.702660
[17] 1.697318 1.692549 1.686149 1.683967
Methods for the Seurat
class can be found with the following:
library(Seurat)
utils::methods(class = 'Seurat')
[
[[
[[<-
colMeans
colSums
Command
DefaultAssay
DefaultAssay<-
dimnames
dim
GetAssayData
GetAssay
HVFInfo
Idents
Idents<-
merge
names
SetAssayData
Stdev
subset
SubsetData
VariableFeatures
VariableFeatures<-
WhichCells