This vignette demonstrates how to store and interact with dimensional reduction information (such as the output from `RunPCA`

) in Seurat v3.0. For demonstration purposes, we will be using the 2,700 PBMC object that is created in the first guided tutorial. You can download the pre-computed object here.

```
library(Seurat)
pbmc <- readRDS(file = "../data/pbmc3k_final.rds")
```

In Seurat v3.0, storing and interacting with dimensional reduction information has been generalized and formalized into the `DimReduc`

object. Each dimensional reduction procedure is stored as a `DimReduc`

object in the `object@reductions`

slot as an element of a named list. Accessing these reductions can be done with the `[[`

operator, calling the name of the reduction desired. For example, after running a principle component analysis with `RunPCA`

, `object[['pca']]`

will contain the results of the PCA. By adding new elements to the list, users can add additional, and custom, dimensional reductions. Each stored dimensional reduction contains the following slots:

**cell.embeddings**: stores the coordinates for each cell in low-dimensional space.**feature.loadings**: stores the weight for each feature along each dimension of the embedding**feature.loadings.projected**: Seurat typically calculate the dimensional reduction on a subset of genes (for example, high-variance genes), and then project that structure onto the entire dataset (all genes). The results of that projection (calculated with`ProjectDim`

) are stored in this slot. Note that the cell loadings will remain unchanged after projection but there are now feature loadings for all feature**stdev**: The standard deviations of each dimension. Most often used with PCA (storing the square roots of the eigenvalues of the covariance matrix) and can be useful when looking at the drop off in the amount of variance that is explained by each successive dimension.**key**: Sets the column names for the cell.embeddings and feature.loadings matrices. For example, for PCA, the column names are PC1, PC2, etc., so the key is “PC”.**jackstraw**: Stores the results of the jackstraw procedure run using this dimensional reduction technique. Currently supported only for PCA.**misc**: Bonus slot to store any other information you might want

To access these slots, we provide the `Embeddings`

,`Loadings`

, and `Stdev`

functions

`pbmc[["pca"]]`

```
## A dimensional reduction object with key PC_
## Number of dimensions: 50
## Projected dimensional reduction calculated: FALSE
## Jackstraw run: TRUE
## Computed using assay: RNA
```

`head(Embeddings(pbmc, reduction = "pca")[, 1:5])`

```
## PC_1 PC_2 PC_3 PC_4 PC_5
## AAACATACAACCAC-1 -4.7296855 -0.5184265 -0.7623220 -2.3156790 -0.07160006
## AAACATTGAGCTAC-1 -0.5174029 4.5918957 5.9091921 6.9118856 -1.96243034
## AAACATTGATCAGC-1 -3.1891063 -3.4695154 -0.8313710 -2.0019985 -5.10442765
## AAACCGTGCTTCCG-1 12.7933021 0.1007166 0.6310221 -0.3687338 0.21838204
## AAACCGTGTATGCG-1 -3.1288078 -6.3481412 1.2507776 3.0191026 7.84739502
## AAACGCACTGGTAC-1 -3.1088963 0.9262125 -0.6482331 -2.3244378 -2.00526763
```

`head(Loadings(pbmc, reduction = "pca")[, 1:5])`

```
## PC_1 PC_2 PC_3 PC_4 PC_5
## PPBP 0.010990202 0.01148426 -0.15176092 0.10403737 0.003299077
## LYZ 0.116231706 0.01472515 -0.01280613 -0.04414540 0.049906881
## S100A9 0.115414362 0.01895146 -0.02368853 -0.05787777 0.085382309
## IGLL5 -0.007987473 0.05454239 0.04901533 0.06694722 0.004603231
## GNLY -0.015238762 -0.13375626 0.04101340 0.06912322 0.104558611
## FTL 0.118292572 0.01871142 -0.00984755 -0.01555269 0.038743505
```

`head(Stdev(pbmc, reduction = "pca"))`

`## [1] 7.098420 4.495493 3.872592 3.748859 3.171755 2.545292`

Seurat provides `RunPCA`

(pca), and `RunTSNE`

(tsne), and representing dimensional reduction techniques commonly applied to scRNA-seq data. When using these functions, all slots are filled automatically.

We also allow users to add the results of a custom dimensional reduction technique (for example, multi-dimensional scaling (MDS), or zero-inflated factor analysis), that is computed separately. All you need is a matrix with each cell’s coordinates in low-dimensional space, as shown below.

Though not incorporated as part of the Seurat package, its easy to run multidimensional scaling (MDS) in R. If you were interested in running MDS and storing the output in your Seurat object:

```
# Before running MDS, we first calculate a distance matrix between all pairs of cells. Here we
# use a simple euclidean distance metric on all genes, using scale.data as input
d <- dist(t(GetAssayData(pbmc, slot = "scale.data")))
# Run the MDS procedure, k determines the number of dimensions
mds <- cmdscale(d = d, k = 2)
# cmdscale returns the cell embeddings, we first label the columns to ensure downstream
# consistency
colnames(mds) <- paste0("MDS_", 1:2)
# We will now store this as a custom dimensional reduction called 'mds'
pbmc[["mds"]] <- CreateDimReducObject(embeddings = mds, key = "MDS_", assay = DefaultAssay(pbmc))
# We can now use this as you would any other dimensional reduction in all downstream functions
DimPlot(pbmc, reduction = "mds", pt.size = 0.5)
```