turep 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
turep-0.1.0/.flake8 ADDED
@@ -0,0 +1,9 @@
1
+ [flake8]
2
+ max-line-length = 120
3
+ exclude =
4
+ .git,
5
+ __pycache__,
6
+ .pytest_cache,
7
+ build,
8
+ dist,
9
+ src/turep.egg-info
@@ -0,0 +1,45 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main", "master"]
6
+ pull_request:
7
+ branches: ["main", "master"]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ test-and-build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.11"
21
+ cache: "pip"
22
+
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install -e .[dev]
27
+ pip install build isort
28
+
29
+ - name: Run formatting and lint checks
30
+ run: |
31
+ black --check src tests examples
32
+ isort --check-only src tests examples
33
+ flake8 src tests examples
34
+
35
+ - name: Run tests
36
+ run: pytest -q
37
+
38
+ - name: Build package
39
+ run: python -m build
40
+
41
+ - name: Upload build artifacts
42
+ uses: actions/upload-artifact@v4
43
+ with:
44
+ name: dist
45
+ path: dist/*
@@ -0,0 +1,49 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.11"
19
+
20
+ - name: Build distributions
21
+ run: |
22
+ python -m pip install --upgrade pip
23
+ pip install build twine
24
+ python -m build
25
+ twine check dist/*
26
+
27
+ - name: Upload distribution artifacts
28
+ uses: actions/upload-artifact@v4
29
+ with:
30
+ name: dist
31
+ path: dist/*
32
+
33
+ publish:
34
+ needs: build
35
+ runs-on: ubuntu-latest
36
+ environment:
37
+ name: pypi
38
+ url: https://pypi.org/p/turep
39
+ permissions:
40
+ id-token: write
41
+ steps:
42
+ - name: Download distribution artifacts
43
+ uses: actions/download-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist
47
+
48
+ - name: Publish to PyPI
49
+ uses: pypa/gh-action-pypi-publish@release/v1
turep-0.1.0/.gitignore ADDED
@@ -0,0 +1,84 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ *.py,cover
49
+ .hypothesis/
50
+ .pytest_cache/
51
+
52
+ # Jupyter Notebook
53
+ .ipynb_checkpoints
54
+
55
+ # IPython
56
+ profile_default/
57
+ ipython_config.py
58
+
59
+ # pyenv
60
+ .python-version
61
+
62
+ # Environments
63
+ .env
64
+ .venv
65
+ env/
66
+ venv/
67
+ ENV/
68
+ env.bak/
69
+ venv.bak/
70
+
71
+ # IDE
72
+ .vscode/
73
+ .idea/
74
+ *.swp
75
+ *.swo
76
+ *~
77
+
78
+ # mypy
79
+ .mypy_cache/
80
+ .dmypy.json
81
+ dmypy.json
82
+
83
+ # Pyre type checker
84
+ .pyre/
turep-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wendao Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include src/turep *.py
5
+ recursive-include tests *.py
6
+ recursive-include examples *.py
7
+ global-exclude __pycache__
8
+ global-exclude *.py[co]
turep-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,117 @@
1
+ Metadata-Version: 2.4
2
+ Name: turep
3
+ Version: 0.1.0
4
+ Summary: Tumor-reactivity prediction for single-cell and spatial transcriptomics data.
5
+ Author-email: Wendao Liu <liuwd15@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/liuwd15/turep
8
+ Project-URL: Repository, https://github.com/liuwd15/turep
9
+ Project-URL: Documentation, https://github.com/liuwd15/turep/blob/main/README.md
10
+ Keywords: single-cell,bioinformatics,machine-learning,vae,focal-loss
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: torch>=1.12.0
22
+ Requires-Dist: numpy>=1.21.0
23
+ Requires-Dist: pandas>=1.3.0
24
+ Requires-Dist: scvi-tools>=1.3.0
25
+ Requires-Dist: fadvi>=0.2.0
26
+ Requires-Dist: anndata>=0.8.0
27
+ Requires-Dist: lightning>=2.0.0
28
+ Requires-Dist: torchmetrics>=0.11.0
29
+ Requires-Dist: platformdirs>=4.0.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
32
+ Requires-Dist: black>=22.0.0; extra == "dev"
33
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
34
+ Requires-Dist: mypy>=0.950; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # Turep
38
+
39
+ **Cross-cancer tumor-reactive CD8+ T cell prediction**
40
+
41
+ `turep` is a Python package for predicting tumor-reactive CD8+ T cells from
42
+ single-cell and spatial transcriptomics data across solid tumors.
43
+
44
+
45
+ ## Installation
46
+
47
+ ### From Pypi
48
+
49
+ ```bash
50
+ pip install turep
51
+ ```
52
+
53
+ ### From source
54
+
55
+ ```bash
56
+ cd turep
57
+ pip install -e .
58
+ ```
59
+
60
+
61
+ ## Usage
62
+
63
+ ### scRNA-seq prediction (Turep-sc)
64
+
65
+ Use the hosted pre-trained model and run prediction directly on query data.
66
+
67
+ ```python
68
+ from turep import load_model, predict_tr
69
+
70
+ # Load the hosted pre-trained turep model.
71
+ # The pretrained model will be downloaded during the first run
72
+ turep_model = load_model()
73
+
74
+ # adata_query is an AnnData input with a column "sample_id" indicating
75
+ # biological sample. It should be subsetted to include CD8+ T cells.
76
+ adata_query = ...
77
+ adata_query = predict_tr(adata_query, turep_model, "sample_id")
78
+ head(adata_query.obs)
79
+ ```
80
+
81
+ Predictions are written to ``adata_query.obs["label_pred"]`` and
82
+ ``adata_query.obs["score_pred"]``.
83
+
84
+ If you have TCR clonotype information saved in a column of adata_query.obs,
85
+ The tumor-reactive probability of TCR clonotypes can be predicted based on Turep score prediction.
86
+
87
+ ```python
88
+ from turep import get_top_clonotype
89
+
90
+ # Uses adata_query.obs["clone_id"] and adata_query.obs["score_pred"] by default
91
+ top_clonotypes = get_top_clonotype(adata_query, clonotype_key="clone_id", K=5, C=0.5)
92
+ print(top_clonotypes.head())
93
+ ```
94
+
95
+ ### Spatial transcriptomics prediction (Turep-st)
96
+
97
+ Factor disentanglement VAE models with focal loss that separate batch effects, biological labels, and residual variation.
98
+
99
+ ```python
100
+ from turep import load_model, predict_tr_spatial
101
+
102
+ adata_ref = load_model().adata
103
+
104
+ # adata_query is an AnnData input with a column "sample_id" indicating
105
+ # biological sample. It should be subsetted to include CD8+ T cells.
106
+ adata_query = ...
107
+ adata_query = predict_tr_spatial(adata_query, adata_ref, "sample_id")
108
+ head(adata_query.obs)
109
+ ```
110
+
111
+ ## Resources
112
+
113
+ The notebooks and scripts for reproducing and visualizing results in our manuscript are available at [turep_notebooks](https://github.com/liuwd15/turep_notebooks).
114
+
115
+ ## Citation
116
+
117
+ If you use this package in your research, please cite our preprint: [Liu et al. bioRxiv. 2026](https://doi.org/10.64898/2026.04.21.719961).
turep-0.1.0/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Turep
2
+
3
+ **Cross-cancer tumor-reactive CD8+ T cell prediction**
4
+
5
+ `turep` is a Python package for predicting tumor-reactive CD8+ T cells from
6
+ single-cell and spatial transcriptomics data across solid tumors.
7
+
8
+
9
+ ## Installation
10
+
11
+ ### From Pypi
12
+
13
+ ```bash
14
+ pip install turep
15
+ ```
16
+
17
+ ### From source
18
+
19
+ ```bash
20
+ cd turep
21
+ pip install -e .
22
+ ```
23
+
24
+
25
+ ## Usage
26
+
27
+ ### scRNA-seq prediction (Turep-sc)
28
+
29
+ Use the hosted pre-trained model and run prediction directly on query data.
30
+
31
+ ```python
32
+ from turep import load_model, predict_tr
33
+
34
+ # Load the hosted pre-trained turep model.
35
+ # The pretrained model will be downloaded during the first run
36
+ turep_model = load_model()
37
+
38
+ # adata_query is an AnnData input with a column "sample_id" indicating
39
+ # biological sample. It should be subsetted to include CD8+ T cells.
40
+ adata_query = ...
41
+ adata_query = predict_tr(adata_query, turep_model, "sample_id")
42
+ head(adata_query.obs)
43
+ ```
44
+
45
+ Predictions are written to ``adata_query.obs["label_pred"]`` and
46
+ ``adata_query.obs["score_pred"]``.
47
+
48
+ If you have TCR clonotype information saved in a column of adata_query.obs,
49
+ The tumor-reactive probability of TCR clonotypes can be predicted based on Turep score prediction.
50
+
51
+ ```python
52
+ from turep import get_top_clonotype
53
+
54
+ # Uses adata_query.obs["clone_id"] and adata_query.obs["score_pred"] by default
55
+ top_clonotypes = get_top_clonotype(adata_query, clonotype_key="clone_id", K=5, C=0.5)
56
+ print(top_clonotypes.head())
57
+ ```
58
+
59
+ ### Spatial transcriptomics prediction (Turep-st)
60
+
61
+ Factor disentanglement VAE models with focal loss that separate batch effects, biological labels, and residual variation.
62
+
63
+ ```python
64
+ from turep import load_model, predict_tr_spatial
65
+
66
+ adata_ref = load_model().adata
67
+
68
+ # adata_query is an AnnData input with a column "sample_id" indicating
69
+ # biological sample. It should be subsetted to include CD8+ T cells.
70
+ adata_query = ...
71
+ adata_query = predict_tr_spatial(adata_query, adata_ref, "sample_id")
72
+ head(adata_query.obs)
73
+ ```
74
+
75
+ ## Resources
76
+
77
+ The notebooks and scripts for reproducing and visualizing results in our manuscript are available at [turep_notebooks](https://github.com/liuwd15/turep_notebooks).
78
+
79
+ ## Citation
80
+
81
+ If you use this package in your research, please cite our preprint: [Liu et al. bioRxiv. 2026](https://doi.org/10.64898/2026.04.21.719961).
@@ -0,0 +1,41 @@
1
+ # Documentation
2
+
3
+ ## Getting Started
4
+
5
+ For practical usage examples, see the [examples](../examples) directory.
6
+
7
+ ## API Reference
8
+
9
+ ### Models
10
+
11
+ - **FANVI**: scANVI-style model with focal-loss classification.
12
+ - **FFADVI**: Factor-disentangled VAE with focal-loss classification.
13
+
14
+ ### Loss Functions
15
+
16
+ - **FocalLoss**: Multiclass focal-loss module.
17
+ - **focal_loss**: Functional interface to compute focal loss.
18
+
19
+ ## Development
20
+
21
+ ### Running Tests
22
+
23
+ ```bash
24
+ pytest tests/
25
+ ```
26
+
27
+ ### Code Style
28
+
29
+ This project uses `black` for code formatting:
30
+
31
+ ```bash
32
+ black src/ tests/
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Contributions are welcome. Please ensure:
38
+
39
+ 1. All tests pass
40
+ 2. Code is formatted with `black`
41
+ 3. Type hints and docstrings are added where appropriate
@@ -0,0 +1,51 @@
1
+ """Example workflow for prediction with a pre-trained turep model.
2
+
3
+ This example demonstrates how to:
4
+ 1. Load the hosted pre-trained model,
5
+ 2. Build a mock query AnnData with matching features,
6
+ 3. Run prediction and summarize clonotypes.
7
+ """
8
+
9
+ import anndata as ad
10
+ import numpy as np
11
+
12
+ from turep import get_top_clonotype, load_model, predict_tr
13
+
14
+
15
+ def create_mock_query_adata(model_adata: ad.AnnData, n_cells: int = 200) -> ad.AnnData:
16
+ """Create mock query data with matched features and required metadata."""
17
+ rng = np.random.default_rng(42)
18
+ n_vars = model_adata.n_vars
19
+
20
+ x_query = rng.negative_binomial(5, 0.3, size=(n_cells, n_vars)).astype(np.float32)
21
+ adata_query = ad.AnnData(X=x_query)
22
+ adata_query.var_names = model_adata.var_names.copy()
23
+
24
+ adata_query.obs["sample_id"] = ["sample_A"] * (n_cells // 2) + ["sample_B"] * (
25
+ n_cells - n_cells // 2
26
+ )
27
+ adata_query.obs["clone_id"] = [f"clone_{i % 20}" for i in range(n_cells)]
28
+ return adata_query
29
+
30
+
31
+ def main() -> None:
32
+ """Run prediction using the hosted pre-trained model."""
33
+ print("Loading pre-trained turep model...")
34
+ turep_model = load_model()
35
+
36
+ print("Building mock query data with matched features...")
37
+ adata_query = create_mock_query_adata(turep_model.adata)
38
+
39
+ print("Predicting on query data...")
40
+ adata_query = predict_tr(adata_query, turep_model, "sample_id")
41
+
42
+ print("Prediction complete")
43
+ print(adata_query.obs[["sample_id", "label_pred", "score_pred"]].head())
44
+
45
+ print("\nTop clonotypes:")
46
+ summary = get_top_clonotype(adata_query)
47
+ print(summary.head(10))
48
+
49
+
50
+ if __name__ == "__main__":
51
+ main()
@@ -0,0 +1,67 @@
1
+ [build-system]
2
+ requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.setuptools.packages.find]
6
+ where = ["src"]
7
+
8
+ [project]
9
+ name = "turep"
10
+ version = "0.1.0"
11
+ description = "Tumor-reactivity prediction for single-cell and spatial transcriptomics data."
12
+ readme = "README.md"
13
+ requires-python = ">=3.11"
14
+ license = {text = "MIT"}
15
+ authors = [
16
+ {name = "Wendao Liu", email = "liuwd15@gmail.com"}
17
+ ]
18
+ keywords = ["single-cell", "bioinformatics", "machine-learning", "vae", "focal-loss"]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Science/Research",
22
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ ]
28
+
29
+ dependencies = [
30
+ "torch>=1.12.0",
31
+ "numpy>=1.21.0",
32
+ "pandas>=1.3.0",
33
+ "scvi-tools>=1.3.0",
34
+ "fadvi>=0.2.0",
35
+ "anndata>=0.8.0",
36
+ "lightning>=2.0.0",
37
+ "torchmetrics>=0.11.0",
38
+ "platformdirs>=4.0.0",
39
+ ]
40
+
41
+ [project.optional-dependencies]
42
+ dev = [
43
+ "pytest>=7.0.0",
44
+ "black>=22.0.0",
45
+ "flake8>=4.0.0",
46
+ "mypy>=0.950",
47
+ ]
48
+
49
+ [project.urls]
50
+ Homepage = "https://github.com/liuwd15/turep"
51
+ Repository = "https://github.com/liuwd15/turep"
52
+ Documentation = "https://github.com/liuwd15/turep/blob/main/README.md"
53
+
54
+ [tool.black]
55
+ line-length = 100
56
+ target-version = ['py311']
57
+ include = '\.pyi?$'
58
+
59
+ [tool.isort]
60
+ profile = "black"
61
+ line_length = 100
62
+
63
+ [tool.mypy]
64
+ python_version = "3.11"
65
+ warn_return_any = true
66
+ warn_unused_configs = true
67
+ disallow_untyped_defs = false
turep-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,43 @@
1
+ """Top-level package exports for turep.
2
+
3
+ This module defines the public API for model classes, loss helpers, and
4
+ prediction utilities.
5
+ """
6
+
7
+ from ._fanvae import FANVAE
8
+ from ._fanvi import FANVI
9
+ from ._focalmixin import FocalLoss, FocalLossClassificationMixin, focal_loss
10
+ from ._model_loader import load_model
11
+ from ._prediction import (
12
+ get_top_clonotype,
13
+ predict_tr,
14
+ predict_tr_pretrained,
15
+ predict_tr_spatial,
16
+ )
17
+
18
+ try:
19
+ from ._ffadvae import FFADVAE
20
+ from ._ffadvi import FFADVI
21
+ except ModuleNotFoundError as exc:
22
+ if exc.name == "fadvi":
23
+ FFADVAE = None
24
+ FFADVI = None
25
+ else:
26
+ raise
27
+
28
+ __version__ = "0.1.0"
29
+
30
+ __all__ = [
31
+ "FANVAE",
32
+ "FANVI",
33
+ "FFADVAE",
34
+ "FFADVI",
35
+ "FocalLoss",
36
+ "FocalLossClassificationMixin",
37
+ "focal_loss",
38
+ "load_model",
39
+ "predict_tr",
40
+ "predict_tr_pretrained",
41
+ "predict_tr_spatial",
42
+ "get_top_clonotype",
43
+ ]