Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running Vignette #56

Open
adrianomartinelli opened this issue Jan 20, 2025 · 5 comments
Open

Error running Vignette #56

adrianomartinelli opened this issue Jan 20, 2025 · 5 comments
Assignees

Comments

@adrianomartinelli
Copy link

Hi!

Thanks for the great package. I wanted to try it out on our dataset however I run into an error running the Vignette.

library(SpatialDatasets)
library(spicyR)
spe <- SpatialDatasets::spe_Keren_2018()
res <- spicy(
  spe,
  condition = "tumour_type",
  from = "CD8_T_cell",
  to = "Neutrophils"
)

Throws an error

Error in data.frame(spatAssoc = spatAssoc, condition = pheno[, condition],  : 
  arguments imply differing number of rows: 40, 197678

If I run it on my data and a plain data.frame I get an error that one point was rejected because it lies outside the specified window.

Best,
Adriano

@shreyarajeshrao shreyarajeshrao self-assigned this Jan 20, 2025
@shreyarajeshrao
Copy link
Contributor

Hi Adriano,

Could you check if you're using the latest version of spicyR (1.18)?

@adrianomartinelli
Copy link
Author

Hi @shreyarajeshrao

I was on 1.16 and upgraded now. The example with spe_Keren_2018() now runs.
However, I still run into errors when using a simple dataframe for my data. Besides x, y and cellType I need to specify the ImageID otherwise I get an error. But running the snippet below I get the error:

cells = data[c('sample_name', 'meta_group', 'x', 'y', 'psa_progr', 'pat_id')] %>% 
  rename(cellType = meta_group, imageID=sample_name, subject='pat_id')
cells$imageID = factor(cells$imageID)
cells$cellType = factor(cells$cellType)
cells$psa_progr = factor(cells$psa_progr)
cells$subject = factor(cells$subject)

res = spicy(
      cells=cells,
      condition = 'psa_progr',
      from = 'epithelial-luminal',
      to = 'immune-macrophages',
      )
Error: BiocParallel errors
  1 remote errors, element index: 468
  73 unevaluated and other errors
  first remote error:
Error: Index out of bounds in [.ppp
In addition: Warning messages:
1: Unknown or uninitialised column: `cellID`. 
2: Unknown or uninitialised column: `imageCellID`. 
3: 1 point was rejected as lying outside the specified window 

This is how the cells dataframe looks like and there a no NaN values in it.

# A tibble: 6 × 6
  imageID    cellType               x     y psa_progr subject
  <fct>      <fct>              <dbl> <dbl> <fct>     <fct>  
1 240211_017 immune-proximity    343. 0.4   0         01.9495
2 240211_017 epithelial-luminal  218. 0.889 0         01.9495
3 240211_017 immune-macrophages  242. 1     0         01.9495
4 240211_017 epithelial-luminal  384  1.5   0         01.9495
5 240211_017 epithelial-luminal  444. 0.923 0         01.9495
6 240211_017 stromal             142. 1.87  0         01.9495
> sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

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

time zone: Europe/Zurich
tzcode source: internal

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

other attached packages:
 [1] arrow_18.1.0.1              survival_3.8-3              dplyr_1.1.4                
 [4] imcRtools_1.12.0            SpatialExperiment_1.16.0    SingleCellExperiment_1.28.1
 [7] SummarizedExperiment_1.36.0 Biobase_2.66.0              GenomicRanges_1.58.0       
[10] GenomeInfoDb_1.42.1         IRanges_2.40.1              S4Vectors_0.44.0           
[13] BiocGenerics_0.52.0         MatrixGenerics_1.18.1       matrixStats_1.5.0          
[16] ggplot2_3.5.1               spicyR_1.18.0              

loaded via a namespace (and not attached):
  [1] splines_4.4.0               later_1.4.1                 bitops_1.0-9               
  [4] svgPanZoom_0.3.4            tibble_3.2.1                polyclip_1.10-7            
  [7] lifecycle_1.0.4             sf_1.0-19                   Rdpack_2.6.2               
 [10] rstatix_0.7.2               vroom_1.6.5                 lattice_0.22-6             
 [13] MASS_7.3-64                 MultiAssayExperiment_1.32.0 backports_1.5.0            
 [16] magrittr_2.0.3              httpuv_1.6.15               doRNG_1.8.6.1              
 [19] ClassifyR_3.10.5            sp_2.1-4                    dcanr_1.22.0               
 [22] spatstat.sparse_3.1-0       DBI_1.2.3                   minqa_1.2.8                
 [25] RColorBrewer_1.1-3          abind_1.4-8                 zlibbioc_1.52.0            
 [28] purrr_1.0.2                 ggraph_2.2.1                RCurl_1.98-1.16            
 [31] tweenr_2.0.3                GenomeInfoDbData_1.2.13     ggrepel_0.9.6              
 [34] RTriangle_1.6-0.14          spatstat.utils_3.1-2        terra_1.8-10               
 [37] pheatmap_1.0.12             units_0.8-5                 goftest_1.2-3              
 [40] spatstat.random_3.3-2       svglite_2.1.3               codetools_0.2-20           
 [43] DelayedArray_0.32.0         scuttle_1.16.0              DT_0.33                    
 [46] ggforce_0.4.2               tidyselect_1.2.1            raster_3.6-31              
 [49] UCSC.utils_1.2.0            farver_2.1.2                lme4_1.1-36                
 [52] viridis_0.6.5               spatstat.explore_3.3-4      jsonlite_1.8.9             
 [55] BiocNeighbors_2.0.1         e1071_1.7-16                tidygraph_1.3.1            
 [58] Formula_1.2-5               iterators_1.0.14            systemfonts_1.2.0          
 [61] foreach_1.5.2               tools_4.4.0                 Rcpp_1.0.14                
 [64] glue_1.8.0                  gridExtra_2.3               SparseArray_1.6.0          
 [67] mgcv_1.9-1                  ggthemes_5.1.0              EBImage_4.48.0             
 [70] HDF5Array_1.34.0            scam_1.2-17                 shinydashboard_0.7.2       
 [73] withr_3.0.2                 numDeriv_2016.8-1.1         fastmap_1.2.0              
 [76] ggh4x_0.3.0                 boot_1.3-31                 rhdf5filters_1.18.0        
 [79] digest_0.6.37               R6_2.5.1                    mime_0.12                  
 [82] colorspace_2.1-1            tensor_1.5                  jpeg_0.1-10                
 [85] spatstat.data_3.1-4         utf8_1.2.4                  tidyr_1.3.1                
 [88] generics_0.1.3              data.table_1.16.4           class_7.3-23               
 [91] graphlayouts_1.2.1          httr_1.4.7                  htmlwidgets_1.6.4          
 [94] S4Arrays_1.6.0              pkgconfig_2.0.3             gtable_0.3.6               
 [97] XVector_0.46.0              htmltools_0.5.8.1           carData_3.0-5              
[100] fftwtools_0.9-11            scales_1.3.0                ggupset_0.4.0              
[103] png_0.1-8                   spatstat.univar_3.1-1       reformulas_0.4.0           
[106] rstudioapi_0.17.1           tzdb_0.4.0                  reshape2_1.4.4             
[109] rjson_0.2.23                nlme_3.1-166                nloptr_2.1.1               
[112] bdsmatrix_1.3-7             proxy_0.4-27                cachem_1.1.0               
[115] rhdf5_2.50.2                stringr_1.5.1               KernSmooth_2.23-26         
[118] parallel_4.4.0              vipor_0.4.7                 concaveman_1.1.0           
[121] pillar_1.10.1               grid_4.4.0                  vctrs_0.6.5                
[124] coxme_2.2-22                promises_1.3.2              ggpubr_0.6.0               
[127] car_3.1-3                   beachmat_2.22.0             distances_0.1.11           
[130] xtable_1.8-4                beeswarm_0.4.0              readr_2.1.5                
[133] magick_2.8.5                cli_3.6.3                   locfit_1.5-9.10            
[136] compiler_4.4.0              rlang_1.1.4                 crayon_1.5.3               
[139] rngtools_1.5.2              ggsignif_0.6.4              classInt_0.4-11            
[142] plyr_1.8.9                  ggbeeswarm_0.7.2            stringi_1.8.4              
[145] nnls_1.6                    viridisLite_0.4.2           deldir_2.0-4               
[148] BiocParallel_1.40.0         assertthat_0.2.1            cytomapper_1.18.0          
[151] lmerTest_3.1-3              munsell_0.5.1               tiff_0.1-12                
[154] spatstat.geom_3.3-4         Matrix_1.7-1                hms_1.1.3                  
[157] bit64_4.6.0-1               Rhdf5lib_1.28.0             shiny_1.10.0               
[160] rbibutils_2.3               igraph_2.1.2                broom_1.0.7                
[163] memoise_2.0.1               bit_4.5.0.1 

@shreyarajeshrao
Copy link
Contributor

shreyarajeshrao commented Jan 21, 2025

Hi @adrianomartinelli

Could you share a subset of the data with us so we can reproduce and fix the issue? Additionally, could you try setting window = "square"? That might solve the problem of points lying outside the specified window

@adrianomartinelli
Copy link
Author

Hi @shreyarajeshrao

find some example data and the script here: https://polybox.ethz.ch/index.php/s/4ZJGFlIUiRVSxbl
The link expires on the 26.01.2025.

I think the problem is if the interaction does not appear in a sample...the dataset I provide is a random subset with very few cells per sample with which spicy errors. However, if I ensure that I only have samples with the interaction it seems to work.

Best,
Adriano

@shreyarajeshrao
Copy link
Contributor

shreyarajeshrao commented Jan 23, 2025

HI @adrianomartinelli

Thanks for the example data. It does look like the fact that there are very few cells per image is causing problems with model fit. Setting window = "square" gets rid of the error. You could also set weightsByPair = TRUE if evaluating the relationship for only one cell type pair so spicy won't take into account the other low frequency cell types when weighting images.

Another quick note based on your code, spicy doesn't automatically pick up the subject column like it does for imageID and cellType, so you would need to specify subject = "subject" to build a mixed effects model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants