Skip to content

Commit

Permalink
docs: activate missing docstring in public class and public function
Browse files Browse the repository at this point in the history
- Moved docstrings from __init__ to the class level instead
- Added missing docstrings or suppressed the call for them
- Did not activate missing docstring in public method because there are too many missing
- Deactivated missing docsstrings in tests
  • Loading branch information
DaniBodor committed Feb 3, 2024
1 parent 1ac091b commit dfb0d74
Show file tree
Hide file tree
Showing 31 changed files with 304 additions and 265 deletions.
239 changes: 121 additions & 118 deletions deeprank2/dataset.py

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions deeprank2/domain/aminoacidlist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

from deeprank2.molstruct.aminoacid import AminoAcid, Polarity

# All info below sourced from above websites in December 2022 and summarized in deeprank2/domain/aminoacid_summary.xlsx
Expand Down Expand Up @@ -377,7 +379,26 @@
amino_acids_by_name = {amino_acid.name: amino_acid for amino_acid in amino_acids}


def convert_aa_nomenclature(aa: str, output_type: int | None = None) -> str:
def convert_aa_nomenclature(aa: str, output_format: Literal[0, 1, 3] = 0) -> str:
"""Converts amino acid nomenclatures.
Conversions are possible between the standard 1-letter codes, 3-letter
codes, and full names of amino acids.
Args:
aa (str): The amino acid to be converted in any of its formats. The
length of the string is used to determine which format is used.
output_format (Literal[0, 1, 3], optional): Nomenclature style to return:
0 (default) returns the full name,
1 returns the 1-letter code,
3 returns the 3-letter code.
Raises:
ValueError: If aa is not recognized or an invalid output format was given
Returns:
str: amino acid in the selected nomenclature system.
"""
try:
if len(aa) == 1:
aa: AminoAcid = next(entry for entry in amino_acids if entry.one_letter_code.lower() == aa.lower())
Expand All @@ -389,11 +410,11 @@ def convert_aa_nomenclature(aa: str, output_type: int | None = None) -> str:
msg = f"{aa} is not a valid amino acid."
raise ValueError(msg) from e

if not output_type:
if not output_format:
return aa.name
if output_type == 3: # noqa:PLR2004
if output_format == 3: # noqa:PLR2004
return aa.three_letter_code
if output_type == 1:
if output_format == 1:
return aa.one_letter_code
msg = f"output_type {output_type} not recognized. Must be set to None (amino acid name), 1 (one letter code), or 3 (three letter code)."
msg = f"output_format {output_format} not recognized. Must be set to 0 (amino acid name), 1 (one letter code), or 3 (three letter code)."
raise ValueError(msg)
2 changes: 1 addition & 1 deletion deeprank2/features/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_log = logging.getLogger(__name__)


def add_features(
def add_features( # noqa:D103
pdb_path: str, # noqa: ARG001
graph: Graph,
single_amino_acid_variant: SingleResidueVariant | None = None,
Expand Down
2 changes: 1 addition & 1 deletion deeprank2/features/conservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from deeprank2.utils.graph import Graph


def add_features(
def add_features( # noqa:D103
pdb_path: str, # noqa: ARG001
graph: Graph,
single_amino_acid_variant: SingleResidueVariant | None = None,
Expand Down
2 changes: 1 addition & 1 deletion deeprank2/features/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _get_nonbonded_energy(
return E_elec, E_vdw


def add_features(
def add_features( # noqa:D103
pdb_path: str, # noqa: ARG001
graph: Graph,
single_amino_acid_variant: SingleResidueVariant | None = None, # noqa: ARG001
Expand Down
8 changes: 4 additions & 4 deletions deeprank2/features/exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
_log = logging.getLogger(__name__)


def handle_sigint(sig, frame) -> None: # noqa: ARG001, ANN001
def handle_sigint(sig, frame) -> None: # noqa: ARG001, ANN001, D103
_log.info("SIGINT received, terminating.")
sys.exit()


def handle_timeout(sig, frame) -> NoReturn: # noqa: ARG001, ANN001
def handle_timeout(sig, frame) -> NoReturn: # noqa: ARG001, ANN001, D103
msg = "Timed out!"
raise TimeoutError(msg)


def space_if_none(value: str) -> str:
def space_if_none(value: str) -> str: # noqa:D103
if value is None:
return " "
return value


def add_features(
def add_features( # noqa:D103
pdb_path: str,
graph: Graph,
single_amino_acid_variant: SingleResidueVariant | None = None, # noqa: ARG001
Expand Down
2 changes: 1 addition & 1 deletion deeprank2/features/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_IRCs(pdb_path: str, chains: list[str], cutoff: float = 5.5) -> dict[str,
return residue_contacts


def add_features( # noqa: C901
def add_features( # noqa: C901, D103
pdb_path: str,
graph: Graph,
single_amino_acid_variant: SingleResidueVariant | None = None,
Expand Down
2 changes: 1 addition & 1 deletion deeprank2/features/secondary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _get_secstructure(pdb_path: str) -> dict:
return sec_structure_dict


def add_features(
def add_features( # noqa:D103
pdb_path: str,
graph: Graph,
single_amino_acid_variant: SingleResidueVariant | None = None, # noqa: ARG001
Expand Down
4 changes: 2 additions & 2 deletions deeprank2/features/surfacearea.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logging.getLogger(__name__)


def add_sasa(pdb_path: str, graph: Graph) -> None:
def add_sasa(pdb_path: str, graph: Graph) -> None: # noqa:D103
structure = freesasa.Structure(pdb_path)
result = freesasa.calc(structure)

Expand All @@ -38,7 +38,7 @@ def add_sasa(pdb_path: str, graph: Graph) -> None:
node.features[Nfeat.SASA] = area


def add_bsa(graph: Graph) -> None:
def add_bsa(graph: Graph) -> None: # noqa:D103
sasa_complete_structure = freesasa.Structure()
sasa_chain_structures = {}

Expand Down
31 changes: 16 additions & 15 deletions deeprank2/molstruct/aminoacid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ def onehot(self) -> NDArray:


class AminoAcid:
"""An amino acid represents the type of `Residue` in a `PDBStructure`.
Args:
name (str): Full name of the amino acid.
three_letter_code (str): Three-letter code of the amino acid (as in PDB).
one_letter_code (str): One-letter of the amino acid (as in fasta).
charge (int): Charge of the amino acid.
polarity (:class:`Polarity`): The polarity of the amino acid.
size (int): The number of non-hydrogen atoms in the side chain.
mass (float): Average residue mass (i.e. mass of amino acid - H20) in Daltons.
pI (float): Isolectric point; pH at which the molecule has no net electric charge.
hydrogen_bond_donors (int): Number of hydrogen bond donors.
hydrogen_bond_acceptors (int): Number of hydrogen bond acceptors.
index (int): The rank of the amino acid, used for computing one-hot encoding.
"""

def __init__(
self,
name: str,
Expand All @@ -35,21 +51,6 @@ def __init__(
hydrogen_bond_acceptors: int,
index: int,
):
"""An amino acid represents the type of `Residue` in a `PDBStructure`.
Args:
name (str): Full name of the amino acid.
three_letter_code (str): Three-letter code of the amino acid (as in PDB).
one_letter_code (str): One-letter of the amino acid (as in fasta).
charge (int): Charge of the amino acid.
polarity (:class:`Polarity`): The polarity of the amino acid.
size (int): The number of non-hydrogen atoms in the side chain.
mass (float): Average residue mass (i.e. mass of amino acid - H20) in Daltons.
pI (float): Isolectric point; pH at which the molecule has no net electric charge.
hydrogen_bond_donors (int): Number of hydrogen bond donors.
hydrogen_bond_acceptors (int): Number of hydrogen bond acceptors.
index (int): The rank of the amino acid, used for computing one-hot encoding.
"""
# amino acid nomenclature
self._name = name
self._three_letter_code = three_letter_code
Expand Down
25 changes: 13 additions & 12 deletions deeprank2/molstruct/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def onehot(self) -> np.array:


class Atom:
"""One atom in a PDBStructure.
Args:
residue (:class:`Residue`): The residue that this atom belongs to.
name (str): Pdb atom name.
element (:class:`AtomicElement`): The chemical element.
position (np.array): Pdb position xyz of this atom.
occupancy (float): Pdb occupancy value.
This represents the proportion of structures where the atom is detected at a given position.
Sometimes a single atom can be detected at multiple positions. In that case separate structures exist where sum(occupancy) == 1.
Note that only the highest occupancy atom is used by deeprank2 (see tools.pdb._add_atom_to_residue).
"""

def __init__(
self,
residue: Residue,
Expand All @@ -38,18 +51,6 @@ def __init__(
position: NDArray,
occupancy: float,
):
"""One atom in a PDBStructure.
Args:
residue (:class:`Residue`): The residue that this atom belongs to.
name (str): Pdb atom name.
element (:class:`AtomicElement`): The chemical element.
position (np.array): Pdb position xyz of this atom.
occupancy (float): Pdb occupancy value.
This represents the proportion of structures where the atom is detected at a given position.
Sometimes a single atom can be detected at multiple positions. In that case separate structures exist where sum(occupancy) == 1.
Note that only the highest occupancy atom is used by deeprank2 (see tools.pdb._add_atom_to_residue).
"""
self._residue = residue
self._name = name
self._element = element
Expand Down
13 changes: 7 additions & 6 deletions deeprank2/molstruct/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@


class Pair:
def __init__(self, item1: Any, item2: Any): # noqa: ANN401
"""A hashable, comparable object for any set of two inputs where order doesn't matter.
"""A hashable, comparable object for any set of two inputs where order doesn't matter.
Args:
item1 (Any object): The pair's first object, must be convertable to string.
item2 (Any object): The pair's second object, must be convertable to string.
"""

Args:
item1 (Any object): The pair's first object, must be convertable to string.
item2 (Any object): The pair's second object, must be convertable to string.
"""
def __init__(self, item1: Any, item2: Any): # noqa: ANN401
self.item1 = item1
self.item2 = item2

Expand Down
13 changes: 7 additions & 6 deletions deeprank2/molstruct/residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ def get_center(self) -> NDArray:


class SingleResidueVariant:
def __init__(self, residue: Residue, variant_amino_acid: AminoAcid):
"""A single residue mutation of a PDBStrcture.
"""A single residue mutation of a PDBStrcture.
Args:
residue (Residue): the `Residue` object from the PDBStructure that is mutated.
variant_amino_acid (AminoAcid): the amino acid that the `Residue` is mutated into.
"""
Args:
residue (Residue): the `Residue` object from the PDBStructure that is mutated.
variant_amino_acid (AminoAcid): the amino acid that the `Residue` is mutated into.
"""

def __init__(self, residue: Residue, variant_amino_acid: AminoAcid):
self._residue = residue
self._variant_amino_acid = variant_amino_acid

Expand Down
4 changes: 2 additions & 2 deletions deeprank2/neuralnets/cnn/model3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# ----------------------------------------------------------------------


class CnnRegression(torch.nn.Module):
class CnnRegression(torch.nn.Module): # noqa: D101
def __init__(self, num_features: int, box_shape: tuple[int]):
super().__init__()

Expand Down Expand Up @@ -76,7 +76,7 @@ def forward(self, data):
# ----------------------------------------------------------------------


class CnnClassification(torch.nn.Module):
class CnnClassification(torch.nn.Module): # noqa: D101
def __init__(self, num_features, box_shape):
super().__init__()

Expand Down
6 changes: 3 additions & 3 deletions deeprank2/neuralnets/gnn/alignmentnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = "Daniel-Tobias Rademaker"


class GNNLayer(nn.Module):
class GNNLayer(nn.Module): # noqa: D101
def __init__(
self,
nmb_edge_projection,
Expand Down Expand Up @@ -104,7 +104,7 @@ def output(self, hidden_features, get_attention=True):
return output


class SuperGNN(nn.Module):
class SuperGNN(nn.Module): # noqa: D101
def __init__(
self,
nmb_edge_attr,
Expand Down Expand Up @@ -172,7 +172,7 @@ def run_through_network(self, edges, edge_attr, node_attr, with_output_attention
return self.modlist[-1].output(node_attr, True) # (boolean-positional-value-in-call)


class AlignmentGNN(SuperGNN):
class AlignmentGNN(SuperGNN): # noqa: D101
def __init__(
self,
nmb_edge_attr,
Expand Down
2 changes: 1 addition & 1 deletion deeprank2/neuralnets/gnn/foutnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __repr__(self):
return f"{self.__class__.__name__}({self.in_channels}, {self.out_channels})"


class FoutNet(torch.nn.Module):
class FoutNet(torch.nn.Module): # noqa: D101
def __init__(
self,
input_shape,
Expand Down
4 changes: 2 additions & 2 deletions deeprank2/neuralnets/gnn/ginet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ruff: noqa: ANN001, ANN201


class GINetConvLayer(torch.nn.Module):
class GINetConvLayer(torch.nn.Module): # noqa: D101
def __init__(self, in_channels, out_channels, number_edge_features=1, bias=False):
super().__init__()

Expand Down Expand Up @@ -54,7 +54,7 @@ def __repr__(self):
return f"{self.__class__.__name__}({self.in_channels}, {self.out_channels})"


class GINet(torch.nn.Module):
class GINet(torch.nn.Module): # noqa: D101
# input_shape -> number of node input features
# output_shape -> number of output value per graph
# input_shape_edge -> number of edge input features
Expand Down
4 changes: 2 additions & 2 deletions deeprank2/neuralnets/gnn/ginet_nocluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ruff: noqa: ANN001, ANN201


class GINetConvLayer(torch.nn.Module):
class GINetConvLayer(torch.nn.Module): # noqa: D101
def __init__(self, in_channels, out_channels, number_edge_features=1, bias=False):
super().__init__()

Expand Down Expand Up @@ -51,7 +51,7 @@ def __repr__(self):
return f"{self.__class__.__name__}({self.in_channels}, {self.out_channels})"


class GINet(torch.nn.Module):
class GINet(torch.nn.Module): # noqa: D101
# input_shape -> number of node input features
# output_shape -> number of output value per graph
# input_shape_edge -> number of edge input features
Expand Down
4 changes: 2 additions & 2 deletions deeprank2/neuralnets/gnn/naive_gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ruff: noqa: ANN001, ANN201


class NaiveConvolutionalLayer(Module):
class NaiveConvolutionalLayer(Module): # noqa: D101
def __init__(self, count_node_features, count_edge_features):
super().__init__()
message_size = 32
Expand All @@ -31,7 +31,7 @@ def forward(self, node_features, edge_node_indices, edge_features):
return self._node_mlp(node_input)


class NaiveNetwork(Module):
class NaiveNetwork(Module): # noqa: D101
def __init__(self, input_shape: int, output_shape: int, input_shape_edge: int):
"""NaiveNetwork.
Expand Down
2 changes: 1 addition & 1 deletion deeprank2/neuralnets/gnn/sgat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __repr__(self):
return f"{self.__class__.__name__}({self.in_channels}, {self.out_channels})"


class SGAT(torch.nn.Module):
class SGAT(torch.nn.Module): # noqa:D101
def __init__(
self,
input_shape,
Expand Down
Loading

0 comments on commit dfb0d74

Please sign in to comment.