Switch Probabilities

These methods calculate and help visualize the probability of pairs of residues having their order switched when one protein is aligned to another using the Gromov-Wasserstein (GW) framework. This analysis is most meaningful when the proteins are morphologically similar (typically with a GW distance under 2).

Switch Probability Calculation

GWProt.switch_probabilities.get_switch_probabilities(T: array, prot_num: int = 0) array

Calculates the probability that the order of two residues are switched or not when the correspondence is applied. This can be used to detect circular permutations between two proteins.

Parameters
  • T – The correspondence to use

  • prot_num – Which protein to use, 0 uses the 0th axis of T, 1 uses the 1st axis.

Returns

A square np.array whose ij*th entry is the probability that residues *i and j are kept in the same order.

This function uses sparse matrices for efficiency, but may encounter issues if the correspondence T has many non-zero entries. In practice, this is rarely a problem.

Visualization and Utilities

GWProt.switch_probabilities.visualize_switch_probabibilities(A: array) None

This method displays a switch probability matrix with matplotlib.

Parameters

A – The switch probability matrix to display; only the upper triangular part of it is used.

GWProt.switch_probabilities.preprocess(A: array) array

Processes a switch probability matrix for applying max_rectangle_diagonal

Parameters

A – A switch probability matrix

Returns

A processed switch probability matrix

GWProt.switch_probabilities.max_rectangle_diagonal(A: array, min: int = 0) tuple[int, tuple[int, int, int, int]]

This method finds the area and coordinates of the largest rectange in an array containing only nonzero entries, with a corner on the main diagonal.

Parameters
  • A – The array

  • min – Rectangles whose width or height are below min are not considered

Returns

This returns the maximal area and the coordinates of the rectangle in the tuple (max_area, (left,  right, bottom, top ))

The maximal rectangle algorithm is based on the solution to the classic maximal rectangle problem, as written up by David Vandevoorde.

Note: While these methods are related to GW alignment and LGD analysis, they focus on the order and mapping of residues rather than direct geometric distortion.