kstreet13 / slingshot

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

Calculating on PCs + Plotting On UMAP #211

Closed connerlambden closed 1 year ago

connerlambden commented 1 year ago

Hi, I want to use PC space for calculating trajectories and UMAP to visualize them. However, when I visualize using UMAP, lines are being drawn where there are no cells. How should I reconcile using slingshot in these 2 different spaces? Thanks for the help.

kstreet13 commented 1 year ago

Hi @connerlambden ,

I think this is the best strategy (running Slingshot in PC space and only using UMAP for visualization), but unfortunately since UMAP is non-linear, it doesn't always produce congruent results.

One thing you could try is to re-run UMAP with slightly different parameters (or even just a different random seed) and see if it improves. Otherwise, I would just color the points on the UMAP plot by pseudotime and either forgo the lines or draw them by hand/in PowerPoint (I've seen a lot of published papers do something like this). This isn't the most satisfying solution, but it is only for visualization, and the actual pseudotime values will be derived from the PCs, anyway.

Best, Kelly

connerlambden commented 1 year ago

Thanks for the help. I'm trying the following:

umap_curve_embedding <- embedCurves(sce, newDimRed=reducedDims(sce)$UMAP) lines(SlingshotDataSet(umap_curve_embedding)@curves[[1]]$s, lwd = 2, col = 'red')

Screenshot 2023-03-13 at 6 20 16 PM

Results look super weird. Any ideas? Also, how do I do this on a per-lineage basis?

kstreet13 commented 1 year ago

Haha, I often get this type of plot myself. The issue is that the s matrix is not re-ordered, so the cells in that matrix match up with the cells in your original data. If you want to put them in order of pseudotime, there is a corresponding index you can use (SlingshotDataSet(umap_curve_embedding)@curves[[1]]$ord), but we wrote a lines function for SlingshotDataSet objects that should know how to handle this properly. If lines(SlingshotDataSet(umap_curve_embedding), lwd = 2, col = 'red') doesn't work, let me know! And you can give a vector of different colors if you don't want all lineages to be the same color.

connerlambden commented 1 year ago

Thanks that worked!