kstreet13 / slingshot

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

how to use slingshot_conditions on PCA and visualization on UMAP #255

Closed TongzhenXu closed 1 month ago

TongzhenXu commented 1 month ago

Hi! I am currently working with the slingshot algorithm on PCA data and following the Second example from bioc2021trajectories for pseudotime analysis under different conditions. I aim to visualize the skeletons plot on a UMAP plot by using the embedCurves method to transform PCA data for different conditions. However, I encountered an error when running the following R code: sce <- slingshot(sce, omega = T, dist.method = 'mnn', omega_scale = 3,

approx_points = 150,,

             clusterLabels = 'cluster_id', 
             reducedDim = 'PCA',
             extend = "n", 
             reweight = FALSE, 
             reassign = FALSE,
             start.clus = start_clusters
             #end.clus = end_clusters

) sdss <- slingshot_conditions(sce, sce$treat_group, approx_points = FALSE, extend = "n", reweight = FALSE, reassign = FALSE)

Plot skeletons

msts <- lapply(sdss, slingMST, as.df = TRUE) %>% bind_rows(.id = "treat_group") %>% arrange(treat_group)

ggplot(umap_coords, aes(x = UMAP1, y = UMAP2, col = treat_group)) + geom_point(size = .7, alpha = .1) + scale_color_brewer(palette = "Accent") + geom_point(data = msts, size = 3) + geom_path(data = msts, aes(group = interaction(Lineage, treat_group)), linewidth = 2) Error in ggplot(umap_coords, aes(x = UMAP1, y = UMAP2, col = treat_group)) : could not find function "ggplot"

Could you please advise me on how to correctly embed the PCA data from sdss into UMAP data, integrate this data into msts, and subsequently visualize it using ggplot? Any guidance on resolving the error and achieving the desired plot would be greatly appreciated.

fig

kstreet13 commented 1 month ago

Hi @TongzhenXu ,

I think you just need to load the ggplot2 library, via library(ggplot2). If you haven't installed that library, you can do so with install.packages('ggplot2').

Best, Kelly

TongzhenXu commented 1 month ago

@kstreet13 I'm sorry, I just noticed that the image I uploaded in the previous post was incorrect. Here is the correct image. My sce has two treatment groups, CRT and ICI. After using the slingshot_condition function on sce, the generated sdss object cannot use the embedCurves function to convert PCA to UMAP for visualization. However, when using the slingshot function on sce, the generated object can use the embedCurves function to convert PCA to UMAP for visualization. My goal is to convert the PCA of sdss to UMAP for visualization, but I haven't succeeded. I'm not sure which step in the process went wrong. picture

TongzhenXu commented 1 month ago

image

kstreet13 commented 1 month ago

Hi @TongzhenXu,

Ah, that makes more sense! I think the issue is the combination of inputs being a PseudotimeOrdering object and a character, because neither of these actually contain the UMAP coordinates. Rather than setting the second argument to "UMAP", try supplying the actual matrix of UMAP coordinates and I think that should work.

Best, Kelly

TongzhenXu commented 1 month ago

@kstreet13 Thank you for your advice. I have figured out this problem by the following code to separate PCA data of two different conditions into UMAP visualization and it works. So I will close this question. image