const-ae / lemur

Latent Embedding Multivariate Regression
https://www.bioconductor.org/packages/lemur/
Other
80 stars 7 forks source link

Error in grassmann_lm #16

Closed nandobonf closed 1 month ago

nandobonf commented 1 month ago

Hi, thanks for this very useful tool. I am trying to run lemur on my dataset (snRNAseq of 10 tumor samples before and after chemotherapy) but when I run the command: fit <- lemur(my_sce, design = ~ sample + chemio, n_embedding = 15, test_fraction = 0.5) I get:

Storing 50% of the data (6326 cells) as test data. Regress out global effects using linear method. Find base point for differential embedding Fit differential embedding model Initial error: 1.62e+07 ---Fit Grassmann linear model Error in grassmann_lm(Y_clean, design = design_matrix, base_point = base_point) : Too few datapoints in some design matrix group. This error could be removed, but this feature hasn't been implemented yet.

How could I fix this? I tried to increase the number of cells but it only works if I remove the "sample" covariate.

const-ae commented 1 month ago

Hi Ferdinando,

thanks for reaching out and sorry that you ran into this slightly obtuse error message.

Could you please post the output of the following R snippet:

colData(my_sce) %>%
  as_tibble() %>%
  dplyr::count(sample, chemio)

The snippet will count all combinations of sample and chemio in your data. Each combination will have to be larger than 15.

Best, Constantin

nandobonf commented 1 month ago

Hi Constantin, thanks for the swift reply. No problem at all, I'm happy if I can be useful to improve the tool, which is already well documented.

In the meantime I figured out by myself that one sample had very few "chemio" cells and after removing it it worked nicely. Now, instead I get a different error message when running: fit <- align_harmony(fit) which throws:

Select cells that are considered close with 'harmony' Error: Expecting a single value: [extent=2].

Hoped this was also something quick to fix but didnt manage to get through so far. Thanks again for the help.

const-ae commented 1 month ago

In the meantime I figured out by myself that one sample had very few "chemio" cells and after removing it it worked nicely.

That's great.

Now, instead I get a different error message when running: fit <- align_harmony(fit) which throws

Oh, that sounds a bit like a version problem with harmony. You can check that by running packageVersion("harmony"). This should be 1.2.0. There were some breaking changes in the last year, which made it a bit tricky to call across, but with the latest version, it should be fine.

nandobonf commented 1 month ago

Yes, it is v1.2.0, I think it is correct, also because I installed lemur with all dependencies from conda in a new environment.

const-ae commented 1 month ago

Okay, and which version of lemur do you use? Could you please post the output of sessionInfo()? That will help me debug the problem :)

nandobonf commented 1 month ago

Sure, thanks again for the help!

sessionInfo() R version 4.3.3 (2024-02-29) Platform: x86_64-conda-linux-gnu (64-bit) Running under: CentOS Stream 8

Matrix products: default BLAS/LAPACK: /mnt/ngs/miniconda3/envs/seurat_copykat/lib/libopenblasp-r0.3.27.so; LAPACK version 3.12.0

locale: [1] LC_CTYPE=it_IT.UTF-8 LC_NUMERIC=C
[3] LC_TIME=it_IT.UTF-8 LC_COLLATE=it_IT.UTF-8
[5] LC_MONETARY=it_IT.UTF-8 LC_MESSAGES=it_IT.UTF-8
[7] LC_PAPER=it_IT.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=it_IT.UTF-8 LC_IDENTIFICATION=C

time zone: Europe/Rome tzcode source: system (glibc)

attached base packages: [1] stats4 stats graphics grDevices utils datasets methods
[8] base

other attached packages: [1] Seurat_5.1.0 SeuratObject_5.0.2
[3] sp_2.1-4 tidyr_1.3.1
[5] SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0 [7] Biobase_2.62.0 GenomicRanges_1.54.1
[9] GenomeInfoDb_1.38.1 IRanges_2.36.0
[11] S4Vectors_0.40.2 BiocGenerics_0.48.1
[13] MatrixGenerics_1.14.0 matrixStats_1.3.0
[15] lemur_1.0.4

loaded via a namespace (and not attached): [1] RColorBrewer_1.1-3 jsonlite_1.8.8
[3] magrittr_2.0.3 spatstat.utils_3.0-5
[5] farver_2.1.2 zlibbioc_1.48.0
[7] vctrs_0.6.5 ROCR_1.0-11
[9] DelayedMatrixStats_1.24.0 spatstat.explore_3.3-1
[11] RCurl_1.98-1.16 htmltools_0.5.8.1
[13] S4Arrays_1.2.0 SparseArray_1.2.2
[15] sctransform_0.4.1 parallelly_1.38.0
[17] KernSmooth_2.23-24 htmlwidgets_1.6.4
[19] ica_1.0-3 plyr_1.8.9
[21] plotly_4.10.4 zoo_1.8-12
[23] igraph_2.0.3 mime_0.12
[25] lifecycle_1.0.4 pkgconfig_2.0.3
[27] Matrix_1.6-5 R6_2.5.1
[29] fastmap_1.2.0 GenomeInfoDbData_1.2.11
[31] fitdistrplus_1.2-1 future_1.34.0
[33] shiny_1.9.1 digest_0.6.36
[35] colorspace_2.1-1 patchwork_1.2.0
[37] tensor_1.5 RSpectra_0.16-2
[39] irlba_2.3.5.1 beachmat_2.18.0
[41] labeling_0.4.3 progressr_0.14.0
[43] fansi_1.0.6 spatstat.sparse_3.1-0
[45] httr_1.4.7 polyclip_1.10-7
[47] abind_1.4-5 compiler_4.3.3
[49] withr_3.0.1 BiocParallel_1.36.0
[51] fastDummies_1.7.3 MASS_7.3-60.0.1
[53] DelayedArray_0.28.0 tools_4.3.3
[55] lmtest_0.9-40 httpuv_1.6.15
[57] future.apply_1.11.2 goftest_1.2-3
[59] glmGamPoi_1.14.0 glue_1.7.0
[61] nlme_3.1-165 promises_1.3.0
[63] grid_4.3.3 Rtsne_0.17
[65] cluster_2.1.6 reshape2_1.4.4
[67] generics_0.1.3 gtable_0.3.5
[69] spatstat.data_3.1-2 data.table_1.15.4
[71] utf8_1.2.4 XVector_0.42.0
[73] spatstat.geom_3.3-2 RcppAnnoy_0.0.22
[75] ggrepel_0.9.5 RANN_2.6.1
[77] pillar_1.9.0 stringr_1.5.1
[79] spam_2.10-0 RcppHNSW_0.6.0
[81] later_1.3.2 splines_4.3.3
[83] dplyr_1.1.4 lattice_0.22-6
[85] survival_3.7-0 deldir_2.0-4
[87] tidyselect_1.2.1 scuttle_1.10.3
[89] miniUI_0.1.1.1 pbapply_1.7-2
[91] gridExtra_2.3 scattermore_1.2
[93] RhpcBLASctl_0.23-42 stringi_1.8.4
[95] lazyeval_0.2.2 codetools_0.2-20
[97] tibble_3.2.1 cli_3.6.3
[99] uwot_0.2.2 xtable_1.8-4
[101] reticulate_1.38.0 munsell_0.5.1
[103] harmony_1.2.0 Rcpp_1.0.13
[105] globals_0.16.3 spatstat.random_3.3-1
[107] png_0.1-8 spatstat.univar_3.0-0
[109] parallel_4.3.3 ggplot2_3.5.1
[111] dotCall64_1.1-1 sparseMatrixStats_1.14.0 [113] bitops_1.0-8 listenv_0.9.1
[115] viridisLite_0.4.2 scales_1.3.0
[117] ggridges_0.5.6 leiden_0.4.3.1
[119] purrr_1.0.2 crayon_1.5.3
[121] rlang_1.1.4 cowplot_1.1.3

const-ae commented 1 month ago

Ah, I see the problem. You are using lemur version 1.0.4. I fixed the incompatibility with harmony 1.2.0 in December in version 1.0.5 (https://github.com/const-ae/lemur/commits/RELEASE_3_18/). You can update lemur by running BiocManager::install("lemur").

nandobonf commented 1 month ago

Thanks for the help! It works fine now.

const-ae commented 1 month ago

That's great. Happy that I could help :)