Metadata-Version: 2.4
Name: terra-st
Version: 0.0.0
Summary: Spatial transcriptomics foundation model
Project-URL: Documentation, https://terra.readthedocs.io/
Project-URL: Source, https://github.com/Lotfollahi-lab/terra
Project-URL: Home-page, https://github.com/Lotfollahi-lab/terra
Author: Sebastian Birk, Mohammad Vali Sanian
Maintainer-email: Sebastian Birk <sebastian.birk@helmholtz-munich.de>, Mohammad Vali Sanian <mohammad.sanian@helsinki.fi>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Lotfollahi-lab
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: anndata
Requires-Dist: datasets
Requires-Dist: ipykernel
Requires-Dist: jupyterlab
Requires-Dist: leidenalg
Requires-Dist: peft
Requires-Dist: pyensembl
Requires-Dist: scib-metrics
Requires-Dist: scikit-misc
Requires-Dist: session-info
Requires-Dist: squidpy
Requires-Dist: torch
Requires-Dist: transformers
Requires-Dist: wandb
Provides-Extra: dev
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: twine>=4.0.2; extra == 'dev'
Provides-Extra: doc
Requires-Dist: docutils!=0.18.*,!=0.19.*,>=0.8; extra == 'doc'
Requires-Dist: ipykernel; extra == 'doc'
Requires-Dist: ipython; extra == 'doc'
Requires-Dist: myst-nb; extra == 'doc'
Requires-Dist: pandas; extra == 'doc'
Requires-Dist: sphinx-autodoc-typehints; extra == 'doc'
Requires-Dist: sphinx-book-theme>=1.0.0; extra == 'doc'
Requires-Dist: sphinx-copybutton; extra == 'doc'
Requires-Dist: sphinx>=4; extra == 'doc'
Requires-Dist: sphinxcontrib-bibtex>=1.0.0; extra == 'doc'
Requires-Dist: sphinxext-opengraph; extra == 'doc'
Provides-Extra: eval
Requires-Dist: cellphonedb; extra == 'eval'
Requires-Dist: omnipath; extra == 'eval'
Provides-Extra: test
Requires-Dist: coverage; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

# TERRA

## Installation

To install the project and its dependencies, run:

```shell
pip install -e .
```

## Repository Structure
1. **`main.py`**  
   The main entry point for the project, which supports running training and evaluation sweeps. It includes command-line arguments for customization and handles multi-GPU setups.

2. **`configs/$DATASET.yaml`**  
   Configuration file that defines the dataset specific hyperparameters and settings used during the training process, such as model architecture, data handling, and optimization settings (```$DATASET``` is the name of the dataset, e.g. ```merfish_300k```).

3. **`src/terra/models/gene_transformer.py`**  
   Contains the model definition for the gene transformer, implementing the core architecture that will be trained and evaluated.

4. **`src/terra/train.py`**  
   Handles the training process in a distributed setting. This script contains the logic for executing the training loop and logging results.

5. **`src/terra/infer.py`**  
   Manages the evaluation process. It evaluates the trained model on the specified tasks and logs the performance metrics.

6. **`src/terra/utils/config.py`**  
   Includes helper functions to setup the model and batch size params.

7. **`src/terra/utils/embedding.py`**  
   Provides utility functions for handling and loading embeddings required by the model during training and inference.

8. **`src/terra/utils/evaluation.py`**  
   Includes helper functions to streamline the evaluation process, such as metrics calculations and data preparation.

9. **`src/terra/datasets/cell_neighborhood_dataset.py`**
   Includes helper functions to create torch datasets for data loading.

10. **`tests`**  
   Includes test cases for different functionalities.

## Usage

### Training

To start training with a single GPU, use the following command:

```shell
python -m pdb main.py --fname configs/$DATASET.yaml --devices cuda:0
```
where ```$DATASET``` is the name of the dataset, e.g. ```merfish_300k```.

To start training with multiple GPUs, use the following command:

```shell
python -m pdb main.py --fname configs/$DATASET.yaml --devices cuda:0 cuda:1
```

To perform a sweep during training, use:

```shell
python -m pdb main.py --fname configs/$DATASET.yaml --devices cuda:0 --do_sweep
```

For multi-node training, first configure the required settings in your job_config file. 
Then, execute the following command:

```shell
bsub_mn_mg_yaml configs/job/hst_corpus_70m_test.yaml
```