kstreet13 / slingshot

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

error when trying to overlay the lineage trajectory on umap #194

Closed Y-CBob closed 2 years ago

Y-CBob commented 2 years ago

I extracted the relevant info from my Seurat object:

dimred <- seurat.object@reductions$umap@cell.embeddings
clustering <- seurat.obect$SCT_snn_res.0.35
counts <- as.matrix(seurat.object@assays$RNA@counts)

and performed the trajectory mapping:

lineages <- getLineages(data = dimred, clusterLabels = clustering)
pal <- c(RColorBrewer::brewer.pal(9, "Set1"), RColorBrewer::brewer.pal(8, "Set2"))
par(mfrow = c(1, 2))
plot(dimred[, 1:2], col = pal[clustering], cex = 0.5, pch = 16)
for (i in levels(clustering)) {
  text(mean(dimred[clustering == i, 1]), mean(dimred[clustering == i, 2]), labels = i, font = 2)
}
plot(dimred[, 1:2], col = pal[clustering], cex = 0.5, pch = 16)
lines(lineages, lwd = 3, col = "black")

Error came out when running the last line of code:

Error in as.vector(x, mode = "numeric") : 
  no method for coercing this S4 class to a vector

On my plot viewer, I am able to see the 2 umap colored according to clusters, one on the left with cluster numbers while the one on the right does not have any label on it.

kstreet13 commented 2 years ago

Hi @Y-CBob,

I am guessing that this is because lineages is a PseudotimeOrdering object and the plotting functions expect a SlingshotDataSet object. Can you try replacing the last line with lines(SlingshotDataSet(lineages), lwd = 3, col = "black")?

Let me know if that doesn't work! Best, Kelly

Y-CBob commented 2 years ago

OMG It worked! Thank you sooo much Kelly!!!

Best, Bob