Installation

This tutorial demonstrates how to install Pysodb on a method which use for spatial clustering.

Using stagate as an example, install Pysodb in its installation environment.

Reference tutorials presents can be found at https://github.com/QIFEIDKN/STAGATE_pyG and https://github.com/TencentAILabHealthcare/pysodb.

Installing softwares and tools

1. The first step is to install Visual Studio Code, Conda, Jupyter notebook and CUDA in advance.

Reference tutorials presents how to install Visual Studio Code, Conda and Jupyter notebook, respectively. And they can be found at https://code.visualstudio.com/Docs/setup/setup-overview, https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal and https://code.visualstudio.com/docs/datascience/data-science-tutorial.

STAGATE’s tensorflow version is based on version 1.15.0. Officials have stopped updating TensorFlow1 and now many algorithms are more developed based on TensorFlow2, STAGATE_pyG will be selected and demonstrated for installation in this tutorial.

Since STAGATE_pyG is based on pyG (PyTorch Geometric) framework, it requires GPUs on a device and need to install CUDA tool. A tutorials is available at https://developer.nvidia.com/cuda-downloads.

2. Launch Visual Studio Code and open a terminal window.

Henceforth, various packages or modules will be installed via the command line

Installation STAGATE_pyG

3. Select the installation path and open it

[ ]:
cd <path>

4. Clone STAGATE_pyG code

[ ]:
git clone https://github.com/QIFEIDKN/STAGATE_pyG.git

If cloning the code fails through git, please download it at https://github.com/QIFEIDKN/STAGATE_pyG, upload it to the folder created above, and extract it.

5. Open the STAGATE_pyG directory

[ ]:
cd STAGATE_pyG

6. Create a conda environment

[ ]:
conda create -n <environment_name> python=3.8

7. Activate a conda environment

Run the following command on the terminal to activate the conda environment:

[ ]:
conda activate <environment_name>

8. Install torch with CUDA

eg. pip install torch==1.13.0+cu117 -f https://download.pytorch.org/whl/cu117/torch_stable.html

[ ]:
pip install torch==<torch_version>+<cuda_version> -f https://download.pytorch.org/whl/<cuda_version>/torch_stable.html

9. Install PyTorch Geometric

Install a PyTorch Geometric according to the version of pytorch and CUDA, system. Select the package and copy a run command to run on your terminal. https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html

eg. pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv torch_geometric -f https://data.pyg.org/whl/torch-1.13.0+cu117.html

10. Install other python packages

[ ]:
pip install -r requirement.txt

Installation mclust library in STAGATE_pyG conda environment

STAGATE uses the mclust package to identify spatial domains, which is an R library.

The next tutorial will show how to install the mclust package using r and rpy2 for python in a conda environment.

Activate by running the command “conda activate “

11. Install r and rpy2 in in a conda environment

[ ]:
conda install -c r rpy2

Run following command on the terminal to set the R_HOME environment variable to the location of the R executable within a conda environment.

[ ]:
export R_HOME=/home/<user_name>/anaconda3/envs/<environment_name>/lib/R

Run following command on the terminal to set the R_LIBS_USER environment variable to where R will install any packages that are installed within this conda environment.

[ ]:
export R_LIBS_USER=/home/<user_name>/anaconda3/envs/<environment_name>/lib/R/library

When configuring the installation paths for R_HOME and R_LIBS_USER, the standard Linux and Conda environment paths (such as .conda) may not be applicable. In such cases, users need to locate the R path and library path within the Conda virtual environment’s Python packages and replace them accordingly.

12. Enter the python interpreter to install mclust library

Run “python” at the terminal to enter the python interpreter and install mclust library in the python interpreter

[ ]:
python

Run the following commands in sequence:

[ ]:
import rpy2.robjects.packages as r
utils = r.importr("utils")
package_name = "mclust"
utils.install_packages(package_name)

Then, select a loading channel to install mclust.

Finally, exit the python interpreter.

[ ]:
exit()

Installation Pysodb

Keep the conda environment active

13. Clone Pysodb code

[ ]:
git clone https://github.com/TencentAILabHealthcare/pysodb.git

If cloning the code fails through git, please download it at https://github.com/TencentAILabHealthcare/pysodb, upload it to the folder created above, and extract it.

14. Open the Pysodb directory

[ ]:
cd pysodb

15. Install a Pysodb package from source code

[ ]:
python setup.py install

If “error: urllib3 2.0.0a3 is installed but urllib3<1.27,>=1.21.1 is required by {‘requests’}” appears, users can execute the following commands,respectively.

[ ]:
pip install 'urllib3>=1.21.1,<1.27'
python setup.py install
[1]:
print('finish!')
finish!