Set of methods to parse, annotate, and calculate features of TCR structures
Project description
STCRpy
Structural TCR python (STCRpy) is a software suite for analysing and processing T-cell receptor structures.
Please feel free to reach out with any comments or feedback.
Under review, please cite:
Quast, N. , Deane, C., & Raybould, M. (2025). STCRpy: a software suite for TCR:pMHC structure parsing, interaction profiling, and machine learning dataset preparation. BioRxiv. https://doi.org/10.1101/2025.04.25.650667
Installation
TL;DR installation
pip install stcrpy
pip install plip
conda install pymol-open-source -y
ANARCI --build_models # this step will take a few minutes
Step by step installation
We recommend installing STCRpy in a conda (or mamba) environment using python 3.9 to 3.12. You can also use a python virtual environment if you do not need pymol visualisations.
conda
conda create -n stcrpy_env python==3.12 -y
conda activate stcrpy_env
mamba
mamba create -n stcrpy_env python==3.12 -y
mamba activate stcrpy_env
venv
python -m venv stcrpy_env
source stcrpy_env/bin/activate
The core functionality of STCRpy can be installed as follows:
pip install stcrpy
After installing stcrpy, the anarci HMM models must be built to enable annotation.
ANARCI --build_models # this step will take a few minutes
To enable interaction profiling, install PLIP (Adasme et. al., 2021):
pip install plip
To enable pymol visualisations, install pymol open source locally within the environment. Unfortunately, pymol currently needs to be installed even if you already have a pymol version. Be sure to install pymol within a managed conda (or mamba) environment to prevent interference with any existing versions.
conda install pymol-open-source -y
To generate pytorch and pytorch-geometric compatible datasets (see the pytorch docs for hardware specific instructions):
pip install stcrpy[ml_datasets]
Note that the installs for pytorch can be platform specific. If errors are ecountered here it is best to manually install the depedencies following the pytorch installation docs. For example:
pip install torch --index-url https://download.pytorch.org/whl/cpu pip install torch_geometricThis installs the CPU version of pytorch (for GPU / CUDA versions follow the install pytorch installation docs).
The EGNN example also uses
einops. Which can be manually installed as follows:pip install einops
Documentation
STCRpy documentation is hosted on ReadtheDocs.
Examples
STCRpy generates and operates on TCR structure objects. The majority of the API can be accessed through functions of the format: tcr.some_stcrpy_function(). (See TCR object docs here). TCR objects are associated with their MHC and antigen if these are presented in the structure.
A notebook with examples can be found under examples/STCRpy_examples.ipynb
First import STCRpy:
import stcrpy
To fetch a TCR structure from STCRDab or the PDB:
multiple_tcrs = stcrpy.fetch_TCRs("8gvb")
This will return a list of all of the TCR structures found in the PDB file, represented as TCR structure objects.
To load a TCR structure from a PDB or MMCIF file:
tcr = stcrpy.load_TCR("filename.{pdb, cif}")
To load multiple TCR structures from a list of files at once:
multiple_tcrs = stcrpy.load_TCRs([file_1, file_2, file_3])
To save a TCR object to PDB or MMCIF files:
tcr.save(filename.{pdb, cif}) # save the TCR and it's associated MHC and antigen
tcr.save(filename.{pdb, cif}, TCR_only=True) # save the TCR only
To calculate the TCR to pMHC geometry:
tcr.calculate_geometry() # change the 'mode' keyword argument to change the geometry calculation method. See paper / documentation for details.
To score the TCR to pMHC geometry:
tcr.score_docking_geometry()
To profile interactions:
tcr.profile_peptide_interactions() # interaction profiling parameters can be adjusted, see documentation for details
To visualise interactions:
tcr.visualise_interactions()
To run full analysis on a set of TCR structures:
from stcrpy.tcr_methods.tcr_batch_operations import analyse_tcrs
germlines_and_alleles_df, geometries_df, interactions_df = analyse_tcrs(list_or_dict_of_files)
To generate graph datasets:
dataset = TCRGraphDataset(
root=PATH_TO_DATASET,
data_paths=PATH_TO_TCR_FILES
)
To calculate TCR prediction metrics such as RMSD, interface RMSD (of the TCR:pMHC interface) or DockQ scores:
# RMSD
from stcrpy.tcr_metrics import RMSD
rmsd_calculator = RMSD()
rmsd = rmsd_calculator.calculate_rmsd(pred_tcr, reference_tcr, save_alignment=False) # Calculates the RMSD of each region of the TCR. To check the alignment set save_alignment to True.
# To calculate RMSD for a set of predictions against a set of reference structures from files:
files = list(zip(prediction_files, reference_files))
rmsd_df = rmsd_calculator.rmsd_from_files(files)
# Interface RMSD of TCR:pMHC interface
from stcrpy.tcr_metrics import InterfaceRMSD
interface_rmsd_calculator = InterfaceRMSD()
irmsds = interface_rmsd_calculator.get_interface_rmsd(tcr, reference_tcr)
# DockQ
from stcrpy.tcr_metrics.tcr_dockq import TCRDockQ
dockq_calculator = TCRDockQ() # by default this will merge the TCR and pMHC chains and calculate DockQ of the complete TCR:pMHC interface. To calculate DockQ scores per chain, use TCR_pMHC_interface=False
dockq_results = dockq_calculator.tcr_dockq(tcr, reference_tcr, save_merged_complex=False) # to investigate the merged TCR:pMHC structure set save_merged_complex=True
Torsion angles and internal coordinates
STCRpy builds upon the Biopython PDB module, and you can calculate the internal coordinates, such as backbone torsion angles, using the internal_coordinates function.
# internal coordinate calculations should be made per chain
for c in tcr.get_chains():
c.atom_to_internal_coordinates() # calculate the internal coordinates
# internal coordinates can be accessed per residue:
res = next(tcr.get_residues())
res.internal_coord.get_angle("psi") # retrieve angles via angle keys
Domain angles between TCR chains
STCRpy can be used to calculate the geometry and angles between the TCR variable domains of abTCRs and gdTCRs. This follows the ABangle implementation (Dunbar et al. 2013).
tcr.get_TCR_angles()
# returns dictionary of TCR domain angles and measurements.
# For example:
# {
# 'BA': -56.72234454750631,
# 'BC1': 122.55277240895967,
# 'AC1': 73.96532018128327,
# 'BC2': 82.63524566165464,
# 'AC2': 99.60327202896609,
# 'dc': np.float64(15.606353954437227)
# }
Symmetry mate handling
Some TCR:pMHC crystals are formed of repeating cell units in which the TCR and the antigen do not directly contact.
STCRpy generates symmetry mates in these cases to pair pMHC with TCRs in the structure.
Note that symmetry mate generation requires pymol to be installed. By default, symmetry mate generation is enabled, however, it can be toggled by setting:
include_symmetry_mates=False in get_tcr_structure.
Example:
tcr_6ulr_paired_antigen = stcrpy.fetch_TCRs("6ulr")
tcr_6ulr_no_antigen = stcrpy.fetch_TCRs("6ulr", include_symmetry_mates=False) # does not generate symmetry mates
Limitations
Connected peptide chains
STCRpy is currently not configured to handle cases where the antigen peptide is connected to the TCR or MHC chain - this is primarily because the parsing pipeline operates on chain objects and it can be tricky to consistently separate the peptide segment from the remainder of the TCR chain. A known case is PDB code 6MNO.
Gamma-Delta TCR geometry
STCRpy supports gamma-delta TCR parsing, interaction profiling and visusalisation, but is not currently configured to calculate gd-TCR geometry.
MHC Class II geometry scoring
STCRpy can be used to calculate and characterise the geometries of TCRs to MHC class II antigen, however, due to the smaller number of complexes we have not fit parametric distributions to the geometry features, which means it is not possible to calculate a geometry score.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stcrpy-1.0.5.tar.gz.
File metadata
- Download URL: stcrpy-1.0.5.tar.gz
- Upload date:
- Size: 764.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fca1dec96b127e4e56e1577c8957d2b9610f7fed0d38c30a1ed93d9bafc694a
|
|
| MD5 |
661cea3d6e089dbe02b761e5f94570dd
|
|
| BLAKE2b-256 |
67184cd831bc53a856426cc072ceb5ef47c8b4592c301ce94a3b63739f945629
|
Provenance
The following attestation bundles were made for stcrpy-1.0.5.tar.gz:
Publisher:
release.yml on oxpig/STCRpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stcrpy-1.0.5.tar.gz -
Subject digest:
7fca1dec96b127e4e56e1577c8957d2b9610f7fed0d38c30a1ed93d9bafc694a - Sigstore transparency entry: 473830748
- Sigstore integration time:
-
Permalink:
oxpig/STCRpy@9b8368f4d35ccc5f209fa5f3254d392df3412e65 -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/oxpig
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9b8368f4d35ccc5f209fa5f3254d392df3412e65 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stcrpy-1.0.5-py3-none-any.whl.
File metadata
- Download URL: stcrpy-1.0.5-py3-none-any.whl
- Upload date:
- Size: 785.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d64e307212a13b88b7ff33901609ddac69c8a372b3539d15ae3573fb051287b
|
|
| MD5 |
0e0bc74d577a312251370acdef4f18d3
|
|
| BLAKE2b-256 |
084e454659d073d5957abba6e5b937f6eae81debfdd72727e029101de0fc126f
|
Provenance
The following attestation bundles were made for stcrpy-1.0.5-py3-none-any.whl:
Publisher:
release.yml on oxpig/STCRpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stcrpy-1.0.5-py3-none-any.whl -
Subject digest:
9d64e307212a13b88b7ff33901609ddac69c8a372b3539d15ae3573fb051287b - Sigstore transparency entry: 473830766
- Sigstore integration time:
-
Permalink:
oxpig/STCRpy@9b8368f4d35ccc5f209fa5f3254d392df3412e65 -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/oxpig
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9b8368f4d35ccc5f209fa5f3254d392df3412e65 -
Trigger Event:
push
-
Statement type: