Cell2Location

Overview

Cell2Location is a python application providing comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model).

We have not installed cell2location centrally but instead show below how to install it in a conda environment in your home directory.

Restrictions on use

Cell2location is made available under the Apache License v2.0. All usage must adhere to this license.

As per the instruction on the cell2location github page, if you use cell2location please cite their paper:

Kleshchevnikov, V., Shmatko, A., Dann, E. et al. Cell2location maps fine-grained cell types in spatial transcriptomics. Nat Biotechnol (2022). https://doi.org/10.1038/s41587-021-01139-4 https://www.nature.com/articles/s41587-021-01139-4.

Installation Procedure

The following instructions have been confirmed to work by a user of cell2location on the CSF (who also runs it on the GPUs):

# From the CSF login node, start an interactive session so you have access to
# the outside world - needed to download the software:
qrsh -l short
 #
 # Wait to be logged in to a compute node, then:

export PYTHONNOUSERSITE=True
export ENAME=cell2loc_env                    # Make a note of what you name your conda env!
module load apps/binapps/anaconda3/2022.10   # Provides python 3.9. New versions of c2l may need newer.
python --version

# Prevent python installs escaping from your conda env
rm ~/.pydistutils.cfg

# Create a new conda env (will be in your ~/.conda directory)
conda create -y -n $ENAME python=3.9

# Activate the env. Note: we DO NOT use 'conda activate ...' because that
# would force this version of python on you every time you log in (it adds
# to your ~/.bashrc file. By using 'source activate ...' we avoid that.) 
source activate $ENAME

# Now install cell2location
pip --no-python-version-warning --isolated install cell2location[tutorials]

# If you wish to use it in a jupyter notebook, the following two installs will help
pip --no-python-version-warning --isolated install ipykernel 
pip --no-python-version-warning --isolated install ipywidgets 

# Now install a cell2location notebook kernel (you'll see this is the menu in your notebook.)
python -m ipykernel install --user --name=$ENAME --display-name='Environment ('${ENAME}')'

# If you wish to install further python packages, do so now ...

# We've finished with the conda env now that we've installed everything
source deactivate
# Leave the interactive session and go back to the login node
exit

Running the application

Please do not run cell2location on the login node. Jobs should be submitted to the compute nodes via batch.

Serial batch job submission

Create a batch submission script (which will load the modulefile in the jobscript), for example:

#!/bin/bash --login
#$ -cwd             # Job will run from the current directory
                    # NO -V line - we load modulefiles in the jobscript

module load apps/binapps/anaconda3/2022.10

# Activate your conda env. Use the name you used above when creating it.
source activate cell2loc_env

python myscript.py

Submit the jobscript using:

qsub scriptname

where scriptname is the name of your jobscript.

Please see the GPU jobs instructions for submitting to the GPU nodes.

Jupyter Notebook job

Here are the brief details on submitting a jupyter notebook job.

# On the CSF login node:
module purge
module load apps/binapps/anaconda3/2022.10 apps/binapps/jupyter-notebook/any
export PYTHONNOUSERSITE=True
# Activate your conda env. Use the name you used above when creating it.
source activate cell2loc_env
jupyter-notebook-csf
          #
          # Add flags to this command to change the type of job (e.g., -g or -G for GPU jobs.)
          # Run 'jupyter-notebook-csf -h' for further help

# Follow the instructions displayed by that command. This will let you connect
# a web-browser on your laptop/desktop to the CFS job. 
#
# In the notebook webpage, you'll be able to select the "Environment (cell2loc_env)" 
# kernel in which to run your notebook commands.

For further details, including how to submit GPU-enabled jupyter notebook jobs, and help with each step, please see our Jupyter Notebook instructions.

Further info

Updates

None.

Last modified on October 19, 2023 at 1:21 pm by George Leaver