shangll123 / SpatialPCA

Spatially aware dimension reduction for spatial transcriptomics.
40 stars 9 forks source link

Error in t.default(PCvalues) : argument is not a matrix #7

Closed marvinquiet closed 1 year ago

marvinquiet commented 1 year ago

Hi Lulu,

Thanks for developing such as great method! From my user experience, spatialPCA is very robust, efficient, and accurate.

When running spatialPCA on my data (with a large sample size), I followed the tutorial of slideseq. In clusterlabel = louvain_clustering(clusternum=8,latent_dat=object@SpatialPCs,knearest=round(sqrt(dim(object@SpatialPCs)[2])) ), I encountered an error Error in t.default(PCvalues):argument is not a matrix.

I went over the function and noticed that PCvalues, which is equivalent to object@SpatialPCs is not a matrix but a dgeMatrix. https://github.com/shangll123/SpatialPCA/blob/9d96c32ef65976a16b80a1697ba8879cb3929121/R/SpatialPCA_utilties.R#L68

Therefore, a potential workaround is to pass as.matrix(object@SpatialPCs) to the clustering function and problem will be solved.

clusterlabel = louvain_clustering(clusternum=8,latent_dat=as.matrix(object@SpatialPCs),knearest=round(sqrt(dim(object@SpatialPCs)[2])) )

In case other people also encounter this issue, I decided to post it here. Please feel free to close the issue as this is a simple resolution and does not affect the overall procedure.

Sincerely, Wenjing

shangll123 commented 1 year ago

Thank you very much Wenjing! I just updated the package and the output from SpatialPCA_SpatialPCs, the object@SpatialPCs, is now a regular matrix instead of a dgeMatrix. Please feel free to let me know if you find any other questions, thanks!

Best, Lulu