Metadata-Version: 2.4
Name: tcrsift
Version: 3.44.11
Summary: T-cell receptor clonotype prioritization from antigen-enrichment cultures and single-cell VDJ and gene-expression data
Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/pirl-unc/tcrsift
Project-URL: Documentation, https://pirl.unc.edu/tcrsift/
Project-URL: Bug Tracker, https://github.com/pirl-unc/tcrsift/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Environment :: Console
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: argcomplete>=3
Requires-Dist: datacache<2.0.0,>=1.38.0; python_version >= "3.12"
Requires-Dist: datacache<2.0.0,>=1.12.0; python_version < "3.12"
Requires-Dist: numpy<3.0.0,>=2.0.0
Requires-Dist: pandas<4.0.0,>=3.0.0; python_version >= "3.12"
Requires-Dist: pandas<3.0.0,>=2.1.4; python_version < "3.12"
Requires-Dist: scipy<2.0.0,>=1.10.0
Requires-Dist: h5py<4.0.0,>=3.8.0
Requires-Dist: scanpy<2.0.0,>=1.10.2
Requires-Dist: anndata<0.14.0,>=0.13.0; python_version >= "3.12"
Requires-Dist: anndata<0.14.0,>=0.10.0; python_version < "3.12"
Requires-Dist: matplotlib<4.0.0,>=3.7.0
Requires-Dist: seaborn<1.0.0,>=0.13
Requires-Dist: pyyaml<7.0,>=6.0
Requires-Dist: tqdm<5.0.0,>=4.60.0
Requires-Dist: reportlab<6.0.0,>=4.0.0
Requires-Dist: pypdf<7.0.0,>=4.0.0
Requires-Dist: pyensembl<3.0.0,>=2.0.0
Requires-Dist: openpyxl<4.0.0,>=3.0.0
Requires-Dist: oncoref<2.0,>=1.8.81
Provides-Extra: tcrpeg
Requires-Dist: tcrpeg>=1.0.0; extra == "tcrpeg"
Requires-Dist: torch>=2.0.0; extra == "tcrpeg"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-xdist>=3.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: pylint<4.0.0,>=3.0.0; extra == "dev"
Requires-Dist: tcrpeg>=1.0.0; extra == "dev"
Requires-Dist: torch>=2.0.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.5.0; extra == "docs"
Requires-Dist: mkdocs-material>=9.0.0; extra == "docs"
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "docs"
Requires-Dist: pymdown-extensions>=10.0.0; extra == "docs"
Provides-Extra: reports
Provides-Extra: plots
Requires-Dist: upsetplot>=0.8; extra == "plots"
Requires-Dist: matplotlib-venn>=0.11; extra == "plots"
Provides-Extra: atlas
Requires-Dist: harmonypy>=0.0.9; extra == "atlas"
Requires-Dist: igraph>=0.10; extra == "atlas"
Provides-Extra: full
Requires-Dist: upsetplot>=0.8; extra == "full"
Requires-Dist: matplotlib-venn>=0.11; extra == "full"
Requires-Dist: harmonypy>=0.0.9; extra == "full"
Requires-Dist: igraph>=0.10; extra == "full"
Requires-Dist: tcrpeg>=1.0.0; extra == "full"
Requires-Dist: torch>=2.0.0; extra == "full"
Dynamic: license-file

# TCRsift

[![Tests](https://github.com/pirl-unc/tcrsift/actions/workflows/tests.yml/badge.svg)](https://github.com/pirl-unc/tcrsift/actions/workflows/tests.yml)
[![Documentation](https://github.com/pirl-unc/tcrsift/actions/workflows/docs.yml/badge.svg)](https://pirl.unc.edu/tcrsift/)
[![Coverage Status](https://coveralls.io/repos/github/pirl-unc/tcrsift/badge.svg)](https://coveralls.io/github/pirl-unc/tcrsift)
[![PyPI version](https://badge.fury.io/py/tcrsift.svg)](https://pypi.org/project/tcrsift/)

Prioritize T-cell receptor clonotypes from paired 10x Genomics single-cell VDJ
and gene-expression data for human (*Homo sapiens*) and mouse (*Mus
musculus*) studies. Standard Cell Ranger directories serve as input:
`cellranger vdj` supplies TCR contigs and clonotypes, and `cellranger count`
supplies gene expression for CD4/CD8 phenotyping, signature scoring, and
cell-type annotation (VDJ-only workflows are also supported).

TCRsift combines clonal abundance, T-cell lineage, gene-expression state
signatures, public TCR database matches (VDJdb, IEDB, CEDAR), sequence
generation probability (`Pgen`/`Ppost`), and optional TIL overlap to produce
auditable shortlists and full-length receptor constructs. None of these
signals predicts epitope specificity on its own; functional testing is still
required.

## Documentation & Benchmarks

- **Documentation home:** [pirl.unc.edu/tcrsift](https://pirl.unc.edu/tcrsift/)
- **Method overview:** [How TCRsift works](https://pirl.unc.edu/tcrsift/how-it-works/) · [Methods section](https://pirl.unc.edu/tcrsift/methods-section/)
- **Guides:** [Installation](https://pirl.unc.edu/tcrsift/getting-started/installation/) · [Quick Start](https://pirl.unc.edu/tcrsift/getting-started/quickstart/) · [Sample Sheets](https://pirl.unc.edu/tcrsift/getting-started/sample-sheets/) · [Culture Pipeline](https://pirl.unc.edu/tcrsift/user-guide/pipeline/) · [Filtering](https://pirl.unc.edu/tcrsift/user-guide/filtering/) · [Clone Prioritization](https://pirl.unc.edu/tcrsift/user-guide/til-signatures/) · [Single-Cell Atlas](https://pirl.unc.edu/tcrsift/user-guide/atlas/)
- **Reference:** [CLI Reference](https://pirl.unc.edu/tcrsift/user-guide/cli/) · [Python API](https://pirl.unc.edu/tcrsift/api/pipeline/) · [Release Notes](https://pirl.unc.edu/tcrsift/release-notes/)
- **Benchmarks:** [Overview & external comparisons](https://pirl.unc.edu/tcrsift/benchmarks-overview/) (`Scanpy`, `stitchr`, `OLGA`, multimer callers) · [Solid-tumor CD8 TIL](https://pirl.unc.edu/tcrsift/benchmarks/) · [Infectious disease & blood](https://pirl.unc.edu/tcrsift/benchmarks-infectious/) · [Paired blood-tumor, post-ACT & CD4 TIL](https://pirl.unc.edu/tcrsift/benchmarks-blood-cd4/) · [Murine models (`--species mouse`)](https://pirl.unc.edu/tcrsift/benchmarks-mouse/)

## Installation

```bash
pip install tcrsift
```

Optional extras (sequence assembly, Excel I/O, PDF reports, `oncoref` CTA
panels, and bundled NumPy k-mer `Pgen`/`Ppost` models are included in the base
install):

```bash
pip install "tcrsift[full]"     # All optional extras below
pip install "tcrsift[tcrpeg]"   # Deep autoregressive TCRpeg/PyTorch sequence probability
pip install "tcrsift[atlas]"    # Harmony + Leiden clustering (`tcrsift cells embed`)
pip install "tcrsift[plots]"    # UpSet and Venn set-overlap plots
```

See [Installation](https://pirl.unc.edu/tcrsift/getting-started/installation/)
for source installs and environment details.

## Quick Start

Create `samples.yaml` pointing to your Cell Ranger output directories (YAML and
CSV formats are both supported; see
[Sample Sheets](https://pirl.unc.edu/tcrsift/getting-started/sample-sheets/)):

```yaml
samples:
  - sample: "Patient1_Culture"
    vdj_dir: "/data/patient1/vdj"
    gex_dir: "/data/patient1/gex"
```

Run the antigen-stimulated culture pipeline (optionally fetch VDJdb/IEDB/CEDAR
and IMGT germlines once with `tcrsift data download`):

```bash
tcrsift data download
tcrsift run --sample-sheet samples.yaml --output-dir results/
```

Or rank clones by expression state in fresh TIL, blood, pleural effusion, or
marrow and assemble full-length `β-T2A-α` constructs in one command:

```bash
tcrsift prioritize til_samples.yaml -o candidates/ --context solid-tumor --assemble
```

### Python API

```python
import tcrsift

adata = tcrsift.load_samples("samples.yaml")
adata = tcrsift.phenotype_cells(adata)
clonotypes = tcrsift.aggregate_clonotypes(adata)
filtered = tcrsift.filter_clonotypes(clonotypes, method="threshold", tcell_type="cd8")
annotated = tcrsift.annotate_clonotypes(filtered, vdjdb_path="/path/to/vdjdb")
assembled = tcrsift.assemble_full_sequences(annotated, include_constant=True)
```

See [Quick Start](https://pirl.unc.edu/tcrsift/getting-started/quickstart/) and
the [Python API reference](https://pirl.unc.edu/tcrsift/api/pipeline/) for full
examples.

## Choose a Workflow

All workflows share loading, CD4/CD8 phenotyping, database annotation, and
construct assembly; only clonotype scoring changes with experimental design:

| Study design | Command | Guide |
| --- | --- | --- |
| Fresh TIL, blood, MPE, or marrow (paired VDJ + GEX, human or mouse) | `tcrsift prioritize samples.yaml -o out/ --context solid-tumor [--assemble]` | [Clone Prioritization](https://pirl.unc.edu/tcrsift/user-guide/til-signatures/) |
| Antigen-stimulated culture or short restimulation (with optional matched TIL) | `tcrsift run -s samples.yaml -o out/ [--method {threshold,logistic,stimulation}]` | [Culture Pipeline](https://pirl.unc.edu/tcrsift/user-guide/pipeline/) |
| Standalone full-length TCR construct assembly from a clone CSV | `tcrsift assemble -i clones.csv -o seqs.csv [--contigs-dir ...]` | [CLI Reference](https://pirl.unc.edu/tcrsift/user-guide/cli/#tcrsift-assemble) |
| Single-cell GEX QC, Harmony/UMAP/Leiden embedding, and cell typing | `tcrsift cells {qc,embed,annotate}` | [Single-Cell Atlas](https://pirl.unc.edu/tcrsift/user-guide/atlas/) |
| Reference database & IMGT germline cache management | `tcrsift data {list,download,clear}` | [CLI Reference](https://pirl.unc.edu/tcrsift/user-guide/cli/#tcrsift-data) |

Additional utilities (`match-til`, `til-clonotype`, `til-select`, `load-sct`,
`annotate-gex`, `unify`, `mnemonic`, `report`) are documented in the
[CLI Reference](https://pirl.unc.edu/tcrsift/user-guide/cli/).

## Architecture

```
Cell Ranger VDJ + GEX
  │
  ▼
1. Load & QC           (tcrsift load)       Paired α/β productive chains + GEX mito/UMI/CD3 QC
  │
  ▼
2. Phenotype & Clone   (phenotype/clonotype) CD4/CD8 lineage (FACS pre_sorted aware) + k-mer Pgen/Ppost
  │
  ├──► Ex vivo tissue/blood (`tcrsift prioritize`):
  │      3. Per-stratum signature scoring + size-matched random-group & hypergeometric calibration
  │      4. Priority-tiered round-robin shortlist + strict_ab DB / FOXP3 Treg / multimer audit
  │
  └──► Stimulated culture (`tcrsift run`):
         3. Expansion tiers (`threshold`/`logistic`) or paired control ΔAIM (`stimulation`) + TIL match
         4. Per-donor / per-method shortlist + VDJdb/IEDB/CEDAR specificity annotation
  │
  ▼
5. Construct Assembly  (`--assemble` / `tcrsift assemble`)
                       Donor-contig V(D)J + native leaders + canonical human/mouse TRAC/TRBC1/2
                       (with optional `--germline-vdj-fallback` + J->C parity correction)
```

- **Inputs:** Cell Ranger VDJ (`filtered_contig_annotations.csv`, optional
  `filtered_contig.fasta` / `consensus_annotations.csv`) and GEX
  (`filtered_feature_bc_matrix/` or `.h5`). Exact barcode matching with
  suffix-stripped fallback when needed.
- **Outputs:** Per-cell `AnnData` (`loaded.h5ad`, `phenotyped.h5ad`),
  clonotype tables (`data/clonotypes.csv`, `filtered_tier*.csv`, or
  `candidate_clones.csv` from `prioritize`), assembled sequences
  (`data/full_sequences.csv`, FASTA/PDF), summary plots, and `provenance.json`.

See [How TCRsift works](https://pirl.unc.edu/tcrsift/how-it-works/) and
[Filtering Strategies](https://pirl.unc.edu/tcrsift/user-guide/filtering/) for
algorithms, column schemas, and multi-donor/multi-method configuration.

## Contributing and License

See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines. Licensed
under the Apache License 2.0 ([LICENSE](LICENSE)).

## Citation

```bibtex
@software{tcrsift,
  author = {Rubinsteyn, Alex},
  title = {TCRsift: T-cell receptor clonotype prioritization from single-cell VDJ and gene-expression data},
  url = {https://github.com/pirl-unc/tcrsift},
  year = {2024}
}
```
