kstreet13 / slingshot

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

Error plotting the trajectory #201

Closed emanuelavilla closed 1 year ago

emanuelavilla commented 1 year ago

Hello!

I am currently using the package to build a trajectory on my integrated Seurat data. Until recently, everything worked perfectly. But for some time now, I get an error that I cannot fully understand.

The code I am using is:

_sds <- slingshot(Embeddings(seu, "umap"), clusterLabels = seu$celltype, start.clus = 'Imm', stretch = 0)

cell_pal <- function(cell_vars, pal_fun,...) { if (is.numeric(cell_vars)) { pal <- pal_fun(100, ...) return(pal[cut(cell_vars, breaks = 100)]) } else { categories <- sort(unique(cell_vars)) pal <- setNames(pal_fun(length(categories), ...), categories) return(pal[cell_vars]) } }

cell_colors <- cell_pal(seu$celltype, brewer_pal("qual", "Set2")) cell_colors_clust <- cell_pal(seu$celltype, hue_pal())

plot(reducedDim(sds), col = cell_colors, pch = 16, cex = 0.5) lines(sds, lwd = 2, type = 'lineages', col = 'black')

plot(reducedDim(sds), col = cell_colorsclust, pch = 16, cex = 0.5) lines(sds, lwd = 2, type = 'lineages', col = 'black')

However, when I try to plot the trajectory (both the plot commands), I get the error:

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'plot': unable to find an inherited method for function ‘reducedDim’ for signature ‘"PseudotimeOrdering", "missing"’

Any suggestion?

Thanks

kstreet13 commented 1 year ago

Hi @emanuelavilla,

Thanks for bringing this to my attention! I'm pretty sure the issue here is that your sds object is actually a PseudotimeOrdering object, not a SlingshotDataSet (as the name implies). Replacing reducedDim(sds) with cellData(sds)$reducedDim should resolve the issue.

And for what it's worth, you might have better luck following the slingshot vignette, which is kept up to date (other people have also had issues with this same code you're using).

Best, Kelly

emanuelavilla commented 1 year ago

Thanks, Kelly for helping me! It worked!