KlugerLab / GeneTrajectory

R implementation of GeneTrajectory
https://www.nature.com/articles/s41587-024-02186-3
50 stars 9 forks source link

how to plot the label of genes in 3d plot? #7

Open feanaros opened 7 months ago

feanaros commented 7 months ago

I don't understand how to determine if a gene is in the end of trajectory, I have a list of markers of interest. they have highers pseudoorder values. ho can I see if they are at the end of the trajectory? and to which cell types they belong to?

RihaoQu commented 6 months ago

Hi, the following code might be helpful to highlight the location of specific gene markers.

#After getting the gene embedding and extracting gene trajectories
gene_labels <- paste("-----", rownames(gene_embedding))
names(gene_labels) <- rownames(gene_embedding)
genes_selected <- c("CCR2", "ICAM2", "FCGR3A",  "SELL", "C1QA", "C1QB",
                    "CD1C", "CLEC10A", "CD2", "CD72", "CCR5",
                    "PKIB", "RETN", "CLEC5A", "CSF1R") #Your genes of interest
gene_labels[names(gene_labels) %notin% genes_selected] <- ""
par(mar = c(1.5,1.5,1.5,1.5))
scatter3D(gene_embedding[,1],
          gene_embedding[,2],
          gene_embedding[,3],
          bty = "b2", colvar = as.integer(as.factor(gene_trajectory$selected))-1,
          main = "trajectory", pch = 19, cex = 1, theta = 45, phi = 0,
          col = ramp.col(c(hue_pal()(3))))
text3D(gene_embedding[,1],
       gene_embedding[,2],
       gene_embedding[,3],  labels = gene_labels,
       add = T, colkey = FALSE, cex = 0.5)

If you want to extract the full list of genes following their order along each gene trajectory, the following code might help.

gene_list <- list()
for (i in 1:3){
  message(paste0("Trajectory-", i))
  gene_trajectory_sub <- gene_trajectory[which(gene_trajectory$selected == paste0("Trajectory-", i)),]
  genes <- rownames(gene_trajectory_sub)[order(gene_trajectory_sub[, paste0("Pseudoorder", i)])]
  message(paste(rev(genes), collapse = ", "))
  gene_list[[i]] <- genes
}
feanaros commented 6 months ago

Ho! Thank you very much! Just another question Is: Is It possibile to color the trajectory by Cell types (clusterization generates by Seurat?) or Is It Just a gene ordering so It Is not possibile to extract the Cell barcode?

RihaoQu commented 6 months ago

Yes, the gene trajectories cannot be directly colored by cell types since they do not match cell barcodes. As an alternative, you can correspond each trajectory to specific cell populations based on gene bin plots over the cell embedding.