Skip to content

Commit

Permalink
update max_edge_length and influence_radius
Browse files Browse the repository at this point in the history
previously `max_edge_distance` and `interaction_radius`, respectively
  • Loading branch information
DaniBodor committed Nov 17, 2023
1 parent 6df8f63 commit d5acd2c
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 101 deletions.
36 changes: 18 additions & 18 deletions deeprank2/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class Query:
Note that this does not limit the structure to residues from this/these chain(s).
pssm_paths (dict[str, str]): the name of the chain(s) (key) and path to the pssm file(s) (value).
targets (dict[str, float]) = Name(s) (key) and target value(s) (value) associated with this query.
interaction_radius (float | None): all residues within this radius from the variant residue or interacting interfaces
influence_radius (float | None): all residues within this radius from the variant residue or interacting interfaces
will be included in the graph, irrespective of the chain they are on.
max_edge_distance (float | None): the maximum distance between two nodes to generate an edge connecting them.
max_edge_length (float | None): the maximum distance between two nodes to generate an edge connecting them.
suppress_pssm_errors (bool): Whether or not to suppress the error raised if the .pssm files do not
match the .pdb files. If True, a warning is returned instead.
"""
Expand All @@ -61,20 +61,20 @@ class Query:
chain_ids: list[str] | str
pssm_paths: dict[str, str] = field(default_factory=dict)
targets: dict[str, float] = field(default_factory=dict)
interaction_radius: float | None = None
max_edge_distance: float | None = None
influence_radius: float | None = None
max_edge_length: float | None = None
suppress_pssm_errors: bool = False

def __post_init__(self):
self._model_id = os.path.splitext(os.path.basename(self.pdb_path))[0]
self.variant = None # not used for PPI, overwritten for SRV

if self.resolution == 'residue':
self.max_edge_distance = 10 if not self.max_edge_distance else self.max_edge_distance
self.interaction_radius = 10 if not self.interaction_radius else self.interaction_radius
self.max_edge_length = 10 if not self.max_edge_length else self.max_edge_length
self.influence_radius = 10 if not self.influence_radius else self.influence_radius
elif self.resolution == 'atom':
self.max_edge_distance = 4.5 if not self.max_edge_distance else self.max_edge_distance
self.interaction_radius = 4.5 if not self.interaction_radius else self.interaction_radius
self.max_edge_length = 4.5 if not self.max_edge_length else self.max_edge_length
self.influence_radius = 4.5 if not self.influence_radius else self.influence_radius
else:
raise ValueError(f"Invalid resolution given ({self.resolution}). Must be one of {VALID_RESOLUTIONS}")

Expand Down Expand Up @@ -228,9 +228,9 @@ class SingleResidueVariantQuery(Query):
Note that this does not limit the structure to residues from this chain.
pssm_paths (dict[str, str]): the name of the chain(s) (key) and path to the pssm file(s) (value).
targets (dict[str, float]) = Name(s) (key) and target value(s) (value) associated with this query.
interaction_radius (float | None): all residues within this radius from the variant residue
influence_radius (float | None): all residues within this radius from the variant residue
will be included in the graph, irrespective of the chain they are on.
max_edge_distance (float | None): the maximum distance between two nodes to generate an edge connecting them.
max_edge_length (float | None): the maximum distance between two nodes to generate an edge connecting them.
suppress_pssm_errors (bool): Whether or not to suppress the error raised if the .pssm files do not
match the .pdb files. If True, a warning is returned instead.
Expand Down Expand Up @@ -294,11 +294,11 @@ def _build_helper(self) -> Graph:
f"Residue not found in {self.pdb_path}: {self.variant_chain_id} {self.residue_id}"
)
self.variant = SingleResidueVariant(variant_residue, self.variant_amino_acid)
residues = get_surrounding_residues(structure, variant_residue, self.interaction_radius)
residues = get_surrounding_residues(structure, variant_residue, self.influence_radius)

# build the graph
if self.resolution == 'residue':
graph = build_residue_graph(residues, self.get_query_id(), self.max_edge_distance)
graph = build_residue_graph(residues, self.get_query_id(), self.max_edge_length)
elif self.resolution == 'atom':
residues.append(variant_residue)
atoms = set([])
Expand All @@ -308,7 +308,7 @@ def _build_helper(self) -> Graph:
atoms.add(atom)
atoms = list(atoms)

graph = build_atomic_graph(atoms, self.get_query_id(), self.max_edge_distance)
graph = build_atomic_graph(atoms, self.get_query_id(), self.max_edge_length)

else:
raise NotImplementedError(f"No function exists to build graphs with resolution of {self.resolution}.")
Expand All @@ -328,9 +328,9 @@ class ProteinProteinInterfaceQuery(Query):
Note that this does not limit the structure to residues from these chains.
pssm_paths (dict[str, str]): the name of the chain(s) (key) and path to the pssm file(s) (value).
targets (dict[str, float]) = Name(s) (key) and target value(s) (value) associated with this query.
interaction_radius (float | None): all residues within this radius from the interacting interfaces
influence_radius (float | None): all residues within this radius from the interacting interface
will be included in the graph, irrespective of the chain they are on.
max_edge_distance (float | None): the maximum distance between two nodes to generate an edge connecting them.
max_edge_length (float | None): the maximum distance between two nodes to generate an edge connecting them.
suppress_pssm_errors (bool): Whether or not to suppress the error raised if the .pssm files do not
match the .pdb files. If True, a warning is returned instead.
"""
Expand Down Expand Up @@ -360,17 +360,17 @@ def _build_helper(self) -> Graph:
contact_atoms = get_contact_atoms(
self.pdb_path,
self.chain_ids,
self.interaction_radius
self.influence_radius
)
if len(contact_atoms) == 0:
raise ValueError("no contact atoms found")

# build the graph
if self.resolution == 'atom':
graph = build_atomic_graph(contact_atoms, self.get_query_id(), self.max_edge_distance)
graph = build_atomic_graph(contact_atoms, self.get_query_id(), self.max_edge_length)
elif self.resolution == 'residue':
residues_selected = list({atom.residue for atom in contact_atoms})
graph = build_residue_graph(residues_selected, self.get_query_id(), self.max_edge_distance)
graph = build_residue_graph(residues_selected, self.get_query_id(), self.max_edge_length)

graph.center = np.mean([atom.position for atom in contact_atoms], axis=0)
structure = contact_atoms[0].residue.chain.model
Expand Down
10 changes: 5 additions & 5 deletions deeprank2/utils/buildgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ def get_structure(pdb, id_: str) -> PDBStructure:
def get_contact_atoms( # pylint: disable=too-many-locals
pdb_path: str,
chain_ids: list[str],
interaction_radius: float
influence_radius: float
) -> list[Atom]:
"""Gets the contact atoms from pdb2sql and wraps them in python objects."""

interface = get_interface(pdb_path)
try:
atom_indexes = interface.get_contact_atoms(
cutoff=interaction_radius,
cutoff=influence_radius,
chain1=chain_ids[0],
chain2=chain_ids[1],
)
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_residue_contact_pairs( # pylint: disable=too-many-locals
structure: PDBStructure,
chain_id1: str,
chain_id2: str,
interaction_radius: float,
influence_radius: float,
) -> list[Pair]:
"""Find all residue pairs that may influence each other.
Expand All @@ -217,7 +217,7 @@ def get_residue_contact_pairs( # pylint: disable=too-many-locals
structure (:class:`PDBStructure`): From which to take the residues.
chain_id1 (str): First protein chain identifier.
chain_id2 (str): Second protein chain identifier.
interaction_radius (float): Maximum distance between residues to consider them as interacting.
influence_radius (float): Maximum distance between residues to consider them as interacting.
Returns:
list[Pair]: The pairs of contacting residues.
Expand All @@ -227,7 +227,7 @@ def get_residue_contact_pairs( # pylint: disable=too-many-locals
interface = get_interface(pdb_path)
try:
contact_residues = interface.get_contact_residues(
cutoff=interaction_radius,
cutoff=influence_radius,
chain1=chain_id1,
chain2=chain_id2,
return_contact_pairs=True,
Expand Down
8 changes: 4 additions & 4 deletions deeprank2/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def get_all_chains(self) -> list[str]:


def build_atomic_graph( # pylint: disable=too-many-locals
atoms: list[Atom], graph_id: str, max_edge_distance: float
atoms: list[Atom], graph_id: str, max_edge_length: float
) -> Graph:
"""Builds a graph, using the atoms as nodes.
Expand All @@ -332,7 +332,7 @@ def build_atomic_graph( # pylint: disable=too-many-locals
positions[atom_index] = atom.position

distances = distance_matrix(positions, positions, p=2)
neighbours = distances < max_edge_distance
neighbours = distances < max_edge_length

graph = Graph(graph_id)
for atom1_index, atom2_index in np.transpose(np.nonzero(neighbours)):
Expand All @@ -355,7 +355,7 @@ def build_atomic_graph( # pylint: disable=too-many-locals


def build_residue_graph( # pylint: disable=too-many-locals
residues: list[Residue], graph_id: str, max_edge_distance: float
residues: list[Residue], graph_id: str, max_edge_length: float
) -> Graph:
"""Builds a graph, using the residues as nodes.
Expand All @@ -381,7 +381,7 @@ def build_residue_graph( # pylint: disable=too-many-locals
distances = distance_matrix(positions, positions, p=2)

# determine which atoms are close enough
neighbours = distances < max_edge_distance
neighbours = distances < max_edge_length

atom_index_pairs = np.transpose(np.nonzero(neighbours))

Expand Down
8 changes: 4 additions & 4 deletions tests/data/hdf5/_generate_testdata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
"models_folder_name = 'exp_nmers_all_HLA_quantitative'\n",
"data = 'pMHCI'\n",
"resolution = 'residue' # either 'residue' or 'atom'\n",
"interaction_radius = 15 # max distance in Å between two interacting residues/atoms of two proteins\n",
"max_edge_distance = 15 # max distance in Å between to create an edge\n",
"influence_radius = 15 # max distance in Å between two interacting residues/atoms of two proteins\n",
"max_edge_length = 15 # max distance in Å between to create an edge\n",
"\n",
"csv_file_path = f'{project_folder}data/external/processed/I/{csv_file_name}'\n",
"models_folder_path = f'{project_folder}data/{data}/features_input_folder/{models_folder_name}'\n",
Expand Down Expand Up @@ -131,8 +131,8 @@
" pdb_path = pdb_files[i],\n",
" resolution = \"residue\",\n",
" chain_ids = [\"M\", \"P\"],\n",
" interaction_radius = interaction_radius,\n",
" max_edge_distance = max_edge_distance,\n",
" influence_radius = influence_radius,\n",
" max_edge_length = max_edge_length,\n",
" targets = {\n",
" 'binary': int(float(bas[i]) <= 500), # binary target value\n",
" 'BA': bas[i], # continuous target value\n",
Expand Down
20 changes: 10 additions & 10 deletions tests/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def _get_residue(chain: Chain, number: int) -> Residue:
def build_testgraph( # pylint: disable=too-many-locals, too-many-arguments # noqa:MC0001
pdb_path: str,
detail: Literal['atomic', 'residue'],
interaction_radius: float,
max_edge_distance: float,
influence_radius: float,
max_edge_length: float,
central_res: int | None = None,
variant: AminoAcid |None = None,
chain_ids: str | tuple[str, str] | None = None,
Expand All @@ -38,8 +38,8 @@ def build_testgraph( # pylint: disable=too-many-locals, too-many-arguments # noq
Args:
pdb_path (str): Path of pdb file.
detail (Literal['atomic', 'residue']): Level of detail.
interaction_radius (float): max distance to include in graph.
max_edge_distance (float): max distance to create an edge.
influence_radius (float): max distance to include in graph.
max_edge_length (float): max distance to create an edge.
central_res (int | None, optional): Residue to center a single-chain graph around.
Use None to create a 2-chain graph, or any value for a single-chain graph
Defaults to None.
Expand Down Expand Up @@ -71,7 +71,7 @@ def build_testgraph( # pylint: disable=too-many-locals, too-many-arguments # noq
for residue1, residue2 in get_residue_contact_pairs(
pdb_path, structure,
chains[0], chains[1],
interaction_radius
influence_radius
):
if detail == 'residue':
nodes.add(residue1)
Expand All @@ -84,9 +84,9 @@ def build_testgraph( # pylint: disable=too-many-locals, too-many-arguments # noq
nodes.add(atom)

if detail == 'residue':
return build_residue_graph(list(nodes), structure.id, max_edge_distance), None
return build_residue_graph(list(nodes), structure.id, max_edge_length), None
if detail == 'atom':
return build_atomic_graph(list(nodes), structure.id, max_edge_distance), None
return build_atomic_graph(list(nodes), structure.id, max_edge_length), None
raise TypeError('detail must be "atom" or "residue"')

else:
Expand All @@ -95,7 +95,7 @@ def build_testgraph( # pylint: disable=too-many-locals, too-many-arguments # noq
else:
chain = structure.get_chain(chain_ids)
residue = _get_residue(chain, central_res)
surrounding_residues = list(get_surrounding_residues(structure, residue, interaction_radius))
surrounding_residues = list(get_surrounding_residues(structure, residue, influence_radius))

try:
with open(f"tests/data/pssm/{structure.id}/{structure.id}.{chain.id}.pdb.pssm", "rt", encoding="utf-8") as f:
Expand All @@ -104,8 +104,8 @@ def build_testgraph( # pylint: disable=too-many-locals, too-many-arguments # noq
pass

if detail == 'residue':
return build_residue_graph(surrounding_residues, structure.id, max_edge_distance), SingleResidueVariant(residue, variant)
return build_residue_graph(surrounding_residues, structure.id, max_edge_length), SingleResidueVariant(residue, variant)
if detail == 'atom':
atoms = set(atom for residue in surrounding_residues for atom in residue.atoms)
return build_atomic_graph(list(atoms), structure.id, max_edge_distance), SingleResidueVariant(residue, variant)
return build_atomic_graph(list(atoms), structure.id, max_edge_length), SingleResidueVariant(residue, variant)
raise TypeError('detail must be "atom" or "residue"')
8 changes: 4 additions & 4 deletions tests/features/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def test_atom_features():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='atom',
interaction_radius=10,
max_edge_distance=10,
influence_radius=10,
max_edge_length=10,
central_res=25,
)
add_features(pdb_path, graph)
Expand All @@ -26,8 +26,8 @@ def test_aminoacid_features():
graph, variant = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=10,
max_edge_distance=10,
influence_radius=10,
max_edge_length=10,
central_res=25,
variant=serine,
)
Expand Down
12 changes: 6 additions & 6 deletions tests/features/test_conservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def test_conservation_residue():
graph, variant = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=10,
max_edge_distance=10,
influence_radius=10,
max_edge_length=10,
central_res=25,
variant=alanine,
)
Expand All @@ -34,8 +34,8 @@ def test_conservation_atom():
graph, variant = build_testgraph(
pdb_path=pdb_path,
detail='atom',
interaction_radius=10,
max_edge_distance=10,
influence_radius=10,
max_edge_length=10,
central_res=25,
variant=alanine,
)
Expand All @@ -55,8 +55,8 @@ def test_no_pssm_file_error():
graph, variant = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=10,
max_edge_distance=10,
influence_radius=10,
max_edge_length=10,
central_res=17,
variant=alanine,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/features/test_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_exposure_residue():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=8.5,
max_edge_distance=8.5,
influence_radius=8.5,
max_edge_length=8.5,
)
add_features(pdb_path, graph)
_run_assertions(graph)
Expand All @@ -34,8 +34,8 @@ def test_exposure_atom():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='atom',
interaction_radius=4.5,
max_edge_distance=4.5,
influence_radius=4.5,
max_edge_length=4.5,
)
add_features(pdb_path, graph)
_run_assertions(graph)
8 changes: 4 additions & 4 deletions tests/features/test_irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def test_irc_residue():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=8.5,
max_edge_distance=8.5,
influence_radius=8.5,
max_edge_length=8.5,
)
add_features(pdb_path, graph)
_run_assertions(graph)
Expand All @@ -40,8 +40,8 @@ def test_irc_atom():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=4.5,
max_edge_distance=4.5,
influence_radius=4.5,
max_edge_length=4.5,
)
add_features(pdb_path, graph)
_run_assertions(graph)
8 changes: 4 additions & 4 deletions tests/features/test_secondary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def test_secondary_structure_residue():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='residue',
interaction_radius=10,
max_edge_distance=10,
influence_radius=10,
max_edge_length=10,
)
add_features(pdb_path, graph)

Expand Down Expand Up @@ -61,8 +61,8 @@ def test_secondary_structure_atom():
graph, _ = build_testgraph(
pdb_path=pdb_path,
detail='atom',
interaction_radius=4.5,
max_edge_distance=4.5,
influence_radius=4.5,
max_edge_length=4.5,
)
add_features(pdb_path, graph)

Expand Down
Loading

0 comments on commit d5acd2c

Please sign in to comment.