KrishnaswamyLab / phateR

PHATE dimensionality reduction method implemented in R
GNU General Public License v2.0
77 stars 9 forks source link

Precomputed Affinity Matrix Read Only Error #65

Open AndrewSkelton opened 2 years ago

AndrewSkelton commented 2 years ago

Describe the bug When running in pre-computed mode, the method errors, but works with a numeric matrix.

To Reproduce Run phate function with parameter: knn.dist.method = "precomputed"

Expected behavior Phate embedding computed from affinity matrix

Actual behavior

Verbose Output

Calculating PHATE...
  Running PHATE on precomputed affinity matrix with 6900 observations.
  Calculating graph and diffusion operator...
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  ValueError: assignment destination is read-only

System information:

Please run phate.__version__ and paste the results here.

1.0.8
Please run pd.show_versions() and paste the results here.

INSTALLED VERSIONS
------------------
commit           : e8093ba372f9adfe79439d90fe74b0b5b6dea9d6
python           : 3.10.5.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 21.5.0
Version          : Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_GB.UTF-8
LOCALE           : en_GB.UTF-8

pandas           : 1.4.3
numpy            : 1.23.1
pytz             : 2022.1
dateutil         : 2.8.2
setuptools       : 64.0.0
pip              : 22.2.2
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
markupsafe       : None
matplotlib       : 3.5.2
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : 1.9.0
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
zstandard        : None

Output of sessionInfo():

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

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

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

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

other attached packages:
 [1] SoupX_1.6.1                 BUSpaRse_1.10.0             DropletUtils_1.16.0        
 [4] SingleCellExperiment_1.18.0 scDblFinder_1.10.0          annotables_0.1.91          
 [7] SingleR_1.10.0              phateR_1.0.7                Matrix_1.4-1               
[10] patchwork_1.1.1             DESeq2_1.36.0               SummarizedExperiment_1.26.1
[13] Biobase_2.56.0              MatrixGenerics_1.8.1        matrixStats_0.62.0         
[16] GenomicRanges_1.48.0        GenomeInfoDb_1.32.2         IRanges_2.30.0             
[19] S4Vectors_0.34.0            BiocGenerics_0.42.0         edgeR_3.38.1               
[22] limma_3.52.2                harmony_0.1.0               Rcpp_1.0.9                 
[25] sp_1.5-0                    SeuratObject_4.1.0          Seurat_4.1.1               
[28] forcats_0.5.1               stringr_1.4.0               dplyr_1.0.9                
[31] purrr_0.3.4                 readr_2.1.2                 tidyr_1.2.0                
[34] tibble_3.1.8                ggplot2_3.3.6               tidyverse_1.3.2            
[37] reticulate_1.25            

loaded via a namespace (and not attached):
  [1] rsvd_1.0.5                    ica_1.0-3                     Rsamtools_2.12.0             
  [4] lmtest_0.9-40                 crayon_1.5.1                  spatstat.core_2.4-4          
  [7] MASS_7.3-58                   rhdf5filters_1.8.0            nlme_3.1-158                 
 [10] backports_1.4.1               reprex_2.0.1                  GOSemSim_2.22.0              
 [13] rlang_1.0.4                   XVector_0.36.0                ROCR_1.0-11                  
 [16] readxl_1.4.0                  irlba_2.3.5                   scater_1.24.0                
 [19] filelock_1.0.2                xgboost_1.6.0.1               plyranges_1.16.0             
 [22] BiocParallel_1.30.3           rjson_0.2.21                  bit64_4.0.5                  
 [25] glue_1.6.2                    pheatmap_1.0.12               sctransform_0.3.3            
 [28] parallel_4.2.1                vipor_0.4.5                   spatstat.sparse_2.1-1        
 [31] AnnotationDbi_1.58.0          DOSE_3.22.0                   spatstat.geom_2.4-0          
 [34] haven_2.5.0                   tidyselect_1.1.2              fitdistrplus_1.1-8           
 [37] XML_3.99-0.10                 zoo_1.8-10                    ggpubr_0.4.0                 
 [40] GenomicAlignments_1.32.1      xtable_1.8-4                  magrittr_2.0.3               
 [43] evaluate_0.15                 scuttle_1.6.2                 cli_3.3.0                    
 [46] zlibbioc_1.42.0               rstudioapi_0.13               miniUI_0.1.1.1               
 [49] rpart_4.1.16                  fastmatch_1.1-3               ensembldb_2.20.2             
 [52] shiny_1.7.2                   BiocSingular_1.12.0           xfun_0.31                    
 [55] cluster_2.1.3                 KEGGREST_1.36.3               interactiveDisplayBase_1.34.0
 [58] ggrepel_0.9.1                 listenv_0.8.0                 Biostrings_2.64.0            
 [61] png_0.1-7                     future_1.27.0                 zeallot_0.1.0                
 [64] withr_2.5.0                   bitops_1.0-7                  plyr_1.8.7                   
 [67] cellranger_1.1.0              AnnotationFilter_1.20.0       dqrng_0.3.0                  
 [70] pillar_1.8.0                  GlobalOptions_0.1.2           cachem_1.0.6                 
 [73] GenomicFeatures_1.48.3        fs_1.5.2                      DelayedMatrixStats_1.18.0    
 [76] vctrs_0.4.1                   ellipsis_0.3.2                generics_0.1.3               
 [79] tools_4.2.1                   beeswarm_0.4.0                munsell_0.5.0                
 [82] fgsea_1.22.0                  DelayedArray_0.22.0           fastmap_1.1.0                
 [85] compiler_4.2.1                abind_1.4-5                   httpuv_1.6.5                 
 [88] rtracklayer_1.56.1            ExperimentHub_2.4.0           plotly_4.10.0                
 [91] rgeos_0.5-9                   GenomeInfoDbData_1.2.8        gridExtra_2.3                
 [94] lattice_0.20-45               deldir_1.0-6                  utf8_1.2.2                   
 [97] later_1.3.0                   BiocFileCache_2.4.0           jsonlite_1.8.0               
[100] scales_1.2.0                  ScaledMatrix_1.4.0            pbapply_1.5-0                
[103] carData_3.0-5                 sparseMatrixStats_1.8.0       genefilter_1.78.0            
[106] lazyeval_0.2.2                promises_1.2.0.1              car_3.1-0                    
[109] R.utils_2.12.0                goftest_1.2-3                 spatstat.utils_2.3-1         
[112] cowplot_1.1.1                 statmod_1.4.36                Rtsne_0.16                   
[115] BSgenome_1.64.0               uwot_0.1.11                   igraph_1.3.4                 
[118] HDF5Array_1.24.1              survival_3.3-1                yaml_2.3.5                   
[121] htmltools_0.5.3               memoise_2.0.1                 BiocIO_1.6.0                 
[124] locfit_1.5-9.6                viridisLite_0.4.0             digest_0.6.29                
[127] assertthat_0.2.1              mime_0.12                     rappdirs_0.3.3               
[130] RSQLite_2.2.15                future.apply_1.9.0            Rmisc_1.5.1                  
[133] data.table_1.14.2             blob_1.2.3                    R.oo_1.25.0                  
[136] labeling_0.4.2                splines_4.2.1                 ggsci_2.9                    
[139] Rhdf5lib_1.18.2               googledrive_2.0.0             AnnotationHub_3.4.0          
[142] ProtGenerics_1.28.0           RCurl_1.98-1.7                broom_1.0.0                  
[145] hms_1.1.1                     modelr_0.1.8                  rhdf5_2.40.0                 
[148] colorspace_2.0-3              BiocManager_1.30.18           ggbeeswarm_0.6.0             
[151] shape_1.4.6                   GEOquery_2.64.2               RANN_2.6.1                   
[154] circlize_0.4.15               fansi_1.0.3                   tzdb_0.3.0                   
[157] parallelly_1.32.1             R6_2.5.1                      grid_4.2.1                   
[160] ggridges_0.5.3                lifecycle_1.0.1               bluster_1.6.0                
[163] curl_4.3.2                    ggsignif_0.6.3                googlesheets4_1.0.0          
[166] leiden_0.4.2                  DO.db_2.9                     qvalue_2.28.0                
[169] RcppAnnoy_0.0.19              RColorBrewer_1.1-3            htmlwidgets_1.5.4            
[172] beachmat_2.12.0               polyclip_1.10-0               biomaRt_2.52.0               
[175] rvest_1.0.2                   mgcv_1.8-40                   globals_0.15.1               
[178] spatstat.random_2.2-0         progressr_0.10.1              codetools_0.2-18             
[181] lubridate_1.8.0               GO.db_3.15.0                  metapod_1.4.0                
[184] prettyunits_1.1.1             dbplyr_2.2.1                  RSpectra_0.16-1              
[187] R.methodsS3_1.8.2             celldex_1.6.0                 gtable_0.3.0                 
[190] DBI_1.1.3                     tensor_1.5                    httr_1.4.3                   
[193] KernSmooth_2.23-20            stringi_1.7.8                 progress_1.2.2               
[196] farver_2.1.1                  reshape2_1.4.4                annotate_1.74.0              
[199] viridis_0.6.2                 DT_0.23                       xml2_1.3.3                   
[202] BiocNeighbors_1.14.0          restfulr_0.0.15               geneplotter_1.74.0           
[205] scattermore_0.8               BiocVersion_3.15.2            scran_1.24.0                 
[208] bit_4.0.4                     spatstat.data_2.2-0           pkgconfig_2.0.3              
[211] gargle_1.2.0                  rstatix_0.7.0                 knitr_1.39
``` Please run sessionInfo() and paste the results here. ```

Output of reticulate::py_discover_config(required_module = "phate"):

python:         /Users/andrewskelton/miniconda3/envs/PHATE/bin/python
libpython:      /Users/andrewskelton/miniconda3/envs/PHATE/lib/libpython3.10.dylib
pythonhome:     /Users/andrewskelton/miniconda3/envs/PHATE:/Users/andrewskelton/miniconda3/envs/PHATE
version:        3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:09:13) [Clang 13.0.1 ]
numpy:          /Users/andrewskelton/miniconda3/envs/PHATE/lib/python3.10/site-packages/numpy
numpy_version:  1.23.1
phate:          /Users/andrewskelton/miniconda3/envs/PHATE/lib/python3.10/site-packages/phate

NOTE: Python version was forced by RETICULATE_PYTHON
``` Please run `reticulate::py_discover_config(required_module = "phate")` and paste the results here. ```

Output of phateR::check_pyphate_version():

TRUE

``` Please run `phateR::check_pyphate_version()` and paste the results here. You can do this with `R -e 'phateR::check_pyphate_version()'` ```

Additional context Add any other context about the problem here.

scottgigante commented 1 year ago

Likely what's happening here is that your precomputed distance matrix is read-only because it's being accessed through reticulate. The fix would likely involve identifying when/if this is a problem and creating a copy of the matrix at the relevant point in the python code.

OneHitKO commented 7 months ago

Hello, I also experience the same error as above, and would be curious to know if you have found a solution. Thanks for your help!