<p>If <code>fit$ord</code> gives you the order of cells on the curve, you should be able to obtain the first and last cells by doing the following:</p>

<pre><code>first_cell_index &lt;- which.min(fit<span class="math-container">$ord)
last_cell_index &lt;- which.max(fit$</span>ord)
</code></pre>

<p>However, I'm not sure this is so informative - if you're looking to get representative gene expression for the start and end of the curve, you should really be looking at the cluster of cells towards the start and end of the curve - for example, by comparing cells in clusters 1 and 3 that you showed in your first plot. A single cell will suffer from dropout and not tell you a lot about the cluster.</p>

CC BY-SA 4.0
2018-10-22T14:41:38.177Z
Thank you, fit$lambda gives me pseudotime amount; Now I want to have a violin plot for lambda for each cell and each cluster
Zizogolu
CC BY-SA 4.0
2018-10-21T19:38:24.553Z
2018-10-21T19:38:24.553Z
Scott Gigante
<p>I returned a Seurat object with a diffusion map by </p>

<pre><code> seurat_object &lt;- RunDiffusion(seurat_object,genes.use = seurat_object@var.genes)
</code></pre>

<p>as below</p>

<p><a href="https://i.sstatic.net/NXIKG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NXIKG.png" alt="enter image description here"></a></p>

<p>Now, how I could know the order of a cell's projection onto this principal curve representing its predicted progression through the development by fitting a principal curve on my diffusion map?</p>

<p>I know Seurat slot for DM1 and DM2 is inside the seurat@dr </p>

<p>by </p>

<pre><code>fit=principal_curve(as.matrix(seurat_object@dr$dm@cell.embeddings))
plot(fit)
line(fit)
points(fit)
</code></pre>

<p>I draw this graph of my cells</p>

<p><a href="https://i.sstatic.net/NB26l.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NB26l.jpg" alt="enter image description here"></a></p>

<p>But how I know the first and last cells on curve? I mean how I know cells from each cluster is being placed where on the curve? By <code>fit$ord</code> I will obtain orders of cells on the line but how I know the first and end of the line?????</p>

<r><scrnaseq><seurat>
Fitting a principal curve into a diffusion map
# Fitting a principal curve into a diffusion map

(Asked by: username_0 on 2018-08-28)

I returned a Seurat object with a diffusion map by 
 seurat_object <- RunDiffusion(seurat_object,genes.use = seurat_object@var.genes)

as below

Now, how I could know the order of a cell's projection onto this principal curve representing its predicted progression through the development by fitting a principal curve on my diffusion map?
I know Seurat slot for DM1 and DM2 is inside the seurat@dr 
by 
fit=principal_curve(as.matrix(seurat_object@dr$dm@cell.embeddings))
plot(fit)
line(fit)
points(fit)

I draw this graph of my cells

But how I know the first and last cells on curve? I mean how I know cells from each cluster is being placed where on the curve? By fit$ord I will obtain orders of cells on the line but how I know the first and end of the line?????

**Tags:** r, scrnaseq, seurat

---

## 1 answers

### Answer by username_1 on 2018-10-21. Score: 1

If fit$ord gives you the order of cells on the curve, you should be able to obtain the first and last cells by doing the following:
first_cell_index <- which.min(fit$ord)
last_cell_index <- which.max(fit$ord)

However, I'm not sure this is so informative - if you're looking to get representative gene expression for the start and end of the curve, you should really be looking at the cluster of cells towards the start and end of the curve - for example, by comparing cells in clusters 1 and 3 that you showed in your first plot. A single cell will suffer from dropout and not tell you a lot about the cluster.

> **Comments:**
> **username_0**: Thank you, fit$lambda gives me pseudotime amount; Now I want to have a violin plot for lambda for each cell and each cluster  

---

