edward130603 / BayesSpace

Bayesian model for clustering and enhancing the resolution of spatial gene expression experiments.
http://edward130603.github.io/BayesSpace
Other
106 stars 21 forks source link

Error in cluster.FUN(Y = as.matrix(Y), df_j = df_j, nrep = nrep, n = n, : Mat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD #75

Open xyn0813 opened 2 years ago

xyn0813 commented 2 years ago

I got this error when run spatialCluster: Error in cluster.FUN(Y = as.matrix(Y), df_j = df_j, nrep = nrep, n = n, : Mat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD how to fix it ? is my object too large ?

edward130603 commented 2 years ago

How many spots is the dataset you are working with? And how many iterations are you using?

xyn0813 commented 2 years ago

About 110,000 spots, and I set nrep=50000

edward130603 commented 2 years ago

Ok, yeah unfortunately the armadillo c++ library has some limitations on the size of matrices. One workaround is to just lower the number of iterations. If you think the results haven't converged yet, you can run it again, using the last iteration of the previous mcmcChain to initialize. Example:

sce = spatialCluster(sce, save.chain = TRUE, nrep = 10000, ...)
new_init = mcmcChain(sce, "z)[10000,]
sce2 = spatialCluster(sce, save.chain = TRUE, nrep = 10000, init = new_init, ...)
new_init2 = mcmcChain(sce2, "z)[10000,]
sce3 = spatialCluster(sce, save.chain = TRUE, nrep = 10000, init = new_init2, ...)
#etc 

Unfortunately a bit tedious to do this but I don't have a better solution at the moment.

xyn0813 commented 2 years ago

I reduced the number of iterations and it worked. but I notice that I got the message : Neighbors were identified for 0 out of xxx spots. This message only shows up in certain samples, In most cases, I got messages like this : Neighbors were identified for xxx out of xxx spots. Is there something wrong?

edward130603 commented 2 years ago

It seems like the neighbor finding didn't work in that case. Do you have Visium data? Did you load it in using BayesSpace's readVisium function? If not, make sure you have both the array coordinates (row and col) and the pixel locations (imagerow and imagecol) in colData. The locations are stored in "tissue_positions_list.csv": https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/images

madhavitippani commented 2 years ago

Hello,

I had this same issue and lowered the iterations from 50000 to 25000 and ran it twice using the last iteration of the previous mcmcChain (Note: My SPE object has 135640 spots). It ran for a while and threw the following error. CODE message("Running spatialCluster()") Sys.time() set.seed(12345) spe2 <- spatialCluster(spe, use.dimred = "HARMONY", q = k, platform = "Visium", save.chain = TRUE, nrep = 25000) new_init = mcmcChain(spe2, z)[10000,] spe <- spatialCluster(spe2, use.dimred = "HARMONY", q = k, platform = "Visium", save.chain = TRUE, nrep = 25000, init = new_init) Sys.time()

ERROR Running spatialCluster() [1] "2022-06-28 13:00:43 EDT" Neighbors were identified for 135612 out of 135640 spots. Fitting model... Error: cannot allocate vector of size 25.3 Gb Execution halted

edward130603 commented 2 years ago

I'm assuming you are running this on a HPC or other high memory machine. Are you able to allocate more memory to the job?

madhavitippani commented 2 years ago

Yes, it's on HPC with 100GB.

edward130603 commented 2 years ago

I don't think I have any other solution unfortunately besides allocating more memory and/or further reducing your # of iterations.

panyuwen commented 1 week ago

It seems like the neighbor finding didn't work in that case. Do you have Visium data? Did you load it in using BayesSpace's readVisium function? If not, make sure you have both the array coordinates (row and col) and the pixel locations (imagerow and imagecol) in colData. The locations are stored in "tissue_positions_list.csv": https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/images

I got the same message "Neighbors were identified for 0 out of 116932 spots." It's visium HD data. I'm sure I have the array coordinates in the colData. Do you have any other suggestions?