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

Misinformation when using anndataToGiotto with non default env_name #230

Open
wwang-chcn opened this issue Aug 29, 2024 · 5 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@wwang-chcn
Copy link
Contributor

wwang-chcn commented Aug 29, 2024

Describe the Error

The function anndataToGiotto, even though it runs successfully, throws an error message.
This will happen if I use an alternative env_name.

...

Error Message

# ERROR: The requested version of Python
# ('/Users/wwang/miniconda3/envs/giotto_env/bin/python')
# cannot be used, as another version of Python
# ('/Users/wwang/miniconda3/envs/giotto_ontrac_env/bin/python')
# has already been initialized. Please restart the R
# session if you need to attach reticulate to a different
# version of Python.

To Reproduce

Steps to reproduce the behavior, i.e.:

  1. Install a custom conda env
installGiottoEnvironment(
  packages_to_install = c(
    "pandas==1.5.1",
    "networkx==2.8.8",
    "python-igraph==0.10.2",
    "leidenalg==0.9.0",
    "python-louvain==0.16",
    "python.app==1.4",
    "scikit-learn==1.1.3",
    "smfishhmrf",
    "scanpy",
    "session-info"
  ),
  pip_packages = c("python-louvain", "smfishhmrf", "session-info", "scanpy"),
  envname = "giotto_alt_env"
)
  1. Try to read an .h5ad obj using anndataToGiotto
set_giotto_python_path("giotto_alt_env")
# a python path has been provided
# Using python path:
#  "/Users/wwang/miniconda3/envs/giotto_alt_env/bin/python"
giotto_all_slices_obj <- anndataToGiotto(file.path("data/03_session5/counts.h5ad"),
                                         env_name = "giotto_alt_env")
# python already initialized in this session
#  active environment : 'giotto_alt_env'
#  python version : 3.10
# checking default envname 'giotto_env'
# a system default python environment was found
# Using python path:
#  "/Users/wwang/miniconda3/envs/giotto_env/bin/python"
# ERROR: The requested version of Python
# ('/Users/wwang/miniconda3/envs/giotto_env/bin/python') cannot be used, as
# another version of Python
# ('/Users/wwang/miniconda3/envs/giotto_alt_env/bin/python') has already been
# initialized. Please restart the R session if you need to attach reticulate
# to a different version of Python.
# There are non numeric or integer columns for the spatial location
#  input at column position(s): 1
#  The first non-numeric column will be considered as a cell ID
#  to test for consistency with the expression matrix
#  Other non numeric columns will be removed
# 
# List item [1]:
#  spat_unit: cell
#  feat_type: rna
# > Cell metadata for spat_unit " cell " and feat_type " rna " already exists and
#  will be replaced with new metadata.
# Setting cell metadata [cell][rna]
# list depth of 2
# 
# List item [1]:
#  spat_unit: cell
#  feat_type: rna
# > Feat metadata for spat_unit " cell " and feat_type " rna " already exists and
#  will be replaced with new metadata.
# Setting feature metadata [cell][rna]
# 
# AnnData object successfully converted to Giotto.
# Warning message:
# Python is required for full Giotto functionality. 
# Spatial locations were not found. If spatial locations should have been found,
#         please modify the anndata object to include a keyword-value pair within the obsm slot,
#         in which the keyword contains the phrase "spatial" and the value corresponds to the spatial locations.
# 
#         In the Giotto Object resulting from this conversion, dummy locations will be used.

Expected behavior

This function ran successfully, no error message should thros.

Screenshots

image

System Information

R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.6.6

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: America/New_York
tzcode source: internal

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

other attached packages:
[1] GiottoClass_0.3.5

loaded via a namespace (and not attached):
 [1] Matrix_1.7-0       jsonlite_1.8.8     compiler_4.4.0     gtools_3.9.5       Rcpp_1.0.13        magick_2.8.4       parallel_4.4.0     png_0.1-8         
 [9] yaml_2.3.8         fastmap_1.2.0      reticulate_1.38.0  lattice_0.22-6     deldir_2.0-4       dbscan_1.2-0       generics_0.1.3     igraph_2.0.3      
[17] knitr_1.47         backports_1.5.0    checkmate_2.3.2    R.utils_2.12.3     GiottoUtils_0.1.11 rlang_1.1.4        sp_2.1-4           terra_1.7-78      
[25] xfun_0.44          cli_3.6.3          withr_3.0.1        magrittr_2.0.3     digest_0.6.35      grid_4.4.0         rstudioapi_0.16.0  lifecycle_1.0.4   
[33] R.methodsS3_1.8.2  R.oo_1.26.0        evaluate_0.24.0    glue_1.7.0         data.table_1.15.4  codetools_0.2-20   rmarkdown_2.27     matrixStats_1.3.0 
[41] tools_4.4.0        pkgconfig_2.0.3    htmltools_0.5.8.1 
@wwang-chcn
Copy link
Contributor Author

When I examined the code within the function anndataToGiotto, I found that the function didn't seem to be using the parameter env_name.

@jiajic
Copy link
Member

jiajic commented Aug 29, 2024

It looks like the only thing that controls which python is used is the python_path param in there right now. But that one only passes the default python_path = NULL to createGiottoInstructions() in an attempt to initialize an environment following defaults.

set_giotto_python_path() has already done that for your specified environment.

I'm more surprised that the error from reticulate didn't stop execution.

@wwang-chcn
Copy link
Contributor Author

We can do nothing if the error message yield from reticulate :(

@jiajic
Copy link
Member

jiajic commented Aug 29, 2024

Well it's a good error to have and makes the user aware. We just need to remove the env_name param and use the python_path param since they're essentially handled the same way by Giotto, or something similar.

You can pass either an envname or a full path to a python binary to python_path param.

Looks like the reason it didn't stop execution is that somewhere in our implementation with createGiottoInstructions() we've used a try()

> createGiottoInstructions(python_path = "r-reticulate")
python already initialized in this session
 active environment : 'giotto_env'
 python version : 3.10
a python path has been provided
Using python path:
 "/projectnb/rd-spat/HOME/george/.conda/envs/r-reticulate/bin/python" Using
 python path:
 "/usr3/graduate/jiajic/.local/share/r-miniconda/envs/r-reticulate/bin/python"
$python_path
[1] "Error in required && !file_test(\"-f\", python) : \n  'length = 2' in coercion to 'logical(1)'\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in required && !file_test("-f", python): 'length = 2' in coercion to 'logical(1)'>

@wwang-chcn
Copy link
Contributor Author

Just test it. It won't throw any error message when I provide env name to python_path.

@jiajic jiajic added the documentation Improvements or additions to documentation label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants