Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime of getting UMAP reductions #18

Open
mohit1997 opened this issue May 4, 2020 · 4 comments
Open

Runtime of getting UMAP reductions #18

mohit1997 opened this issue May 4, 2020 · 4 comments

Comments

@mohit1997
Copy link

mohit1997 commented May 4, 2020

I am trying to run scRNA_01_Clustering_UMAP_v1.R, and apparently the function optimizeLSI is iterative. The code shows that each iteration take 30 seconds and the maximum number of iterations is 3000. Am I doing something wrong or is it supposed to be this slow?

@jgranja24
Copy link
Contributor

This was a bug my mistake

I updated it to this

nTop <- c(3000, 3000, 3000) #Choose a higher number of variable peaks

Best

Jeff

@mohit1997
Copy link
Author

mohit1997 commented May 5, 2020

Works like charm! Thanks a lot.
A few more suggestions, I encountered an error while calling metadata(se)
Instead calling se@metadata works fine. (Note: I am new to R and might be missing something obvious here, but this worked for me.)
So after optimizeLSI, we can replace the rest of the lines with the following code. Also edited the third line which was using lsi instead of lsiObj.

se@metadata$optimizeLSI <- lsiObj
se@metadata$matSVD <- lsiObj[[length(lsiObj)]][[1]][[1]] #Last one
se@metadata$variableGenes <- rownames(se)[lsiObj[[length(lsiObj)]]$varFeatures] #Variable genes

####################################################
#For Creating UMAP Start Here
####################################################
matSVD <- se@metadata$matSVD
clusters <- colData(se)$Clusters

#Set Seed and perform UMAP on LSI-SVD Matrix
set.seed(1)
uwotUmap <- uwot::umap(
  matSVD, 
  n_neighbors = 35, 
  min_dist = 0.45, 
  metric = "euclidean", 
  n_threads = 1, 
  verbose = TRUE, 
  ret_nn = TRUE,
  ret_model = TRUE
)

pdf("Plot_UMAP-NN-35-MD-45.pdf", width = 12, height = 12, useDingbats = FALSE)
df <- data.frame(
  x = uwotUmap[[1]][,1],
  y = -uwotUmap[[1]][,2], 
  color = clusters
)
ggplot(df,aes(x,y,color=color)) + 
  geom_point() + 
  theme_bw() + 
  scale_color_manual(values=se@metadata$colorMap$Clusters) +
  xlab("UMAP Dimension 1") + 
  ylab("UMAP Dimension 2")
dev.off()

@pbrazda
Copy link

pbrazda commented Sep 14, 2020

Hi @mohit1997 ,
Thanks for opening this issue! ;)
Do you have any suggestions on this topic, maybe?:

I am trying to replicate 'scRNA_02_Cluster_Disease_w_Reference_v1.R' .
However, in "Project Into LSI UMAP", line366, for
umapProjection <- uwot::umap_transform(as.matrix(lsiProjection$matSVD)[,1:25], umapManifold, verbose = TRUE)
I get an error:
Error in lsiProjection$matSVD : $ operator not defined for this S4 class

(for
umapProjection <- uwot::umap_transform(as.matrix(lsiProjection@matSVD)[,1:25], umapManifold, verbose = TRUE) :

Error in as.matrix(lsiProjection@matSVD) : 
  no slot of name "matSVD" for this object of class "dgeMatrix"

)

Thanks!

@MugenQin
Copy link

Hi,

Works like charm! Thanks a lot. A few more suggestions, I encountered an error while calling metadata(se) Instead calling se@metadata works fine. (Note: I am new to R and might be missing something obvious here, but this worked for me.) So after optimizeLSI, we can replace the rest of the lines with the following code. Also edited the third line which was using lsi instead of lsiObj.

se@metadata$optimizeLSI <- lsiObj
se@metadata$matSVD <- lsiObj[[length(lsiObj)]][[1]][[1]] #Last one
se@metadata$variableGenes <- rownames(se)[lsiObj[[length(lsiObj)]]$varFeatures] #Variable genes

####################################################
#For Creating UMAP Start Here
####################################################
matSVD <- se@metadata$matSVD
clusters <- colData(se)$Clusters

#Set Seed and perform UMAP on LSI-SVD Matrix
set.seed(1)
uwotUmap <- uwot::umap(
  matSVD, 
  n_neighbors = 35, 
  min_dist = 0.45, 
  metric = "euclidean", 
  n_threads = 1, 
  verbose = TRUE, 
  ret_nn = TRUE,
  ret_model = TRUE
)

pdf("Plot_UMAP-NN-35-MD-45.pdf", width = 12, height = 12, useDingbats = FALSE)
df <- data.frame(
  x = uwotUmap[[1]][,1],
  y = -uwotUmap[[1]][,2], 
  color = clusters
)
ggplot(df,aes(x,y,color=color)) + 
  geom_point() + 
  theme_bw() + 
  scale_color_manual(values=se@metadata$colorMap$Clusters) +
  xlab("UMAP Dimension 1") + 
  ylab("UMAP Dimension 2")
dev.off()

Hi @mohit1997 ,
I had the same problem with you that I got error when I run metadata, then I tried se@metadata, but I got another error when I run the following codes:
[email protected]$optimizeLSI <- lsiObj
[email protected]$matSVD <- lsiObj[[length(lsiObj)]][[1]][[1]] #Last one
[email protected]$variableGenes <- rownames(se)[lsiObj[[length(lsiObj)]]$varFeatures] #Variable genes
and I got these errores respectively:
Error in $<-.data.frame(tmp, optimizeLSI, value = list(iter1 = list( : replacement has 3 rows, data has 3434 Error in $<-.data.frame(tmp, variableGenes, value = c("IGLV2-14", : replacement has 3000 rows, data has 3434

How do you think about these errors?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants