feiyoung / PRECAST

an efficient data integration method for multiple spatial transcriptomics data with non- cluster-relevant effects such as the complex batch effects.
GNU General Public License v3.0
9 stars 3 forks source link

Error when fitting PRECAST #7

Closed utule closed 1 year ago

utule commented 1 year ago

Hello author! thanks for your great work.

I encountered an error while running the command P_RECASTObj<- PRECAST (PRECASTObj, K=15): Error in idrsc2Cpp (XList, AdjList, Adjlist_car, hZ, ymat, Mu0List, Sigma0List,: inv_sympd(): matrix is singular or not positive define). Additionally, before this error occurred, a warning was issued: warning: solve(): system is singular; I am not sure why this error occurred. Could you please provide some suggestions? Thank you very much! QQ图片20230412215440

feiyoung commented 1 year ago

It is not easy to judge why this error happens since the function PRECAST() is a high-level function. You can try this function ICM.EM() in PRECAST package by taking out the components from PRECASTObj. For example:

  1. take out adjacence matrix list. AdjList <- PRECASTObj@AdjList
  2. take out the log-normalized data from seulist. If your default assay is RNA, use the following code. XList <- lapply(PRECASTObj@seulist, function(x) Matrix::t(x[['RNA']]@ data)) If not, use XList <- list() for(i in seq_along(PRECASTObj@seulist)){ message("i=", i) seu <- PRECASTObj@seulist[[i]] defassy <- DefaultAssay(seu) XList[[i]] <- Matrix::t(seu[[defassy]]@ data) } XList[[1]][1:4,1:5] ## check the values hq <- 15; hK <- 15 ## ICM.EM is the low-level interface for PRECAST algorithm. resList <- ICM.EM(XList, q=hq, K=hK, AdjList= AdjList, platform = "Other_SRT" ,maxIter = 30, Sigma_equal =F, coreNum=1)

3.If the above command still produce error, you can try using a more strict filtering rule. For example, set premin.spots=40; premin.features=40. Then rerun your original code and the above command.

set.seed(2022) PRECASTObj <- CreatePRECASTObject(bc2, project = "BC2", gene.number = 2000, selectGenesMethod = "SPARK-X", premin.spots = 40, premin.features = 40, postmin.spots = 1, postmin.features = 10)

Hope this can help you.

utule commented 1 year ago

I will try your suggestions, thanks for your kind help!