kstreet13 / slingshot

Functions for identifying and characterizing continuous developmental trajectories in single-cell data.
259 stars 42 forks source link

Curves and lineages #231

Closed Ahmedalaraby20 closed 6 months ago

Ahmedalaraby20 commented 9 months ago

Hi there, Why does my getCurves plot look a bit different than my getLineages plot?

I used this snippet to get the lineages

library(slingshot)
dimred <- seuratobj@reductions$umap@cell.embeddings
clustering <- seuratobj$seurat_clusters
counts <- as.matrix(seuratobj@assays$RNA@counts[seuratobj@assays$RNA@var.features, ])
lineages <- getLineages(data = dimred,
                        clusterLabels = clustering,
                        start.clus = "6", omega = T, omega_scale = 3 ) 

with lineages@metadata$lineages returning this

$Lineage1
[1] "6" "4" "2" "1" "0"

$Lineage2
[1] "6" "4" "2" "3"

$Lineage3
[1] "6" "4" "5"

I then run getCurves

curves <- getCurves(lineages, shrink = T,  extend = "n", reweight = T,reassign = TRUE,  thresh = 0.001,maxit = 30, stretch = 0.01, approx_points = 150,  smoother = "smooth.spline", shrink.method = "cosine",  allow.breaks = F)

and I get similar results from curves@metadata$lineages but the plot looks all different. why would the curve from lineage 3 extends all the way into cluster 2 even though it should not? is there a way to make the curves more stringent?

getLineages plot

Rplot11

getCurves plot

Rplot12

Thanks

kstreet13 commented 9 months ago

Hi @Ahmedalaraby20,

Thanks for the questions. First, I'd like to ask, did you get this code from somewhere? It's very specific and makes some interesting choices regarding subtle parameters that I wouldn't generally recommend adjusting (such as omega_scale and stretch).

As for the difference between the two plots, there are a couple things going on that probably contributed to that. First is that the curve fitting process is iterative and sometimes it can get a little weird before it converges. Second is that there's a pretty big difference in the variability around lineage 3 as opposed to lineages 1 and 2. The former is much narrower, while the latter are pretty spread out. Slingshot assumes approximately equal variance along the lineages, so when that assumption is violated, it can lead to some weird results.

Best, Kelly

Ahmedalaraby20 commented 9 months ago

HI @kstreet13 , Thanks a lot for your response, I got the code from here Indeed, based on already published results Lineage3 should be shorter than the rest,

For the getLineages, I ended up using the default parameters after reading your comments

For getCurves I used the same code as before while just changing the reassign = F

curves <- getCurves(lineages, shrink = TRUE,  extend = "n", reweight = TRUE,reassign = F,  thresh = 0.001,maxit = 30, stretch = 0.01, approx_points = 150,  smoother = "smooth.spline", shrink.method = "tricube",  allow.breaks = TRUE)

However, I am sceptical now after reading your comment, when going default with the stretch the curves go haywire What would you suggest in this case? using reassign = F,stretch = 0.01 seems to be the closest to what I would expect

reassign = F,stretch = 0.01,

Rplot15

reassign = F

Rplot14

reassign = T , stretch = 0.01

Rplot16

reassign = T

Rplot17

kstreet13 commented 8 months ago

I don't really have any great suggestions other than maybe trying some different dimensionality reductions. Like I said, the main issue is that Lineages 1 and 2 have huge variance, relative to Lineage 3. There's also not much to distinguish Lineages 1 and 2 (if I was just looking at the points on these plots, I would not guess that those were separate endpoints).