kstreet13 / slingshot

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

Trajectories with multiple starting clusters #190

Closed SirKuikka closed 1 year ago

SirKuikka commented 2 years ago

Hi,

Is it possible to create trajectories (converging) using Slingshot that have two or more start points. Judging from the R package documentation it looks like it could be possible

start.clus
(optional) character, indicates the starting cluster(s) from which lineages will be drawn.

But when I actually run Slingshot with multiple start clusters, the tool ignores the second start cluster.

sds <- slingshot( rd, labels, shrink = 1, reweight = TRUE, reassign = TRUE, thresh = 0.001, maxit = 10, stretch = 2, smoother = "smooth.spline", shrink.method = "cosine", dist.method="slingshot",start.clus=c(2,4) )

I get the following lineages.

lineages <- slingLineages(sds) lineages $Lineage1 [1] "2" "3" "8" "1" "9" "7"`

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

$Lineage3 [1] "2" "3" "8" "5"

And the Slingshot parameters look like this

slingParams(sds) $start.clus [1] "2"

$end.clus [1] "7" "4" "5"

So the tool actually just ignored the second start cluster (4).

kstreet13 commented 2 years ago

Hi @SirKuikka,

This is a good question and I will admit that the documentation is a little unclear. Your assessment of Slingshot's behavior is correct and the general rule is that it can only handle one starting cluster per connected component of the cluster-based graph. Put another way, if all the clusters are connected in a single MST, then Slingshot will only accept one starting cluster. If there are multiple, disconnected trees resulting from the use omega, then it can use one starting cluster per tree.

However, you can get around this in certain situations. If your trajectory only contains converging lineages (not a combination of converging and diverging), then you can actually specify the terminal cluster as start.clus. This will build a "reversed" trajectory, from the terminal cluster to the starting clusters. If you flip the sign of the resulting pseudotime values, you will get a valid result (you may also add a constant, if you want them to be positive, since pseudotime units are arbitrary, anyway).

Unfortunately, Slingshot cannot handle more complicated trajectories where lineages alternately converge and diverge.

Hope this helps! Kelly

SirKuikka commented 2 years ago

Great! Thanks for the super fast response. So let me just get this clear. Diverging means e.g. bifurcating, multifurcating, etc.? Non-diverging means linear?

kstreet13 commented 2 years ago

That is what I meant by "diverging", yes. I suppose "non-diverging" could mean any number of things, including linear, converging, cyclical, etc.

SirKuikka commented 2 years ago

Hi,

I myself understood that convergence means a bifurcating, multifurcating or other tree-shaped non-linear trajectory that has at least two starting points. Please see this illustration from a paper " TinGa: fast and flexible trajectory inference with Growing Neural Gas".

https://academic.oup.com/view-large/figure/205480453/btaa463f2.tif

So I'm still a bit confused. I thought that a trajectory can be diverging (e.g. bifurcating) and also be converging, like the example in the Figure.

EDIT: Well in the text it says that converging just means bifurcating with two start points. But wouldn't the same be possible with any tree-shaped, non-linear trajectory? Are you aware of any trajectory inference tool that generate such trajectories?

kstreet13 commented 2 years ago

I thought that a trajectory can be diverging (e.g. bifurcating) and also be converging, like the example in the Figure.

Which example in the figure are you referring to? The examples of "bifurcation" and "convergence" seem pretty clear and distinct.

I'm not sure what you are asking, but Slingshot can handle arbitrary tree-shaped trajectories, so long as there is a single root node and all edges either flow into (converging) or out of (diverging) it. With respect to the figure, this would encompass the "linear", "bifurcation", "tree", "convergence", "disconnected_graph", and "multifurcation" scenarios.

SirKuikka commented 2 years ago

I think I get it know. Slingshot can handle a trajectory as long as there is a single root node, diverging or converging. But it can't handle a trajectory that has two root nodes. For example, if I had a trajectory like the one below, but edge M3->M2 would be reversed M2->M3. I was trying to generate a trajectory that looked like this. And I assumed that any trajectory that had at least two root nodes (or more) like this one is converging based on the Figure in the manuscript. I thought that the converging trajectory in the manuscript Figure had two root nodes, but it had only one. image

kstreet13 commented 2 years ago

Yeah, I think you've got it. In the scenario you described (where M2->M3), there would be both convergence and divergence, which is not something Slingshot can handle.