stcrpy 1.0.3__tar.gz → 1.0.6__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.
Files changed (101) hide show
  1. stcrpy-1.0.6/PKG-INFO +286 -0
  2. stcrpy-1.0.6/README.md +258 -0
  3. stcrpy-1.0.6/pyproject.toml +49 -0
  4. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/__init__.py +1 -1
  5. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_formats/tcr_formats.py +20 -1
  6. stcrpy-1.0.6/stcrpy/tcr_geometry/TCRAngle.py +177 -0
  7. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/Acoreset.txt +30 -0
  8. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/Bcoreset.txt +30 -0
  9. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/pcA.txt +3 -0
  10. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/pcB.txt +3 -0
  11. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/reference_A.pdb +31 -0
  12. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/reference_B.pdb +31 -0
  13. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/reference_D.pdb +31 -0
  14. stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/reference_G.pdb +31 -0
  15. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_interactions/TCRInteractionProfiler.py +8 -1
  16. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_methods/tcr_batch_operations.py +14 -10
  17. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_methods/tcr_methods.py +23 -22
  18. stcrpy-1.0.6/stcrpy/tcr_metrics/tcr_dockq.py +404 -0
  19. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/MHC.py +389 -4
  20. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/TCR.py +252 -0
  21. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/TCRParser.py +351 -189
  22. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/annotate.py +6 -1
  23. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/utils/region_definitions.py +9 -0
  24. stcrpy-1.0.6/stcrpy/tcr_processing/utils/symmetry_mates.py +96 -0
  25. stcrpy-1.0.6/stcrpy.egg-info/PKG-INFO +286 -0
  26. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy.egg-info/SOURCES.txt +12 -3
  27. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy.egg-info/requires.txt +7 -0
  28. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy.egg-info/top_level.txt +2 -0
  29. {stcrpy-1.0.3 → stcrpy-1.0.6}/test/test_tcr_datasets.py +11 -11
  30. stcrpy-1.0.6/test/test_tcr_formats.py +79 -0
  31. stcrpy-1.0.6/test/test_tcr_geometry.py +260 -0
  32. {stcrpy-1.0.3 → stcrpy-1.0.6}/test/test_tcr_interactions.py +21 -52
  33. stcrpy-1.0.6/test/test_tcr_methods.py +18 -0
  34. {stcrpy-1.0.3 → stcrpy-1.0.6}/test/test_tcr_metrics.py +48 -3
  35. stcrpy-1.0.6/test/test_tcr_processing.py +248 -0
  36. {stcrpy-1.0.3 → stcrpy-1.0.6}/test/test_tcr_sequence_operations.py +1 -1
  37. stcrpy-1.0.3/PKG-INFO +0 -173
  38. stcrpy-1.0.3/README.md +0 -145
  39. stcrpy-1.0.3/setup.py +0 -31
  40. stcrpy-1.0.3/stcrpy.egg-info/PKG-INFO +0 -173
  41. stcrpy-1.0.3/test/test_tcr_formats.py +0 -77
  42. stcrpy-1.0.3/test/test_tcr_geometry.py +0 -259
  43. stcrpy-1.0.3/test/test_tcr_methods.py +0 -18
  44. stcrpy-1.0.3/test/test_tcr_processing.py +0 -188
  45. {stcrpy-1.0.3 → stcrpy-1.0.6}/LICENCE +0 -0
  46. {stcrpy-1.0.3 → stcrpy-1.0.6}/examples/__init__.py +0 -0
  47. {stcrpy-1.0.3 → stcrpy-1.0.6}/examples/egnn.py +0 -0
  48. {stcrpy-1.0.3 → stcrpy-1.0.6}/setup.cfg +0 -0
  49. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_datasets/__init__.py +0 -0
  50. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_datasets/tcr_graph_dataset.py +0 -0
  51. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_datasets/tcr_selector.py +0 -0
  52. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_datasets/tcr_structure_dataset.py +0 -0
  53. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_datasets/utils.py +0 -0
  54. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_formats/__init__.py +0 -0
  55. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_formats/tcr_haddock.py +0 -0
  56. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/TCRCoM.py +0 -0
  57. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/TCRCoM_LICENCE +0 -0
  58. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/TCRDock.py +0 -0
  59. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/TCRGeom.py +0 -0
  60. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/TCRGeomFiltering.py +0 -0
  61. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/__init__.py +0 -0
  62. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/reference_data/__init__.py +0 -0
  63. /stcrpy-1.0.3/stcrpy/tcr_geometry/reference_data/reference_A.pdb → /stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/consensus_A.pdb +0 -0
  64. /stcrpy-1.0.3/stcrpy/tcr_geometry/reference_data/reference_B.pdb → /stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/consensus_B.pdb +0 -0
  65. /stcrpy-1.0.3/stcrpy/tcr_geometry/reference_data/reference_D.pdb → /stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/consensus_D.pdb +0 -0
  66. /stcrpy-1.0.3/stcrpy/tcr_geometry/reference_data/reference_G.pdb → /stcrpy-1.0.6/stcrpy/tcr_geometry/reference_data/consensus_G.pdb +0 -0
  67. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/reference_data/dock_reference_1_imgt_numbered.pdb +0 -0
  68. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/reference_data/dock_reference_2_imgt_numbered.pdb +0 -0
  69. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_geometry/reference_data/reference_data.py +0 -0
  70. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_interactions/PLIPParser.py +0 -0
  71. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_interactions/TCRpMHC_PLIP_Model_Parser.py +0 -0
  72. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_interactions/__init__.py +0 -0
  73. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_interactions/utils.py +0 -0
  74. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_methods/__init__.py +0 -0
  75. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_methods/tcr_reformatting.py +0 -0
  76. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_metrics/__init__.py +0 -0
  77. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_metrics/constants.py +0 -0
  78. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_metrics/tcr_interface_rmsd.py +0 -0
  79. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_metrics/tcr_rmsd.py +0 -0
  80. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_ml/__init__.py +0 -0
  81. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_ml/geometry_predictor.py +0 -0
  82. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/AGchain.py +0 -0
  83. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/Chemical_components.py +0 -0
  84. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/Entity.py +0 -0
  85. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/Fragment.py +0 -0
  86. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/Holder.py +0 -0
  87. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/MHCchain.py +0 -0
  88. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/Model.py +0 -0
  89. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/Select.py +0 -0
  90. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/TCRIO.py +0 -0
  91. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/TCRStructure.py +0 -0
  92. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/TCRchain.py +0 -0
  93. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/__init__.py +0 -0
  94. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/utils/__init__.py +0 -0
  95. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/utils/common.py +0 -0
  96. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/tcr_processing/utils/constants.py +0 -0
  97. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/utils/__init__.py +0 -0
  98. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy/utils/error_stream.py +0 -0
  99. {stcrpy-1.0.3 → stcrpy-1.0.6}/stcrpy.egg-info/dependency_links.txt +0 -0
  100. {stcrpy-1.0.3 → stcrpy-1.0.6}/test/test_annotations.py +0 -0
  101. {stcrpy-1.0.3 → stcrpy-1.0.6}/test/test_tcr_geometry_filters.py +0 -0
stcrpy-1.0.6/PKG-INFO ADDED
@@ -0,0 +1,286 @@
1
+ Metadata-Version: 2.4
2
+ Name: stcrpy
3
+ Version: 1.0.6
4
+ Summary: Set of methods to parse, annotate, and calculate features of TCR structures
5
+ Maintainer-email: Nele Quast <quast@stats.ox.ac.uk>
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENCE
9
+ License-File: stcrpy/tcr_geometry/TCRCoM_LICENCE
10
+ Requires-Dist: biopython
11
+ Requires-Dist: numpy==1.26.4
12
+ Requires-Dist: lxml
13
+ Requires-Dist: openbabel-wheel==3.1.1.21
14
+ Requires-Dist: rdkit
15
+ Requires-Dist: pyhmmer==0.11.4
16
+ Requires-Dist: anarci-mhc
17
+ Requires-Dist: pandas
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: scipy
20
+ Requires-Dist: requests
21
+ Requires-Dist: scikit-learn
22
+ Requires-Dist: DockQ
23
+ Provides-Extra: ml-datasets
24
+ Requires-Dist: einops; extra == "ml-datasets"
25
+ Requires-Dist: torch; extra == "ml-datasets"
26
+ Requires-Dist: torch_geometric; extra == "ml-datasets"
27
+ Dynamic: license-file
28
+
29
+
30
+
31
+ <img src="./stcrpy_logo.png" alt="drawing" width="300"/>
32
+
33
+
34
+ # STCRpy
35
+ [![stcrpy installation](https://github.com/npqst/STCRpy/actions/workflows/conda-workflow.yml/badge.svg)](https://github.com/npqst/STCRpy/actions/workflows/conda-workflow.yml)
36
+ [![stcrpy unittests](https://github.com/npqst/STCRpy/actions/workflows/unittest-workflow.yml/badge.svg)](https://github.com/npqst/STCRpy/actions/workflows/unittest-workflow.yml)
37
+ [![stcrpy_docs](https://readthedocs.org/projects/stcrpy/badge/?version=latest)](https://stcrpy.readthedocs.io/en/latest/)
38
+
39
+
40
+ Structural TCR python (STCRpy) is a software suite for analysing and processing T-cell receptor structures.
41
+
42
+ Please feel free to reach out with any comments or feedback.
43
+
44
+ Under review, please cite:
45
+
46
+ **Quast, N. , Deane, C., & Raybould, M. (2025). STCRpy: a software suite for TCR:pMHC structure parsing, interaction profiling, and machine learning dataset preparation. Bioinformatics. [https://doi.org/10.1093/bioinformatics/btaf566](https://doi.org/10.1093/bioinformatics/btaf566)**
47
+
48
+ <img src="./stcrpy_main_fig.png" alt="drawing" width="1500"/>
49
+
50
+
51
+
52
+ # Installation
53
+
54
+ ## TL;DR installation
55
+ ```
56
+ pip install stcrpy
57
+ pip install plip
58
+ conda install pymol-open-source -y
59
+ ANARCI --build_models # this step will take a few minutes
60
+ ```
61
+
62
+ ## Step by step installation
63
+ We recommend installing STCRpy in a [conda](https://www.anaconda.com/docs/getting-started/miniconda/install#macos-linux-installation) (or [mamba](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html)) environment using python 3.9 to 3.12. You can also use a python virtual environment if you do not need pymol visualisations.
64
+
65
+ <details> <summary>conda</summary>
66
+
67
+ ```
68
+ conda create -n stcrpy_env python==3.12 -y
69
+ conda activate stcrpy_env
70
+ ```
71
+
72
+ </details>
73
+ <details> <summary>mamba</summary>
74
+
75
+ ```
76
+ mamba create -n stcrpy_env python==3.12 -y
77
+ mamba activate stcrpy_env
78
+ ```
79
+
80
+ </details>
81
+ <details> <summary>venv</summary>
82
+
83
+ ```
84
+ python -m venv stcrpy_env
85
+ source stcrpy_env/bin/activate
86
+ ```
87
+
88
+ </details>
89
+
90
+
91
+ The core functionality of STCRpy can be installed as follows:
92
+ ```
93
+ pip install stcrpy
94
+ ```
95
+
96
+ After installing stcrpy, the anarci HMM models must be built to enable annotation.
97
+ ```
98
+ ANARCI --build_models # this step will take a few minutes
99
+ ```
100
+
101
+ To enable interaction profiling, install PLIP (Adasme et. al., 2021):
102
+ ```
103
+ pip install plip
104
+ ```
105
+
106
+ 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.
107
+ ```
108
+ conda install pymol-open-source -y
109
+ ```
110
+
111
+ To generate pytorch and pytorch-geometric compatible datasets (see the [pytorch docs](https://pytorch.org/get-started/locally/) for hardware specific instructions):
112
+ ```
113
+ pip install stcrpy[ml_datasets]
114
+ ```
115
+
116
+ > Note that the installs for pytorch can be platform specific.
117
+ > If errors are ecountered here it is best to manually install the depedencies following the [pytorch installation docs](https://pytorch.org/get-started/locally/).
118
+ > For example:
119
+ > ```
120
+ > pip install torch --index-url https://download.pytorch.org/whl/cpu
121
+ > pip install torch_geometric
122
+ > ```
123
+ > This installs the CPU version of pytorch (for GPU / CUDA versions follow the install [pytorch installation docs](https://pytorch.org/get-started/locally/)).
124
+ >
125
+ > The EGNN example also uses `einops`. Which can be manually installed as follows:
126
+ > ```
127
+ > pip install einops
128
+ > ```
129
+
130
+ # Documentation
131
+ STCRpy [documentation](https://stcrpy.readthedocs.io/en/latest/) is hosted on ReadtheDocs.
132
+
133
+ # Examples
134
+ 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](https://stcrpy.readthedocs.io/en/latest/stcrpy.tcr_processing.html#stcrpy.tcr_processing.TCR.TCR)). TCR objects are associated with their MHC and antigen if these are presented in the structure.
135
+
136
+ A notebook with examples can be found under [examples/STCRpy_examples.ipynb](./examples/STCRpy_examples.ipynb)
137
+
138
+ First import STCRpy:
139
+ ```
140
+ import stcrpy
141
+ ```
142
+
143
+ ### To fetch a TCR structure from STCRDab or the PDB:
144
+ ```
145
+ multiple_tcrs = stcrpy.fetch_TCRs("8gvb")
146
+ ```
147
+ This will return a list of all of the TCR structures found in the PDB file, represented as TCR structure objects.
148
+
149
+ ### To load a TCR structure from a PDB or MMCIF file:
150
+ ```
151
+ tcr = stcrpy.load_TCR("filename.{pdb, cif}")
152
+ ```
153
+
154
+ ### To load multiple TCR structures from a list of files at once:
155
+ ```
156
+ multiple_tcrs = stcrpy.load_TCRs([file_1, file_2, file_3])
157
+ ```
158
+
159
+ ### To save a TCR object to PDB or MMCIF files:
160
+ ```
161
+ tcr.save(filename.{pdb, cif}) # save the TCR and it's associated MHC and antigen
162
+ tcr.save(filename.{pdb, cif}, TCR_only=True) # save the TCR only
163
+ ```
164
+
165
+ ### To calculate the TCR to pMHC geometry:
166
+ ```
167
+ tcr.calculate_geometry() # change the 'mode' keyword argument to change the geometry calculation method. See paper / documentation for details.
168
+ ```
169
+
170
+ ### To score the TCR to pMHC geometry:
171
+ ```
172
+ tcr.score_docking_geometry()
173
+ ```
174
+
175
+ ### To profile interactions:
176
+ ```
177
+ tcr.profile_peptide_interactions() # interaction profiling parameters can be adjusted, see documentation for details
178
+ ```
179
+
180
+ ### To visualise interactions:
181
+ ```
182
+ tcr.visualise_interactions()
183
+ ```
184
+
185
+ ### To run full analysis on a set of TCR structures:
186
+ ```
187
+ from stcrpy.tcr_methods.tcr_batch_operations import analyse_tcrs
188
+ germlines_and_alleles_df, geometries_df, interactions_df = analyse_tcrs(list_or_dict_of_files)
189
+ ```
190
+
191
+ ### To generate graph datasets:
192
+ ```
193
+ dataset = TCRGraphDataset(
194
+ root=PATH_TO_DATASET,
195
+ data_paths=PATH_TO_TCR_FILES
196
+ )
197
+ ```
198
+
199
+ ### To calculate TCR prediction metrics such as RMSD, interface RMSD (of the TCR:pMHC interface) or DockQ scores:
200
+
201
+ ```
202
+ # RMSD
203
+ from stcrpy.tcr_metrics import RMSD
204
+
205
+ rmsd_calculator = RMSD()
206
+ 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.
207
+
208
+ # To calculate RMSD for a set of predictions against a set of reference structures from files:
209
+ files = list(zip(prediction_files, reference_files))
210
+ rmsd_df = rmsd_calculator.rmsd_from_files(files)
211
+
212
+
213
+
214
+ # Interface RMSD of TCR:pMHC interface
215
+ from stcrpy.tcr_metrics import InterfaceRMSD
216
+
217
+ interface_rmsd_calculator = InterfaceRMSD()
218
+ irmsds = interface_rmsd_calculator.get_interface_rmsd(tcr, reference_tcr)
219
+
220
+ # DockQ
221
+ from stcrpy.tcr_metrics.tcr_dockq import TCRDockQ
222
+
223
+ 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
224
+ 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
225
+
226
+ ```
227
+
228
+ ### Torsion angles and internal coordinates
229
+ STCRpy builds upon the Biopython PDB module, and you can calculate the internal coordinates, such as backbone torsion angles, using the [`internal_coordinates` function](https://biopython.org/docs/dev/api/Bio.PDB.internal_coords.html).
230
+
231
+ ```
232
+ # internal coordinate calculations should be made per chain
233
+ for c in tcr.get_chains():
234
+ c.atom_to_internal_coordinates() # calculate the internal coordinates
235
+
236
+ # internal coordinates can be accessed per residue:
237
+ res = next(tcr.get_residues())
238
+ res.internal_coord.get_angle("psi") # retrieve angles via angle keys
239
+ ```
240
+
241
+ ### Domain angles between TCR chains
242
+ 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)](https://academic.oup.com/peds/article/26/10/611/1509255).
243
+ ```
244
+ tcr.get_TCR_angles()
245
+
246
+ # returns dictionary of TCR domain angles and measurements.
247
+ # For example:
248
+ # {
249
+ # 'BA': -56.72234454750631,
250
+ # 'BC1': 122.55277240895967,
251
+ # 'AC1': 73.96532018128327,
252
+ # 'BC2': 82.63524566165464,
253
+ # 'AC2': 99.60327202896609,
254
+ # 'dc': np.float64(15.606353954437227)
255
+ # }
256
+
257
+ ```
258
+
259
+
260
+ # Symmetry mate handling
261
+ Some TCR:pMHC crystals are formed of repeating cell units in which the TCR and the antigen do not directly contact.
262
+ STCRpy generates symmetry mates in these cases to pair pMHC with TCRs in the structure.
263
+ Note that symmetry mate generation requires pymol to be installed. By default, symmetry mate generation is enabled, however, it can be toggled by setting:
264
+ `include_symmetry_mates=False` in `get_tcr_structure`.
265
+
266
+ ## Example:
267
+ ```
268
+ tcr_6ulr_paired_antigen = stcrpy.fetch_TCRs("6ulr")
269
+ tcr_6ulr_no_antigen = stcrpy.fetch_TCRs("6ulr", include_symmetry_mates=False) # does not generate symmetry mates
270
+
271
+ ```
272
+
273
+
274
+
275
+ # Limitations
276
+
277
+ ## Connected peptide chains
278
+ 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.
279
+
280
+ ## Gamma-Delta TCR geometry
281
+ STCRpy supports gamma-delta TCR parsing, interaction profiling and visusalisation, but is not currently configured to calculate gd-TCR geometry.
282
+
283
+ ## MHC Class II geometry scoring
284
+ 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.
285
+
286
+
stcrpy-1.0.6/README.md ADDED
@@ -0,0 +1,258 @@
1
+
2
+
3
+ <img src="./stcrpy_logo.png" alt="drawing" width="300"/>
4
+
5
+
6
+ # STCRpy
7
+ [![stcrpy installation](https://github.com/npqst/STCRpy/actions/workflows/conda-workflow.yml/badge.svg)](https://github.com/npqst/STCRpy/actions/workflows/conda-workflow.yml)
8
+ [![stcrpy unittests](https://github.com/npqst/STCRpy/actions/workflows/unittest-workflow.yml/badge.svg)](https://github.com/npqst/STCRpy/actions/workflows/unittest-workflow.yml)
9
+ [![stcrpy_docs](https://readthedocs.org/projects/stcrpy/badge/?version=latest)](https://stcrpy.readthedocs.io/en/latest/)
10
+
11
+
12
+ Structural TCR python (STCRpy) is a software suite for analysing and processing T-cell receptor structures.
13
+
14
+ Please feel free to reach out with any comments or feedback.
15
+
16
+ Under review, please cite:
17
+
18
+ **Quast, N. , Deane, C., & Raybould, M. (2025). STCRpy: a software suite for TCR:pMHC structure parsing, interaction profiling, and machine learning dataset preparation. Bioinformatics. [https://doi.org/10.1093/bioinformatics/btaf566](https://doi.org/10.1093/bioinformatics/btaf566)**
19
+
20
+ <img src="./stcrpy_main_fig.png" alt="drawing" width="1500"/>
21
+
22
+
23
+
24
+ # Installation
25
+
26
+ ## TL;DR installation
27
+ ```
28
+ pip install stcrpy
29
+ pip install plip
30
+ conda install pymol-open-source -y
31
+ ANARCI --build_models # this step will take a few minutes
32
+ ```
33
+
34
+ ## Step by step installation
35
+ We recommend installing STCRpy in a [conda](https://www.anaconda.com/docs/getting-started/miniconda/install#macos-linux-installation) (or [mamba](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html)) environment using python 3.9 to 3.12. You can also use a python virtual environment if you do not need pymol visualisations.
36
+
37
+ <details> <summary>conda</summary>
38
+
39
+ ```
40
+ conda create -n stcrpy_env python==3.12 -y
41
+ conda activate stcrpy_env
42
+ ```
43
+
44
+ </details>
45
+ <details> <summary>mamba</summary>
46
+
47
+ ```
48
+ mamba create -n stcrpy_env python==3.12 -y
49
+ mamba activate stcrpy_env
50
+ ```
51
+
52
+ </details>
53
+ <details> <summary>venv</summary>
54
+
55
+ ```
56
+ python -m venv stcrpy_env
57
+ source stcrpy_env/bin/activate
58
+ ```
59
+
60
+ </details>
61
+
62
+
63
+ The core functionality of STCRpy can be installed as follows:
64
+ ```
65
+ pip install stcrpy
66
+ ```
67
+
68
+ After installing stcrpy, the anarci HMM models must be built to enable annotation.
69
+ ```
70
+ ANARCI --build_models # this step will take a few minutes
71
+ ```
72
+
73
+ To enable interaction profiling, install PLIP (Adasme et. al., 2021):
74
+ ```
75
+ pip install plip
76
+ ```
77
+
78
+ 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.
79
+ ```
80
+ conda install pymol-open-source -y
81
+ ```
82
+
83
+ To generate pytorch and pytorch-geometric compatible datasets (see the [pytorch docs](https://pytorch.org/get-started/locally/) for hardware specific instructions):
84
+ ```
85
+ pip install stcrpy[ml_datasets]
86
+ ```
87
+
88
+ > Note that the installs for pytorch can be platform specific.
89
+ > If errors are ecountered here it is best to manually install the depedencies following the [pytorch installation docs](https://pytorch.org/get-started/locally/).
90
+ > For example:
91
+ > ```
92
+ > pip install torch --index-url https://download.pytorch.org/whl/cpu
93
+ > pip install torch_geometric
94
+ > ```
95
+ > This installs the CPU version of pytorch (for GPU / CUDA versions follow the install [pytorch installation docs](https://pytorch.org/get-started/locally/)).
96
+ >
97
+ > The EGNN example also uses `einops`. Which can be manually installed as follows:
98
+ > ```
99
+ > pip install einops
100
+ > ```
101
+
102
+ # Documentation
103
+ STCRpy [documentation](https://stcrpy.readthedocs.io/en/latest/) is hosted on ReadtheDocs.
104
+
105
+ # Examples
106
+ 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](https://stcrpy.readthedocs.io/en/latest/stcrpy.tcr_processing.html#stcrpy.tcr_processing.TCR.TCR)). TCR objects are associated with their MHC and antigen if these are presented in the structure.
107
+
108
+ A notebook with examples can be found under [examples/STCRpy_examples.ipynb](./examples/STCRpy_examples.ipynb)
109
+
110
+ First import STCRpy:
111
+ ```
112
+ import stcrpy
113
+ ```
114
+
115
+ ### To fetch a TCR structure from STCRDab or the PDB:
116
+ ```
117
+ multiple_tcrs = stcrpy.fetch_TCRs("8gvb")
118
+ ```
119
+ This will return a list of all of the TCR structures found in the PDB file, represented as TCR structure objects.
120
+
121
+ ### To load a TCR structure from a PDB or MMCIF file:
122
+ ```
123
+ tcr = stcrpy.load_TCR("filename.{pdb, cif}")
124
+ ```
125
+
126
+ ### To load multiple TCR structures from a list of files at once:
127
+ ```
128
+ multiple_tcrs = stcrpy.load_TCRs([file_1, file_2, file_3])
129
+ ```
130
+
131
+ ### To save a TCR object to PDB or MMCIF files:
132
+ ```
133
+ tcr.save(filename.{pdb, cif}) # save the TCR and it's associated MHC and antigen
134
+ tcr.save(filename.{pdb, cif}, TCR_only=True) # save the TCR only
135
+ ```
136
+
137
+ ### To calculate the TCR to pMHC geometry:
138
+ ```
139
+ tcr.calculate_geometry() # change the 'mode' keyword argument to change the geometry calculation method. See paper / documentation for details.
140
+ ```
141
+
142
+ ### To score the TCR to pMHC geometry:
143
+ ```
144
+ tcr.score_docking_geometry()
145
+ ```
146
+
147
+ ### To profile interactions:
148
+ ```
149
+ tcr.profile_peptide_interactions() # interaction profiling parameters can be adjusted, see documentation for details
150
+ ```
151
+
152
+ ### To visualise interactions:
153
+ ```
154
+ tcr.visualise_interactions()
155
+ ```
156
+
157
+ ### To run full analysis on a set of TCR structures:
158
+ ```
159
+ from stcrpy.tcr_methods.tcr_batch_operations import analyse_tcrs
160
+ germlines_and_alleles_df, geometries_df, interactions_df = analyse_tcrs(list_or_dict_of_files)
161
+ ```
162
+
163
+ ### To generate graph datasets:
164
+ ```
165
+ dataset = TCRGraphDataset(
166
+ root=PATH_TO_DATASET,
167
+ data_paths=PATH_TO_TCR_FILES
168
+ )
169
+ ```
170
+
171
+ ### To calculate TCR prediction metrics such as RMSD, interface RMSD (of the TCR:pMHC interface) or DockQ scores:
172
+
173
+ ```
174
+ # RMSD
175
+ from stcrpy.tcr_metrics import RMSD
176
+
177
+ rmsd_calculator = RMSD()
178
+ 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.
179
+
180
+ # To calculate RMSD for a set of predictions against a set of reference structures from files:
181
+ files = list(zip(prediction_files, reference_files))
182
+ rmsd_df = rmsd_calculator.rmsd_from_files(files)
183
+
184
+
185
+
186
+ # Interface RMSD of TCR:pMHC interface
187
+ from stcrpy.tcr_metrics import InterfaceRMSD
188
+
189
+ interface_rmsd_calculator = InterfaceRMSD()
190
+ irmsds = interface_rmsd_calculator.get_interface_rmsd(tcr, reference_tcr)
191
+
192
+ # DockQ
193
+ from stcrpy.tcr_metrics.tcr_dockq import TCRDockQ
194
+
195
+ 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
196
+ 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
197
+
198
+ ```
199
+
200
+ ### Torsion angles and internal coordinates
201
+ STCRpy builds upon the Biopython PDB module, and you can calculate the internal coordinates, such as backbone torsion angles, using the [`internal_coordinates` function](https://biopython.org/docs/dev/api/Bio.PDB.internal_coords.html).
202
+
203
+ ```
204
+ # internal coordinate calculations should be made per chain
205
+ for c in tcr.get_chains():
206
+ c.atom_to_internal_coordinates() # calculate the internal coordinates
207
+
208
+ # internal coordinates can be accessed per residue:
209
+ res = next(tcr.get_residues())
210
+ res.internal_coord.get_angle("psi") # retrieve angles via angle keys
211
+ ```
212
+
213
+ ### Domain angles between TCR chains
214
+ 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)](https://academic.oup.com/peds/article/26/10/611/1509255).
215
+ ```
216
+ tcr.get_TCR_angles()
217
+
218
+ # returns dictionary of TCR domain angles and measurements.
219
+ # For example:
220
+ # {
221
+ # 'BA': -56.72234454750631,
222
+ # 'BC1': 122.55277240895967,
223
+ # 'AC1': 73.96532018128327,
224
+ # 'BC2': 82.63524566165464,
225
+ # 'AC2': 99.60327202896609,
226
+ # 'dc': np.float64(15.606353954437227)
227
+ # }
228
+
229
+ ```
230
+
231
+
232
+ # Symmetry mate handling
233
+ Some TCR:pMHC crystals are formed of repeating cell units in which the TCR and the antigen do not directly contact.
234
+ STCRpy generates symmetry mates in these cases to pair pMHC with TCRs in the structure.
235
+ Note that symmetry mate generation requires pymol to be installed. By default, symmetry mate generation is enabled, however, it can be toggled by setting:
236
+ `include_symmetry_mates=False` in `get_tcr_structure`.
237
+
238
+ ## Example:
239
+ ```
240
+ tcr_6ulr_paired_antigen = stcrpy.fetch_TCRs("6ulr")
241
+ tcr_6ulr_no_antigen = stcrpy.fetch_TCRs("6ulr", include_symmetry_mates=False) # does not generate symmetry mates
242
+
243
+ ```
244
+
245
+
246
+
247
+ # Limitations
248
+
249
+ ## Connected peptide chains
250
+ 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.
251
+
252
+ ## Gamma-Delta TCR geometry
253
+ STCRpy supports gamma-delta TCR parsing, interaction profiling and visusalisation, but is not currently configured to calculate gd-TCR geometry.
254
+
255
+ ## MHC Class II geometry scoring
256
+ 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.
257
+
258
+
@@ -0,0 +1,49 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "stcrpy"
7
+ version = "1.0.6"
8
+ description = "Set of methods to parse, annotate, and calculate features of TCR structures"
9
+ readme = "README.md"
10
+ license-files = [
11
+ "LICENCE",
12
+ "stcrpy/tcr_geometry/TCRCoM_LICENCE",
13
+ ]
14
+ maintainers = [
15
+ {name = "Nele Quast", email = "quast@stats.ox.ac.uk"}
16
+ ]
17
+ requires-python = ">=3.10"
18
+ dependencies = [
19
+ "biopython",
20
+ "numpy==1.26.4", # required by DockQ
21
+ "lxml",
22
+ "openbabel-wheel==3.1.1.21",
23
+ "rdkit",
24
+ "pyhmmer==0.11.4", # fix pyhmmer version to prevent string encoding bu. TODO:fix this within anarci-mhc directly and redeploy
25
+ "anarci-mhc",
26
+ "pandas",
27
+ "matplotlib",
28
+ "scipy",
29
+ "requests",
30
+ "scikit-learn",
31
+ "DockQ",
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ ml_datasets = [
36
+ "einops",
37
+ "torch",
38
+ "torch_geometric",
39
+ ]
40
+
41
+ [tool.setuptools]
42
+ include-package-data = true
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["."]
46
+ exclude = ["test", "test.*"]
47
+
48
+ [tool.setuptools.package-data]
49
+ stcrpy = ["tcr_geometry/reference_data/*", ]
@@ -2,4 +2,4 @@ from .tcr_processing.TCRParser import TCRParser
2
2
  from .tcr_processing.TCRIO import TCRIO
3
3
  from .tcr_geometry.TCRDock import TCRDock
4
4
  from .tcr_geometry.TCRGeom import TCRGeom
5
- from .tcr_methods.tcr_methods import load_TCRs, fetch_TCR, yield_TCRs, load_TCR
5
+ from .tcr_methods.tcr_methods import load_TCRs, fetch_TCRs, yield_TCRs, load_TCR
@@ -99,7 +99,7 @@ def get_sequences(
99
99
  for chain in entity.get_chains()
100
100
  }
101
101
  except AttributeError as e:
102
- if entity.level == "C":
102
+ if entity.level == "C" or entity.level == "F": # covers chains and fragments
103
103
  sequences = {
104
104
  entity.id: seq1(
105
105
  "".join(
@@ -112,3 +112,22 @@ def get_sequences(
112
112
  if amino_acids_only:
113
113
  sequences = {k: seq.replace("X", "") for k, seq in sequences.items()}
114
114
  return sequences
115
+
116
+
117
+ def merge_chains(chains, new_chain_id=None):
118
+ from Bio import PDB
119
+
120
+ if new_chain_id is None:
121
+ new_chain_id = f"{chains[0].id}_{chains[1].id}"
122
+ new_chain = PDB.Chain.Chain(new_chain_id)
123
+ new_res_id = 1
124
+
125
+ for chain in chains:
126
+ for residue in chain.get_residues():
127
+ new_residue = residue.copy()
128
+ new_residue.id = (" ", new_res_id, " ")
129
+
130
+ new_chain.add(new_residue)
131
+ new_res_id += 1
132
+
133
+ return new_chain