shuzhao-li-lab / asari

asari, metabolomics data preprocessing
Other
38 stars 9 forks source link

Asari has no functions / modules when interfacing thru reticulate #50

Closed jmmitc06 closed 1 year ago

jmmitc06 commented 1 year ago

From Lei with Jeff Xia:

Hi Joshua, how are you?

I'm trying to call asari in R using reticulate package (which is a interface to 'Python' modules, classes, and functions in R.), to interface with our tools in R. But after I import asari, there are no functions or modules, only the standard attributes that are available in all Python modules. Could you help me with that? Here attached is what I run in R.

`

asari <- reticulate::import("asari") methods <- reticulate::py_list_attributes(asari) print(methods) [1] "builtins" "cached" "doc" "file"
[5] "loader" "name" "package" "path"
[9] "spec" "version"

methods_scipy <- reticulate::py_list_attributes(scipy) print(methods_scipy) [1] "LowLevelCallable" "__numpy_version" "version__"
[4] "cluster" "datasets" "fft"
[7] "fftpack" "integrate" "interpolate"
[10] "io" "linalg" "misc"
[13] "ndimage" "odr" "optimize"
[16] "show_config" "signal" "sparse"
[19] "spatial" "special" "stats"
[22] "test" `

Was able to replicate on my end, I believe this is a packaging issue.

shuzhao-li commented 1 year ago

This is related to how to reuse asari in notebooks or other packages. Asari functions are usually in the name space of individual modules. My hunch is that, without any experience in reticulate, adding imports into asari.init may work.

jmmitc06 commented 1 year ago

There is now code to dynamically import all sub-modules into asari.init. May not be the cleanest solution but we can refine later.

^^ scratch this, while this made the functions available it broke all the imports and I did not catch it since I was accidently testing on the wrong version ^^

jmmitc06 commented 1 year ago

This issue has now been fixed. Strangely, dynamically populating all in init.py is not recognized by reticulate. I'm not sure why. This unfortunately means that I have to do the not so clever thing of just listing all the imports for the modules explicitly.

`

library(reticulate) x <- reticulate::import("asari") reticulate::py_list_attributes(x) [1] "builtins" "cached" "doc" "file" "loader" "name" "package"
[8] "path" "spec" "version" "analyze" "annotate_user_table" "chromatograms" "command_line"
[15] "constructors" "dashboard" "db" "default_parameters" "experiment" "json_encoder" "main"
[22] "mass_functions" "peaks" "qc" "samples" "workflow"

`

You can also install from github from within Rstudio using the system command. I assume that reticulate simply imports the package from the local install if present.

jmmitc06 commented 1 year ago

This is now implemented and it seems Lei has no further requirements.