seurat-wrappers icon indicating copy to clipboard operation
seurat-wrappers copied to clipboard

Obtaining RNA velocity for the integrated Seurat object's existing UMAP Embeddings

Open rahulnutron opened this issue 3 years ago • 0 comments

Dear Seurat Team,

Thank you very much for this great tool!

I was trying to obtain RNA velocity plot for already integrated Seurat object. After many searching and trial runs, leads me to this solution. I have created this "issue", not because these is really a issue, rather I have a question and if I am right, I wanted to share this code as I noticed that many people are searching for how to do it.

My question is: my integrated object's UMAP is based on 'integrated' data, however the processing for the RunVelocity was done with SCTransform for a merged object. So when the velocity plots are showing with original Embeddings, are they compatible? or I need to provide the normalization from 'integrated' assay to calculate RNA velocity?

Regards, Rahul

############# Original ############################ Ecom.integrated <- readRDS('all_samples_integrated.rds') sample_cells_E6 <- colnames(Ecom.integrated)[Ecom.integrated$orig.ident =="E6"] sample_cells_E9 <- colnames(Ecom.integrated)[Ecom.integrated$orig.ident =="E9"] E69 <- subset(Ecom.integrated,cells =c(sample_cells_E6,sample_cells_E9)) DimPlot(E69) ## need RNA velocity for this UMAP Embeddings

################# individual loom file read ################ E6 <- ReadVelocity(file = "E6.loom") E9 <- ReadVelocity(file = "E9.loom") bm_E6 <- as.Seurat(x = E6) bm_E9 <- as.Seurat(x = E9)

ndb_S2_1 <- gsub("\E6:", "h6_",colnames(bm_E6)) ndb_S2_1 <- gsub(".{1}$", "-1_1",ndb_S2_1) bm_E6 <- RenameCells(bm_E6,new.names = ndb_S2_1)

ndb_S2_1 <- gsub("\E9:", "h9_",colnames(bm_E9)) ndb_S2_1 <- gsub(".{1}$", "-1_1",ndb_S2_1) bm_E9 <- RenameCells(bm_E9,new.names = ndb_S2_1)

head(colnames(bm_E6)) head(sample_cells_E6)

bm <- merge(bm_E6 ,bm_E9)

bm <- subset(bm, cells = colnames(E69),features = rownames(E69))

bm<- SCTransform(object = bm, assay = "spliced") bm <- RunPCA(object = bm, verbose = FALSE) bm <- FindNeighbors(object = bm, dims = 1:20) bm <- FindClusters(object = bm) bm <- RunUMAP(object = bm, dims = 1:20)

dim(bm) dim(E69)

bm <- RunVelocity(object = bm, deltaT = 1, kCells = 25, fit.quantile = 0.02) ident.colors <- (scales::hue_pal())(n = length(x = levels(x = bm))) names(x = ident.colors) <- levels(x = bm) cell.colors <- ident.colors[Idents(object = bm)] names(x = cell.colors) <- colnames(x = bm)

show.velocity.on.embedding.cor(emb = Embeddings(object = E69, reduction = "umap"), vel = Tool(object = bm, slot = "RunVelocity"), n = 200, scale = "sqrt", cell.colors = ac(x = cell.colors, alpha = 0.5), cex = 0.8, arrow.scale = 3, show.grid.flow = TRUE, min.grid.cell.mass = 0.5, grid.n = 40, arrow.lwd = 1, do.par = FALSE, cell.border.alpha = 0.1)

rahulnutron avatar Jul 22 '21 18:07 rahulnutron