MarioniLab / miloR

R package implementation of Milo for testing for differential abundance in KNN graphs
https://bioconductor.org/packages/release/bioc/html/miloR.html
GNU General Public License v3.0
342 stars 22 forks source link

Error running testNhoods from Tutorial #234

Closed gt7901b closed 2 years ago

gt7901b commented 2 years ago

Describe the bug while running tutorial code da_results <- testNhoods(traj_milo, design = ~ Condition, design.df = traj_design) I got this error

Error in testNhoods(traj_milo, design = ~Condition, design.df = traj_design): Sample names in design matrix and nhood counts are not matched. Set appropriate rownames in design matrix. Traceback:

  1. testNhoods(traj_milo, design = ~Condition, design.df = traj_design)
  2. stop("Sample names in design matrix and nhood counts are not matched.\n Set appropriate rownames in design matrix.")

Minimum code example Minimum example to reproduce the error

 your code

da_results <- testNhoods(traj_milo, design = ~ Condition, design.df = traj_design)

Full error traceback

## the error

Session info Output of sessionInfo() R version 4.1.1 (2021-08-10) Platform: x86_64-conda-linux-gnu (64-bit) Running under: CentOS Linux 7 (Core)

Matrix products: default BLAS/LAPACK: /data/miniconda3/envs/R_4.1.x/lib/libopenblasp-r0.3.18.so

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

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

other attached packages: [1] patchwork_1.1.1 dplyr_1.0.7
[3] scater_1.22.0 ggplot2_3.3.5
[5] scuttle_1.4.0 miloR_1.2.0
[7] edgeR_3.36.0 limma_3.48.3
[9] SingleCellExperiment_1.16.0 SummarizedExperiment_1.24.0 [11] Biobase_2.54.0 GenomicRanges_1.46.1
[13] GenomeInfoDb_1.30.1 IRanges_2.28.0
[15] S4Vectors_0.32.4 BiocGenerics_0.40.0
[17] MatrixGenerics_1.6.0 matrixStats_0.61.0

MikeDMorgan commented 2 years ago

Please update to the latest version of Milo (v1.5) - available through Bioconductor: BiocManager::install("miloR")

gt7901b commented 2 years ago

Hi, @MikeDMorgan , I used the BiocManager::install("miloR") but still only got miloR 1.4 and the same error persists.

R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.5

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages: [1] sp_1.5-0 SeuratObject_4.1.1 Seurat_4.1.1 patchwork_1.1.2
[5] dplyr_1.0.10 scater_1.24.0 ggplot2_3.3.6 scuttle_1.6.3
[9] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.1 Biobase_2.56.0 GenomicRanges_1.48.0
[13] GenomeInfoDb_1.32.4 IRanges_2.30.1 S4Vectors_0.34.0 BiocGenerics_0.42.0
[17] MatrixGenerics_1.8.1 matrixStats_0.62.0 miloR_1.4.0 edgeR_3.38.4
[21] limma_3.52.2

gt7901b commented 2 years ago

similar error when I ran the other tutorial

da_results <- testNhoods(embryo_milo, design = ~ sequencing.batch + stage, design.df = embryo_design) Error in testNhoods(embryo_milo, design = ~sequencing.batch + stage, design.df = embryo_design) : PCA is not found in reducedDimNames. Avaiable options are pca.corrected,umap

MikeDMorgan commented 2 years ago

@gt7901b - these are 2 completely different errors. The first has evidently been resolved in the vignette as the error states that the rownames of the design.df argument do not match the columns of the nhoodCounts matrix. The second error requires that you included reduced.dim="pca.corrected" in the arguments to testNhoods

gt7901b commented 2 years ago

thanks for the reply, @MikeDMorgan , the second error can be fixed by adding reduced.dim="pca.corrected" and the second tutorial worked nicely. I installed miloR 1.5. I followed the tutorial and had the same traj_design output, but still got this Sample names in design matrix and nhood counts are not matched. R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.5

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages: [1] miloR_1.5.0 statmod_1.4.37 MouseGastrulationData_1.10.0 [4] SpatialExperiment_1.6.1 sp_1.5-0 SeuratObject_4.1.1
[7] Seurat_4.1.1 patchwork_1.1.2 dplyr_1.0.10
[10] scater_1.24.0 ggplot2_3.3.6 scuttle_1.6.3
[13] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.1 Biobase_2.56.0
[16] GenomicRanges_1.48.0 GenomeInfoDb_1.32.4 IRanges_2.30.1
[19] S4Vectors_0.34.0 BiocGenerics_0.42.0 MatrixGenerics_1.8.1
[22] matrixStats_0.62.0 edgeR_3.38.4 limma_3.52.2

Tang-RH commented 9 months ago

thanks for the reply, @MikeDMorgan , the second error can be fixed by adding reduced.dim="pca.corrected" and the second tutorial worked nicely. I installed miloR 1.5. I followed the tutorial and had the same traj_design output, but still got this Sample names in design matrix and nhood counts are not matched. R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.5

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages: [1] miloR_1.5.0 statmod_1.4.37 MouseGastrulationData_1.10.0 [4] SpatialExperiment_1.6.1 sp_1.5-0 SeuratObject_4.1.1 [7] Seurat_4.1.1 patchwork_1.1.2 dplyr_1.0.10 [10] scater_1.24.0 ggplot2_3.3.6 scuttle_1.6.3 [13] SingleCellExperiment_1.18.0 SummarizedExperiment_1.26.1 Biobase_2.56.0 [16] GenomicRanges_1.48.0 GenomeInfoDb_1.32.4 IRanges_2.30.1 [19] S4Vectors_0.34.0 BiocGenerics_0.42.0 MatrixGenerics_1.8.1 [22] matrixStats_0.62.0 edgeR_3.38.4 limma_3.52.2

I don't know if you fixed this problem, I'm replying your comment just in case others encounter the same problem. I faced a similar issue with my data. In the latest version of miloR (1.10.0), the mismatch is now flagged as a warning. The function testNhoods will automatically reorder the matrix to ensure compatibility. Alternatively, you can manually reorder the design matrix before running the testNhoods using the following code:

design = design[match(colnames(milo_obj@nhoodCounts), design$sample),]