stcrpy.tcr_geometry package

Subpackages

Submodules

stcrpy.tcr_geometry.TCRCoM module

class stcrpy.tcr_geometry.TCRCoM.MHCII_TCRCoM[source]

Bases: TCRCoM

get_filtered_MHC_residues(tcr: TCR) list[<module 'Bio.PDB.Residue' from '/home/quast/miniconda3/envs/test-stcrpy/lib/python3.12/site-packages/Bio/PDB/Residue.py'>][source]

Retrieve MHC residues from query TCR and filter out those whose counterpart is not found in reference.

Parameters:

tcr (TCR) – TCR structure object associated with MHC Class II.

Returns:

filtered_MHC_residues

Return type:

list[Bio.PDB.Residue]

set_mhc_reference()[source]

Set class II reference MHC residues

set_reffile()[source]

Sets reference file for MHC class II structures

class stcrpy.tcr_geometry.TCRCoM.MHCI_TCRCoM[source]

Bases: TCRCoM

get_filtered_MHC_residues(tcr: TCR) list[<module 'Bio.PDB.Residue' from '/home/quast/miniconda3/envs/test-stcrpy/lib/python3.12/site-packages/Bio/PDB/Residue.py'>][source]

Retrieve MHC residues from query TCR and filter out those whose counterpart is not found in reference.

Parameters:

tcr (TCR) – TCR structure object associated with MHC Class I.

Returns:

filtered_MHC_residues

Return type:

list[Bio.PDB.Residue]

set_mhc_reference()[source]

Set class I reference MHC residues

set_reffile()[source]

Sets reference file for MHC class I structures

class stcrpy.tcr_geometry.TCRCoM.TCRCoM[source]

Bases: object

add_com(mhc_com: array, tcr_com: array, VA_com: array, VB_com: array, tcr: TCR) TCR[source]

Function to add pseudoatoms at MHC-CoM, TCR-CoM, and XYZ axis to the output PDB file

Parameters:
  • mhc_com (np.array) – MHC centre of mass

  • tcr_com (np.array) – TCR centre of mass

  • VA_com (np.array) – Alpha chain centre of mass

  • VB_com (np.array) – Beta chain entre of mass

  • tcr (TCR) – TCR structure object

Returns:

Copy of the original TCR strucutre object with added pseudo-atoms.

Return type:

TCR

calculate_centres_of_mass(tcr: abTCR, save_aligned_as: str = None) tuple[array][source]

Calculate the TCR and MHC centres of mass of an stcrpy TCR structure object.

Parameters:
  • tcr (abTCR) – TCR structure object

  • save_aligned_as (str) – Path to same alignment to. If None or False alignment is not saved. Defaults to None.

Raises:

NotImplementedError – Alpha Beta TCR compatible only, Gamma Delta TCRs not implemented.

Returns:

tcr_com, mhc_com, tcr_VA_com, tcr_VB_com

Return type:

tuple[np.array]

center_of_mass(entity: Entity | list[Atom], geometric: bool = False) array[source]

Calculate the mass weighted or purely geometric centre of mass of an entity or a list of atoms.

Parameters:
  • entity (Union[Bio.PDB.Entity.Entity, list[Bio.PDB.Atom.Atom]]) – Structure entity whose centre of mass will be calculated

  • geometric (bool, optional) – Whether to calculate geometric mean. Defaults to False.

Raises:
  • ValueError – Checks input type to ensure atoms can be retrieved.

  • ValueError – Unknown atoms.

Returns:

centre of mass

Return type:

np.array

get_filtered_TCR_residues(tcr: TCR) tuple[list[Bio.PDB.Residue]][source]

Get variable domain residues of query TCR and filter out those without a counterpart in the reference TCR.

Parameters:

tcr (TCR) – TCR structure object

Returns:

VA_residues, VB_residues.

Return type:

tuple[list[Bio.PDB.Residue]]

set_mhc_reference()[source]

Super method for setting MHC reference residues for superposition. Overwritten by MHC class sepcific methods.

Raises:

NotImplementedError

set_reference_residues()[source]

Set TCR and MHC reference residues.

set_reffile()[source]

Super method for setting MHC reference file.

Raises:

NotImplementedError

set_tcr_reference()[source]

Set TCR variable domain residues in reference model as residues numbered 1 to 121 for VA and 1 to 126 for VB.

stcrpy.tcr_geometry.TCRDock module

__init__.py Description: Calculate the TCR/pMHC docking angle.

Based on the method by Rudolph, Stanfield, Wilson (Annu Revl Immmunol 2006, 24:419-466). This method is preferred for cases when the antigen is not a peptide. Formula uses SVD.

Jun 12, 2017

class stcrpy.tcr_geometry.TCRDock.TCRDock(tcr, QUIET=False)[source]

Bases: object

calculate_docking_angle(force=False)[source]

stcrpy.tcr_geometry.TCRGeom module

class stcrpy.tcr_geometry.TCRGeom.TCRGeom(tcr: TCR, save_aligned_as: bool = False, polarity_as_sign: bool = True, mode: str = 'cys')[source]

Bases: object

Class for TCR geometry calculations.

calculate_rudolph_angle(tcr_vector: array, mhc_vector: array) float[source]

Calculate the scanning angle of TCR:pMHC complex according to Rudolph et. al.

Parameters:
  • tcr_vector (np.array) – Vector pointing from VA Cys centroid to VB Cys centroid

  • mhc_vector (np.array) – Vector pointing along MHC cleft

Returns:

scanning angle

Return type:

float

calculate_tcr_docking_angles(tcr_vector: array, polarity_as_sign: bool = True) tuple[array][source]

Calculates the scanning angle and pitch of the TCR relative to the MHC. This function relies on the previous alignment of the MHC to the reference MHC, with the x axis defined perpedicular to the peptide, the y-axis along the peptide, and the z-axis pointing ‘up’ away from the MHC.

The scanning angle is calculated as the angle between the y axis and the projection of the TCR vector, which points from VA to VB, onto the x-y plane.

The pitch is calculated as the angle between the z-axis and the plane normal to the TCR vector and passing through the TCR CoM. Specifically the angle of the vector from the z-axis intersection and the nearest projection of the z-axis onto the plane dividing the VA and VB TCR domains is calculated, which is defined as the pitch of the TCR.

Parameters:
  • tcr_vector (np.array) – Unit vector in direction of VA CoM to VB CoM

  • polarity (bool, optional) – Set the polarity as the sign of the scanning angle ie negative if polarity is reversed (1), else positive if polarity is canonical (0). Defaults to True.

Returns:

Tuple containing the scanning angle and pitch angle of the TCR to the MHC

Return type:

tuple[np.array]

get_pitch_angle(rad: bool = False) float[source]

Return TCR:pMHC pitch angle, ie tilt of the TCR over the MHC.

Parameters:

rad (bool, optional) – Return angle in radians. Defaults to False.

Returns:

TCR:pMHC pitch angle

Return type:

float

get_polarity() int[source]

Return the polarity of the TCR based on the TCR vector pointing from the VA to the VB CoM, or the scanning angle if using Rudolph et. al.. If the x component is negative, ie the tcr_vector points from the alpha 2 chain to the alpha 1 chain of the MHC, the polarity is canonical (0). Otherwise the polarity is reverse (1).

Returns:

0 for canonical polarity, 1 for reverse polarity.

Return type:

int

get_scanning_angle(rad: bool = False) float[source]

Return TCR:pMHC complex scanning (aka crossing, incident angle) of TCR to MHC.

Parameters:

rad (bool, optional) – Return angle in radians. Defaults to False.

Returns:

TCR:pMHC scanning angle.

Return type:

float

get_tcr_vector(tcr_VA_com: array, tcr_VB_com: array) array[source]

Calculates the vector from the VA centre of mass to the VB centre of mass, translated such that the vector originates at the total TCR’s centre of mass and truncated to unit length. :param tcr_VA_com: TCR VA centre of mass :type tcr_VA_com: np.array :param tcr_VB_com: TCR VB center of mass :type tcr_VB_com: np.array

Returns:

Unit vector from TCR CoM in direction of VA CoM to VB CoM

Return type:

np.array

to_df() pandas.DataFrame[source]

Return TCR:pMHC complex geometry metrics and pandas dataframe.

Returns:

TCR:pMHC complex geometry metrics

Return type:

pandas.DataFrame

to_dict() dict[source]

Return TCR:pMHC complex geometry metrics as dictionary.

Returns:

TCR:pMHC complex geometry.

Return type:

dict

stcrpy.tcr_geometry.TCRGeomFiltering module

class stcrpy.tcr_geometry.TCRGeomFiltering.DockingGeometryFilter[source]

Bases: object

score_docking_geometry(scanning_angles, pitch_angles, z_dists, weights=array([1, 1, 1]))[source]
set_pitch_angle_pdf(new_pitch_angle_pdf)[source]
set_scanning_angle_pdf(new_scanning_angle_pdf)[source]
set_zdist_angle_pdf(new_zdist_pdf)[source]
class stcrpy.tcr_geometry.TCRGeomFiltering.DockingGeometryPDF(data=None)[source]

Bases: object

fit(data)[source]
log_probs(x)[source]
pdf(x)[source]
plot(data=None, plot_min=0, plot_max=150, save_as=None)[source]
class stcrpy.tcr_geometry.TCRGeomFiltering.GammaPDF(data=None, alpha=None, loc=None, scale=None)[source]

Bases: DockingGeometryPDF

fit(data)[source]
pdf(x)[source]
class stcrpy.tcr_geometry.TCRGeomFiltering.GaussianMixturePDF(data=None, n_components=None, weights=None, means=None, covariances=None)[source]

Bases: DockingGeometryPDF

fit(data)[source]
pdf(x)[source]
class stcrpy.tcr_geometry.TCRGeomFiltering.PitchAnglePDF(pitch_angles=None, alpha=1.1993765213484138, loc=0.036500005492399054, scale=5.781270719307026)[source]

Bases: GammaPDF

class stcrpy.tcr_geometry.TCRGeomFiltering.ScanningAnglePDF(scanning_angles=None, mean=array([[67.92200037]]), variance=array([[202.11710875]]))[source]

Bases: GaussianMixturePDF

class stcrpy.tcr_geometry.TCRGeomFiltering.ZDistPDF(z_dists=None, n_components=None, weights=array([0.43420871, 0.56579129]), mean=array([[27.04673494], [28.62071785]]), variance=array([[[0.46845205]], [[0.90790909]]]))[source]

Bases: GaussianMixturePDF

Module contents