kstreet13 / slingshot

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

How to plot the pseudotime for all lineages together in one UMAP plot? #209

Closed xx789 closed 1 year ago

xx789 commented 1 year ago

Hi,

Slingshot is great for my data!

I am following the tutorial below to plot the pseudotime. However, it can only show pseudotime one lineage per plot. How can I modify the code to show pseudotime of all lineages in one UMAP plot? I tried "slingAvgPseudotime" function, it does not work anymore, with error: could not find function "slingAvgPseudotime"

Thanks!

https://bustools.github.io/BUS_notebooks_R/slingshot.html#slingshot

################ nc <- 3 pt <- slingPseudotime(sds) nms <- colnames(pt) nr <- ceiling(length(nms)/nc) pal <- viridis(100, end = 0.95) par(mfrow = c(nr, nc)) for (i in nms) { colors <- pal[cut(pt[,i], breaks = 100)] plot(reducedDim(sds), col = colors, pch = 16, cex = 0.5, main = i) lines(sds, lwd = 2, col = 'black', type = 'lineages') } #################

kstreet13 commented 1 year ago

Hi @xx789 ,

What version of Slingshot do you have? slingAvgPseudotime was added a while ago, so any recent version of the package should have it.

Also, the official Slingshot vignette can be found on Bioconductor: https://www.bioconductor.org/packages/release/bioc/vignettes/slingshot/inst/doc/vignette.html

Best, Kelly

xx789 commented 1 year ago

Hi, Kelly

Thanks for your speedy response! I installed '1.8.0'.

Per my previous question, how do I modify the codes (copied below again) to show pseudotime of all lineages merged in one UMAP plot?

################ nc <- 3 pt <- slingPseudotime(sds) nms <- colnames(pt) nr <- ceiling(length(nms)/nc) pal <- viridis(100, end = 0.95) par(mfrow = c(nr, nc)) for (i in nms) { colors <- pal[cut(pt[,i], breaks = 100)] plot(reducedDim(sds), col = colors, pch = 16, cex = 0.5, main = i) lines(sds, lwd = 2, col = 'black', type = 'lineages') } #################

You can see these current codes can only show pseudotime one lineage per plot. I want all lineages merged in one plot.

image

kstreet13 commented 1 year ago

Hi @xx789,

Thanks for the update. The current version of Slingshot is 2.6.0, so I would recommend installing the latest version from Bioconductor, which should give you access to the slingAvgPseudotime function. That function will produce a single vector of pseudotimes that should suit your needs.

I'm not certain (because it's not my code), but If you want to keep the same style of plot, I think something like this should work:

pt <- slingAvgPseudotime(sds)
pal <- viridis(100, end = 0.95)
colors <- pal[cut(pt, breaks = 100)]
plot(reducedDim(sds), col = colors, pch = 16, cex = 0.5)
lines(sds, lwd = 2, col = 'black', type = 'lineages')