Skip to content

Commit

Permalink
fix: format doc strings using docformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohulan committed Jan 17, 2024
1 parent d1d160f commit 63616d6
Show file tree
Hide file tree
Showing 33 changed files with 250 additions and 375 deletions.
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ repos:
- id: check-yaml
- id: debug-statements
- id: requirements-txt-fixer
- repo: https://github.com/DanielNoord/pydocstringformatter
rev: v0.7.3
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.1
hooks:
- id: pydocstringformatter
- id: docformatter
args: [--in-place]
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
Expand Down
17 changes: 12 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# -*- coding: utf-8 -*-
"""
Cheminformatics Microservice Python Modules.
"""Cheminformatics Microservice Python Modules.
This set of essential and valuable microservices is designed to be accessed via API calls to support cheminformatics. Generally, it is designed to work with SMILES-based inputs and could be used to translate between different machine-readable representations, get Natural Product (NP) likeliness scores, visualize chemical structures, and generate descriptors. In addition, the microservices also host an instance of STOUT and another instance of DECIMER (two deep learning models for IUPAC name generation and optical chemical structure recognition, respectively).
This set of essential and valuable microservices is designed to be
accessed via API calls to support cheminformatics. Generally, it is
designed to work with SMILES-based inputs and could be used to translate
between different machine-readable representations, get Natural Product
(NP) likeliness scores, visualize chemical structures, and generate
descriptors. In addition, the microservices also host an instance of
STOUT and another instance of DECIMER (two deep learning models for
IUPAC name generation and optical chemical structure recognition,
respectively).
For comments, bug reports or feature requests,
please raise an issue on our GitHub repository.
For comments, bug reports or feature requests, please raise an issue on
our GitHub repository.
"""
from __future__ import annotations

Expand Down
3 changes: 1 addition & 2 deletions app/exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def __init__(self, name: str, value: str):


async def input_exception_handler(request: Request, exc: InvalidInputException):
"""
Custom exception handler for InvalidInputException.
"""Custom exception handler for InvalidInputException.
Args:
request (Request): The FastAPI Request object.
Expand Down
3 changes: 1 addition & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ async def root():
response_model=HealthCheck,
)
def get_health() -> HealthCheck:
"""
## Perform a Health Check.
"""## Perform a Health Check.
Endpoint to perform a health check on. This endpoint can primarily be used by Docker
to ensure a robust container orchestration and management are in place. Other
Expand Down
16 changes: 6 additions & 10 deletions app/modules/all_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@


def get_all_rdkit_descriptors(molecule: any) -> Union[tuple, str]:
"""
Calculate a selected set of molecular descriptors using RDKit.
"""Calculate a selected set of molecular descriptors using RDKit.
This function takes an input SMILES string and calculates various molecular descriptors
using RDKit.
Expand Down Expand Up @@ -79,8 +78,7 @@ def get_all_rdkit_descriptors(molecule: any) -> Union[tuple, str]:


def get_all_cdk_descriptors(molecule: any) -> Union[tuple, str]:
"""
Calculate a set of molecular descriptors using the CDK.
"""Calculate a set of molecular descriptors using the CDK.
This function takes a SMILES string as input and calculates various molecular descriptors
using the CDK. The calculated descriptors are returned as a tuple.
Expand Down Expand Up @@ -196,8 +194,8 @@ def get_all_cdk_descriptors(molecule: any) -> Union[tuple, str]:
def get_cdk_rdkit_combined_descriptors(
smiles: str,
) -> Union[dict, str]:
"""
Calculate a selected set of molecular descriptors using CDK and RDKit for a given SMILES string.
"""Calculate a selected set of molecular descriptors using CDK and RDKit
for a given SMILES string.
Args:
smiles (str): A SMILES string representing a chemical compound.
Expand Down Expand Up @@ -252,8 +250,7 @@ def get_cdk_rdkit_combined_descriptors(


def get_table(tanimoto_values: list) -> str:
"""
Convert a list of Tanimoto similarity values into an HTML table.
"""Convert a list of Tanimoto similarity values into an HTML table.
Args:
tanimoto_values (list): A list of lists containing Tanimoto similarity values.
Expand Down Expand Up @@ -282,8 +279,7 @@ def get_table(tanimoto_values: list) -> str:


def get_tanimoto_similarity(smileslist: str, toolkit: str = "cdk") -> list:
"""
Calculate the Tanimoto similarity index between pairs of SMILES strings.
"""Calculate the Tanimoto similarity index between pairs of SMILES strings.
This function takes a list of SMILES strings, splits them, and calculates
the Tanimoto similarity index between every pair of SMILES strings.
Expand Down
7 changes: 3 additions & 4 deletions app/modules/classyfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


async def classify(smiles: str) -> dict:
"""
This function queries the ClassyFire API to classify a chemical compound.
"""This function queries the ClassyFire API to classify a chemical
compound.
represented by a SMILES string.
Expand Down Expand Up @@ -43,8 +43,7 @@ async def classify(smiles: str) -> dict:


async def result(id: str) -> dict:
"""
Fetches JSON response from the ClassyFire API for a given ID.
"""Fetches JSON response from the ClassyFire API for a given ID.
This function takes an ID and retrieves the corresponding chemical classification
information from the ClassyFire API in JSON format.
Expand Down
7 changes: 3 additions & 4 deletions app/modules/coconut/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@


def get_descriptors(smiles: str, toolkit: str) -> Union[tuple, str]:
"""
Calculate descriptors using RDKit or CDK toolkit for the given SMILES.
"""Calculate descriptors using RDKit or CDK toolkit for the given SMILES.
Args:
smiles (str): SMILES input.
Expand All @@ -36,8 +35,8 @@ def get_descriptors(smiles: str, toolkit: str) -> Union[tuple, str]:


def get_COCONUT_descriptors(smiles: str, toolkit: str) -> Union[Dict[str, float], str]:
"""
Calculate COCONUT descriptors using RDKit or CDK toolkit for the given SMILES.
"""Calculate COCONUT descriptors using RDKit or CDK toolkit for the given
SMILES.
Args:
smiles (str): SMILES input.
Expand Down
13 changes: 5 additions & 8 deletions app/modules/coconut/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


def get_mol_block(input_text: str) -> str:
"""
Generate a Molblock from input text using CDK.
"""Generate a Molblock from input text using CDK.
Args:
input_text (str): Input text (Mol/SMILES).
Expand All @@ -38,8 +37,7 @@ def get_mol_block(input_text: str) -> str:


def get_molecule_hash(molecule: any) -> dict:
"""
Return various molecule hashes for the provided SMILES.
"""Return various molecule hashes for the provided SMILES.
Args:
smiles (str): Standardized SMILES string.
Expand All @@ -65,8 +63,7 @@ def get_molecule_hash(molecule: any) -> dict:


def get_representations(molecule: any) -> dict:
"""
Return COCONUT representations for the provided SMILES.
"""Return COCONUT representations for the provided SMILES.
Args:
smiles (str): SMILES string.
Expand All @@ -85,8 +82,8 @@ def get_representations(molecule: any) -> dict:


def get_COCONUT_preprocessing(input_text: str) -> dict:
"""
Preprocess user input text suitable for the COCONUT database submission data.
"""Preprocess user input text suitable for the COCONUT database submission
data.
Args:
input_text (str): Input text (Mol/str).
Expand Down
15 changes: 7 additions & 8 deletions app/modules/decimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


def convert_image(path: str) -> str:
"""
Convert a GIF image to PNG format, resize, and place on a white background.
"""Convert a GIF image to PNG format, resize, and place on a white
background.
Args:
path (str): The path to the GIF image file.
Expand Down Expand Up @@ -53,8 +53,8 @@ def convert_image(path: str) -> str:


def get_segments(path: str) -> tuple:
"""
Takes an image file path and returns a set of paths and image names of segmented images.
"""Takes an image file path and returns a set of paths and image names of
segmented images.
Args:
input_path (str): the path of an image.
Expand All @@ -75,8 +75,7 @@ def get_segments(path: str) -> tuple:


def get_predicted_segments(path: str) -> str:
"""
Get predicted SMILES representations for segments within an image.
"""Get predicted SMILES representations for segments within an image.
This function takes an image path, extracts segments, predicts SMILES representations
for each segment, and returns a concatenated string of predicted SMILES.
Expand Down Expand Up @@ -106,8 +105,8 @@ def get_predicted_segments(path: str) -> str:


def get_predicted_segments_from_file(content: any, filename: str) -> tuple:
"""
Takes an image file path and returns a set of paths and image names of segmented images.
"""Takes an image file path and returns a set of paths and image names of
segmented images.
Args:
input_path (str): the path of an image.
Expand Down
7 changes: 3 additions & 4 deletions app/modules/depiction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def get_cdk_depiction(
CIP=True,
unicolor=False,
):
"""
This function takes the user input SMILES and Depicts it.
"""This function takes the user input SMILES and Depicts it.
using the CDK Depiction Generator.
Expand Down Expand Up @@ -91,8 +90,8 @@ def get_cdk_depiction(


def get_rdkit_depiction(molecule: any, molSize=(512, 512), rotate=0, kekulize=True):
"""
This function takes the user input SMILES and Canonicalize it using the RDKit.
"""This function takes the user input SMILES and Canonicalize it using the
RDKit.
Args:
molecule (Chem.Mol): RDKit molecule object.
Expand Down
13 changes: 5 additions & 8 deletions app/modules/npscorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@


def get_np_model(model_path) -> dict:
"""
Load the NP model from a pickle file.
"""Load the NP model from a pickle file.
Parameters:
model_path (str): Path to the pickled model file.
Expand All @@ -37,8 +36,7 @@ def get_np_model(model_path) -> dict:


def score_mol_with_confidence(molecule) -> dict:
"""
Calculate NP-likeness score and confidence for a molecule.
"""Calculate NP-likeness score and confidence for a molecule.
Args:
molecule (rdkit.Chem.rdchem.Mol): The input molecule.
Expand Down Expand Up @@ -74,8 +72,7 @@ def score_mol_with_confidence(molecule) -> dict:


def score_mol(molecule) -> float:
"""
Calculate the Natural Product Likeness score for a given molecule.
"""Calculate the Natural Product Likeness score for a given molecule.
Parameters:
molecule (rdkit.Chem.Mol): RDKit molecule object.
Expand All @@ -88,8 +85,8 @@ def score_mol(molecule) -> float:


def get_np_score(molecule: any) -> str:
"""
Convert SMILES string to RDKit molecule object and generate the NP Score.
"""Convert SMILES string to RDKit molecule object and generate the NP
Score.
Parameters:
molecule (Chem.Mol): RDKit molecule object.
Expand Down
Loading

0 comments on commit 63616d6

Please sign in to comment.