Skip to content

Commit

Permalink
Merge pull request #441 from Steinbeck-Lab/dev-kohulan
Browse files Browse the repository at this point in the history
feat: add pre-commit
  • Loading branch information
NishaSharma14 authored Jan 11, 2024
2 parents 64f62cc + ecc84c1 commit ed1129f
Show file tree
Hide file tree
Showing 89 changed files with 978 additions and 555 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# - Fetch Latest release.
# - Build the latest docker image in development which needs test to pass first.
# - Push the docker image to Github Artifact Registry-Dev.
#
#
# Maintainers:
# - name: Nisha Sharma
# - email: [email protected]
Expand All @@ -28,13 +28,13 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - Fetch Latest release.
# - Build the latest docker image in production.
# - Push the docker image to Github Artifact Registry-Prod.
#
#
# Maintainers:
# - name: Nisha Sharma
# - email: [email protected]
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}

#Build and push Docker image
#Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
Expand All @@ -58,4 +58,4 @@ jobs:
RELEASE_VERSION=${{ steps.fetch-latest-release.outputs.tag_name }}
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:${{ steps.fetch-latest-release.outputs.tag_name }}, ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:latest
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}
password: ${{ env.DOCKER_HUB_PASSWORD }}
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - Test linting with pylint.
# - Test the code with pytest.
# - Trigger release-please action to create release which needs test to pass first.
#
#
# Maintainers:
# - name: Nisha Sharma
# - email: [email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-check.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Unit test and Lint check

on:
on:
pull_request:
branches:
- development
- main

jobs:
test:
uses: Steinbeck-Lab/cheminformatics-microservice/.github/workflows/test.yml@main
uses: Steinbeck-Lab/cheminformatics-microservice/.github/workflows/test.yml@main
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: test

on:
workflow_call:
workflow_call:

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ node_modules
docs/_build/

#grafana
grafana_data/
grafana_data/
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
exclude: ^(pre_commit/resources/|testing/resources/python3_hooks_repo/)
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [
"--per-file-ignores=__init__.py:F401",
"--ignore=E402,E501,W503",
".",
]
3 changes: 1 addition & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build:
jobs:
post_install:
- python -m pip install --no-deps -r docs/extra-requirements.txt

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
Expand All @@ -27,4 +27,3 @@ formats:
python:
install:
- requirements: docs/requirements.txt

2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors:
orcid: "https://orcid.org/0000-0003-1554-6666"
- family-names: "Steinbeck"
given-names: "Christoph"
orcid: "https://orcid.org/0000-0001-6966-0814"
orcid: "https://orcid.org/0000-0001-6966-0814"
- family-names: "Rajan"
given-names: "Kohulan"
orcid: "https://orcid.org/0000-0003-1066-7792"
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><a href="https://api.naturalproducts.net/" target="_blank"><img src="/public/img/logo.png" width="400" alt="CMS Logo"></a></p>
<p align="center"><a href="https://api.naturalproducts.net/" target="_blank"><img src="/public/img/logo.png" width="400" alt="CMS Logo"></a></p>

[![License](https://img.shields.io/badge/License-MIT%202.0-blue.svg)](https://opensource.org/licenses/MIT)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-blue.svg)](https://GitHub.com/Steinbeck-Lab/cheminformatics-microservice/graphs/commit-activity)
Expand Down Expand Up @@ -48,7 +48,7 @@ https://docs.api.naturalproducts.net/standalone.html
## License :scroll:

This project is licensed under the MIT License - see the [LICENSE](https://github.com/Steinbeck-Lab/cheminformatics-microservice/blob/main/LICENSE) file for details

## Citation :newspaper:

*Paper*
Expand All @@ -59,7 +59,7 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu

## Maintained by :wrench:

Cheminformatics Microservice and [Natural Products Online](https://naturalproducts.net) are developed and maintained by the [Steinbeck group](https://cheminf.uni-jena.de) at the [Friedrich Schiller University](https://www.uni-jena.de/en/) Jena, Germany.
Cheminformatics Microservice and [Natural Products Online](https://naturalproducts.net) are developed and maintained by the [Steinbeck group](https://cheminf.uni-jena.de) at the [Friedrich Schiller University](https://www.uni-jena.de/en/) Jena, Germany.
The code for this web application is released under the [MIT license](https://opensource.org/licenses/MIT). Copyright © CC-BY-SA 2023
<p align="center"><a href="https://cheminf.uni-jena.de/" target="_blank"><img src="https://github.com/Kohulan/DECIMER-Image-to-SMILES/blob/master/assets/CheminfGit.png" width="800" alt="cheminf Logo"></a></p>

Expand All @@ -78,5 +78,3 @@ Funded by the [Deutsche Forschungsgemeinschaft (DFG, German Research Foundation)
<img src="https://github.com/Steinbeck-Lab/cheminformatics-microservice/assets/30716951/45c8e153-8322-4563-a51d-cbdbe4e08627" width="30%" alt="Chembiosys Logo">
</a>
</div>


2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

"""
Cheminformatics Microservice Python Modules.
Expand All @@ -8,5 +7,6 @@
For comments, bug reports or feature requests,
please raise an issue on our GitHub repository.
"""
from __future__ import annotations

__version__ = "1.0.0"
1 change: 1 addition & 0 deletions app/dependencies.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# from fastapi import Header, HTTPException
from __future__ import annotations

Check warning on line 2 in app/dependencies.py

View check run for this annotation

Codecov / codecov/patch

app/dependencies.py#L2

Added line #L2 was not covered by tests
4 changes: 3 additions & 1 deletion app/exception_handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from fastapi.responses import JSONResponse
from __future__ import annotations

from fastapi import Request
from fastapi.responses import JSONResponse


class InvalidInputException(Exception):
Expand Down
24 changes: 16 additions & 8 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from __future__ import annotations

import os
from fastapi import FastAPI, status
from fastapi.responses import RedirectResponse
from fastapi_versioning import VersionedFastAPI

from .routers import tools, depict, converters, chem, ocsr
from fastapi import FastAPI
from fastapi import status
from fastapi.middleware.cors import CORSMiddleware

from fastapi.responses import RedirectResponse
from fastapi_versioning import VersionedFastAPI
from prometheus_fastapi_instrumentator import Instrumentator
from app.schemas import HealthCheck

from app.exception_handlers import InvalidInputException, input_exception_handler
from .routers import chem
from .routers import converters
from .routers import depict
from .routers import ocsr
from .routers import tools
from app.exception_handlers import input_exception_handler
from app.exception_handlers import InvalidInputException
from app.schemas import HealthCheck

app = FastAPI(
title="Cheminformatics Microservice",
Expand Down Expand Up @@ -77,7 +84,8 @@ async def add_cors_headers(request, call_next):
for sub_app in app.routes:
if hasattr(sub_app.app, "add_exception_handler"):
sub_app.app.add_exception_handler(
InvalidInputException, input_exception_handler
InvalidInputException,
input_exception_handler,
)


Expand Down
50 changes: 31 additions & 19 deletions app/modules/all_descriptors.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from rdkit.Chem import Descriptors, QED, Lipinski, rdMolDescriptors, rdmolops
from __future__ import annotations

from typing import Union
from app.modules.toolkits.rdkit_wrapper import (
check_RO5_violations,
get_tanimoto_similarity_rdkit,
)
from app.modules.toolkits.cdk_wrapper import (
get_CDK_SDG,
JClass,
cdk_base,
get_aromatic_ring_count,
get_tanimoto_similarity_CDK,
get_vander_waals_volume,
)

from rdkit.Chem import Descriptors
from rdkit.Chem import Lipinski
from rdkit.Chem import QED
from rdkit.Chem import rdMolDescriptors
from rdkit.Chem import rdmolops

from app.modules.toolkits.cdk_wrapper import cdk_base
from app.modules.toolkits.cdk_wrapper import get_aromatic_ring_count
from app.modules.toolkits.cdk_wrapper import get_CDK_SDG
from app.modules.toolkits.cdk_wrapper import get_tanimoto_similarity_CDK
from app.modules.toolkits.cdk_wrapper import get_vander_waals_volume
from app.modules.toolkits.cdk_wrapper import JClass
from app.modules.toolkits.helpers import parse_input
from app.modules.toolkits.rdkit_wrapper import check_RO5_violations
from app.modules.toolkits.rdkit_wrapper import get_tanimoto_similarity_rdkit


def get_all_rdkit_descriptors(molecule: any) -> Union[tuple, str]:
Expand Down Expand Up @@ -105,7 +109,7 @@ def get_all_cdk_descriptors(molecule: any) -> Union[tuple, str]:
.toString()
)
TotalExactMass = JClass(
cdk_base + ".tools.manipulator.AtomContainerManipulator"
cdk_base + ".tools.manipulator.AtomContainerManipulator",
).getTotalExactMass(SDGMol)
ALogP = (
JClass(cdk_base + ".qsar.descriptors.molecular.ALOGPDescriptor")()
Expand All @@ -114,7 +118,7 @@ def get_all_cdk_descriptors(molecule: any) -> Union[tuple, str]:
)
NumRotatableBonds = (
JClass(
cdk_base + ".qsar.descriptors.molecular.RotatableBondsCountDescriptor"
cdk_base + ".qsar.descriptors.molecular.RotatableBondsCountDescriptor",
)()
.calculate(SDGMol)
.getValue()
Expand All @@ -127,7 +131,7 @@ def get_all_cdk_descriptors(molecule: any) -> Union[tuple, str]:
)
HBondAcceptorCountDescriptor = (
JClass(
cdk_base + ".qsar.descriptors.molecular.HBondAcceptorCountDescriptor"
cdk_base + ".qsar.descriptors.molecular.HBondAcceptorCountDescriptor",
)()
.calculate(SDGMol)
.getValue()
Expand All @@ -145,15 +149,21 @@ def get_all_cdk_descriptors(molecule: any) -> Union[tuple, str]:
AromaticRings = get_aromatic_ring_count(SDGMol)
QEDWeighted = None
FormalCharge = JClass(
cdk_base + ".tools.manipulator.AtomContainerManipulator"
cdk_base + ".tools.manipulator.AtomContainerManipulator",
).getTotalFormalCharge(SDGMol)
FractionalCSP3Descriptor = (
JClass(cdk_base + ".qsar.descriptors.molecular.FractionalCSP3Descriptor")()
.calculate(SDGMol)
.getValue()
.toString()
)
NumRings = JClass(cdk_base + ".graph.Cycles").mcb(SDGMol).numberOfCycles()
NumRings = (
JClass(
cdk_base + ".graph.Cycles",
)
.mcb(SDGMol)
.numberOfCycles()
)
VABCVolume = get_vander_waals_volume(SDGMol)

return (
Expand Down Expand Up @@ -229,7 +239,9 @@ def get_cdk_rdkit_combined_descriptors(
combined_dict = {
descriptor: (rdkit_desc, cdk_desc)
for descriptor, rdkit_desc, cdk_desc in zip(
all_descriptors, rdkit_descriptors, cdk_descriptors
all_descriptors,
rdkit_descriptors,
cdk_descriptors,
)
}
return combined_dict
Expand Down
7 changes: 5 additions & 2 deletions app/modules/classyfire.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import requests
from __future__ import annotations

import json

import requests


async def classify(smiles: str) -> dict:
"""
Expand All @@ -22,7 +25,7 @@ async def classify(smiles: str) -> dict:

# Prepare payload for the API request
payload = json.dumps(
{"label": "query", "query_input": smiles, "query_type": "STRUCTURE"}
{"label": "query", "query_input": smiles, "query_type": "STRUCTURE"},
)

# Set headers for the API request
Expand Down
20 changes: 11 additions & 9 deletions app/modules/coconut/descriptors.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from app.modules.toolkits.rdkit_wrapper import get_rdkit_descriptors
from typing import Dict, Union
from app.modules.toolkits.cdk_wrapper import (
get_murko_framework,
get_CDK_descriptors,
)
from __future__ import annotations

from typing import Dict
from typing import Union

from app.modules.all_descriptors import get_cdk_rdkit_combined_descriptors
from app.modules.npscorer import get_np_score
from app.modules.tools.sugar_removal import get_sugar_info
from app.modules.toolkits.cdk_wrapper import get_CDK_descriptors
from app.modules.toolkits.cdk_wrapper import get_murko_framework
from app.modules.toolkits.helpers import parse_input
from app.modules.toolkits.rdkit_wrapper import get_rdkit_descriptors
from app.modules.tools.sugar_removal import get_sugar_info


def get_descriptors(smiles: str, toolkit: str) -> Union[tuple, str]:
Expand Down Expand Up @@ -60,7 +62,7 @@ def get_COCONUT_descriptors(smiles: str, toolkit: str) -> Union[Dict[str, float]

CombinedDescriptors = list(Descriptors)
CombinedDescriptors.extend(
[hasLinearSugar, hasCircularSugars, framework, nplikeliness]
[hasLinearSugar, hasCircularSugars, framework, nplikeliness],
)

DescriptorList = (
Expand Down Expand Up @@ -91,7 +93,7 @@ def get_COCONUT_descriptors(smiles: str, toolkit: str) -> Union[Dict[str, float]
"circular_sugars": hasCircularSugars,
"murko_framework": framework,
"nplikeness": nplikeliness,
}
},
)

return (
Expand Down
Loading

0 comments on commit ed1129f

Please sign in to comment.