Answers.Body: <p>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. <code>cmdscale()</code> returns the cell embeddings. <code>SetDimReduction()</code> is the Seurat function you are looking for. No manual editing using <code>@</code> required.</p>
  
  <p>The authors use add mds embeddings, but if you want to add your own pca embeddings swap out <code>"mds"</code> for <code>"pca"</code> and <code>mds</code> for <code>URD_object@pca.load</code>.</p>
  
  <pre><code># 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 object@scale.data as input
  d &lt;- dist(x = t(x = pbmc@scale.data))
  # Run the MDS procedure, k determines the number of dimensions
  mds &lt;- cmdscale(d = d, k = 2)
  # cmdscale returns the cell embeddings, we first label the columns to ensure
  # downstream consistency
  colnames(x = mds) &lt;- paste0("MDS", 1:2)
  # We will now store this as a new dimensional reduction called 'mds'
  pbmc &lt;- SetDimReduction(object = pbmc, reduction.type = "mds", slot = "cell.embeddings", 
      new.data = mds)
  pbmc &lt;- SetDimReduction(object = pbmc, reduction.type = "mds", slot = "key", 
      new.data = "MDS")
  </code></pre>
  
  <p>See <a href="https://satijalab.org/seurat/dim_reduction_vignette.html" rel="nofollow noreferrer">the dimensional reduction vignette</a> for more.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-24T15:13:54.993Z
Answers.Text: 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
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-24T15:17:31.777Z
Answers.Text: In `SetDimReduction()` replace `"mds"` with `"pca"` and `mds` with `URD_object@pca.load`.
Answers.UserDisplayName: Kohl Kinning
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-24T15:27:07.450Z
Answers.Text: Thank you                                                                                                              > pbmc <- SetDimReduction(object = seuset, reduction.type = "pca", slot = "cell.embeddings", 
  +                         new.data = URD@pca.scores)
   Show Traceback
   
   Rerun with Debug
   Error in (function (cl, name, valueClass)  : 
    ‘cell.embeddings’ is not a slot in class “data.frame” 
  >
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-26T14:02:38.127Z
Answers.Text: 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.
Answers.UserDisplayName: Kohl Kinning
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-24T14:50:10.730Z
Answers.LastActivityDate: 2018-10-24T15:20:28.790Z
Answers.LastEditDate: 2018-10-24T15:20:28.790Z
Answers.UserDisplayName: Kohl Kinning
Body: <p>I am going to use principal components (PCs) comes from calcPCA function in URD program for clustering my cells in Seurat; So</p>
  
  <pre><code>seurat@dr$pca=URD_object@pca.load
  
  &gt; seurat &lt;- 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
  </code></pre>
  
  <p>There is <code>seuratToURD</code> 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</p>
  
  <p>Thanks a lot for any help</p>
  
Tags: <seurat><clustering><pca>
Title: Using external list of PCs for clustering
ThreadText: # Using external list of PCs for clustering
  
  (Asked by: username_0 on 2018-10-24)
  
  I am going to use principal components (PCs) comes from calcPCA function in URD program for clustering my cells in Seurat; So
  
  ```
  seurat@dr$pca=URD_object@pca.load
  
  > 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
  
  **Tags:** seurat, clustering, pca
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-10-24. Score: 3 | Accepted answer
  
  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 `URD_object@pca.load`.
  
  ```
  # 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 object@scale.data as input
  d <- dist(x = t(x = pbmc@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(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](https://satijalab.org/seurat/dim_reduction_vignette.html) for more.
  
  > **Comments:**
  > **username_0**: 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  
  > **username_1**: In `SetDimReduction()` replace `"mds"` with `"pca"` and `mds` with `URD_object@pca.load`.  
  > **username_0**: Thank you                                                                                                              > pbmc <- SetDimReduction(object = seuset, reduction.type = "pca", slot = "cell.embeddings",  +                         new.data = URD@pca.scores)  Show Traceback    Rerun with Debug  Error in (function (cl, name, valueClass)  :    ‘cell.embeddings’ is not a slot in class “data.frame”  >  
  > **username_1**: 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.  
  
  ---
  
  