# Using external list of PCs for clustering

I am going to use principal components (PCs) comes from calcPCA function in URD program for clustering my cells in Seurat; So

seurat@[email protected]

> seurat <- FindClusters(
+     object = seurat,
+     reduction.type = "pca",
+     dims.use = 1:8,
+     resolution = 1.0,
+     print.output = 0,
+     save.SNN = TRUE
+ )
Error in GetDimReduction(object = object, reduction.type = reduction.type,  :
cell.embeddings slot doesn't exist


There is seuratToURD function but there is not URD to seurat function I guess so I could use URD object for clustering in seurat How I can overcome this error please? I want to see when I am using PCA from URD what would be my clustering by SNN algorithm in seurat

Thanks a lot for any help

There is a way to do this, and even better--there is documentation for how to do it! No surprise coming from the Satija Lab. In the vignette they perform multidimensional scaling, but the idea is the same. cmdscale() returns the cell embeddings. SetDimReduction() is the Seurat function you are looking for. No manual editing using @ required.

The authors use add mds embeddings, but if you want to add your own pca embeddings swap out "mds" for "pca" and mds for [email protected].

# 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 [email protected] as input
d <- dist(x = t(x = [email protected]))
# 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(x = mds) <- paste0("MDS", 1:2)
# We will now store this as a new dimensional reduction called 'mds'
pbmc <- SetDimReduction(object = pbmc, reduction.type = "mds", slot = "cell.embeddings",
new.data = mds)
pbmc <- SetDimReduction(object = pbmc, reduction.type = "mds", slot = "key",
new.data = "MDS")


See the dimensional reduction vignette for more.

• Thank you, but I have already demential reduction matrix (PCs) by another program (URD) and I want to store that in Seurat object for clustering Commented Oct 24, 2018 at 15:13
• In SetDimReduction() replace "mds" with "pca" and mds with [email protected]. Commented Oct 24, 2018 at 15:17
• Thank you > pbmc <- SetDimReduction(object = seuset, reduction.type = "pca", slot = "cell.embeddings", + new.data = [email protected]) Show Traceback Rerun with Debug Error in (function (cl, name, valueClass) : ‘cell.embeddings’ is not a slot in class “data.frame” > Commented Oct 24, 2018 at 15:27
• Try str(seuset) to ensure your Seurat object is whole. You might also RunPCA() within Seurat and return to cell.embeddings to ensure the format of your external embeddings is identical. I'd also recommend changing reduction.type="pca" to something like reduction.type="pca.external" just to ensure you aren't dealing with some protected fields in the S4 object. Commented Oct 26, 2018 at 14:02