Teichlab / celltypist

A tool for semi-automatic cell type classification
https://www.celltypist.org/
MIT License
278 stars 44 forks source link

Use "python -m" to run celltypist? #8

Closed bbimber closed 2 years ago

bbimber commented 2 years ago

Hello,

We're interested in running celltypist from R/reticulate. While I understand that celltypist makes a standalone executable, can something like the following work on the command line? For various reasons this is preferred since code would not need ot know the location of the celltypist executable file itself:

python.exe -m celltypist.command_line --update_models

The above does not error, but it also doesnt seem to do anything either (no console output produced). Thanks.

prete commented 2 years ago

Hi @bbimber I'm not sure how you're using that command, but if you want to pull the models from R using reticulate I'd recommend you do this:

library(reticulate)
celltypist <- reticulate::import("celltypist")
celltypist$models$download_models(TRUE)

and from bash you can invoke the python module+method like this:

python -c "import celltypist; celltypist.models.download_models(True)" 
bbimber commented 2 years ago

@prete Thanks. While my example was a simple --update_models, do you know if one could replicate a more complex command-line as command-line arguments, rather than converting to python code? your idea about '-c' is a reasonable fallback.

ChuanXu1 commented 2 years ago

@bbimber, not sure I understand correctly, but if you want to use celltypist as command-line, after installing it, you can just do celltypist --update-models in the shell environment.

bbimber commented 2 years ago

I realize this is a little abnormal, but here's the logic. We have an R package that calls celltypist. If someone installs the R package, I cant really control their environment. Therefore I dont know if celltypist is on their $PATH. R-Reticulate will provide the location of the python executable, and python can resolve the celltypist package.

The specific code is here, where I'm just assuming celltypist is in the $PATH currently:

https://github.com/bimberlabinternal/RIRA_classification/blob/342d6a6e3d51b8b9ce91e967e8a1ed509784029a/R/CellTypist.R#L26

The reason I opened this thread is because I was hoping there was some existing python hook I'm just not seeing, like "python.exe -m celltypist.command_line [arguments]". I assume this doesnt work since it somehow circumvents the arg-parsing code?

In contrast, we're able to run another command-line python tool, GMM-Demux, by calling their python entrypoint directly and passing in the full command-line args:

https://github.com/BimberLab/cellhashR/blob/7aa9fee0649a5f82d51e09180f396a5299582380/R/GMM_Demux.R#L26

Also, my example of --update-models was mainly for example. Our goal is to run the full command-line in a way that didnt require knowing the location of your celltypist executable. Anyway, 'python -c' is a reasonable solution, like you suggested.

ChuanXu1 commented 2 years ago

@bbimber, this has been fixed by calling the main() function. 0e1694915fbdcb4b72408d806fb1260222f9aa59

This will be reflected in the next release, I will let you know then; for now, maybe you can install the latest CellTypist from Github?

bbimber commented 2 years ago

@ChuanXu1 thanks - i really appreciate this!