From 593342c442b877ad9e4a6b28681ef3f14f907eb4 Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Sat, 9 Sep 2023 12:41:40 +0200 Subject: [PATCH 1/3] fix: resolves #387, #388 --- app/modules/tools/sugar_removal.py | 6 +++--- app/modules/tools/surge.py | 6 +++--- app/routers/tools.py | 2 +- docs/index.md | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/modules/tools/sugar_removal.py b/app/modules/tools/sugar_removal.py index a5e6076..6bd39f3 100644 --- a/app/modules/tools/sugar_removal.py +++ b/app/modules/tools/sugar_removal.py @@ -130,10 +130,10 @@ def remove_linear_and_circular_sugar(molecule: any): molecule, True ) try: + print(MoleculeWithoutSugars) S_SMILES = SmilesGenerator.create(MoleculeWithoutSugars) + return str(S_SMILES) except Exception as e: - print(e) - return "Error generating SMILES" - return str(S_SMILES) + raise Exception(f"{str(e)}") else: return "No Linear or Circular sugars found" diff --git a/app/modules/tools/surge.py b/app/modules/tools/surge.py index c37dff8..a29ff53 100644 --- a/app/modules/tools/surge.py +++ b/app/modules/tools/surge.py @@ -70,8 +70,8 @@ def generate_structures_SURGE(molecular_formula: str) -> Union[list, str]: smiles = [line.strip() for line in output_lines] return smiles else: - return f"Error running surge: {stderr.decode('utf-8')}" - except Exception as e: - return f"An error occurred: {str(e)}" + raise Exception(f"Error running surge: {stderr.decode('utf-8')}") + except Exception: + raise Exception(f"Error running surge: {stderr.decode('utf-8')}") else: return "The molecular formula contains more heavy atoms than allowed (10 Heavy Atoms max)." diff --git a/app/routers/tools.py b/app/routers/tools.py index 3c006e9..b5486c4 100644 --- a/app/routers/tools.py +++ b/app/routers/tools.py @@ -211,8 +211,8 @@ async def remove_linear_sugars( - str: The modified SMILES string with linear sugars removed. """ + mol = parse_input(smiles, "cdk", False) try: - mol = parse_input(smiles, "cdk", False) removed_smiles = remove_linear_sugar(mol) if removed_smiles: return removed_smiles diff --git a/docs/index.md b/docs/index.md index 9cd3918..d935839 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,7 +2,7 @@ layout: home hero: - name: "Cheminformatics Microservice (CM)" + name: "Cheminformatics Microservice" text: "" tagline: Effortlessly integrate cheminformatics tools into your web application or workflows. actions: @@ -17,7 +17,7 @@ features: - title: Multi-Tool Kit Support (Portability) details: Seamlessly incorporate and utilize various toolkits, such as RDKit, CDK, and OpenBabel, to improve your cheminformatics and computational chemistry tasks without the need for complex setup. Maximize the benefits of different frameworks available. - title: Consistent and Reproducible Environments (Reproducibility) - details: CPM packages toolkits and all their dependencies, libraries, and system tools, into a single container (including the entire runtime ensuring consistency across different deployments). + details: Cheminformatics Microservice packages toolkits and all their dependencies, libraries, and system tools, into a single container (including the entire runtime ensuring consistency across different deployments). - title: Advanced logging (Metrics) - details: Prometheus and Grafana provide a powerful monitoring solution for CPM that collects and visualizes metrics in real time, enabling efficient tracking of system health, performance, and behaviour. + details: Prometheus and Grafana provide a powerful monitoring solution for Cheminformatics Microservice that collects and visualizes metrics in real time, enabling efficient tracking of system health, performance, and behaviour. --- From e72dcbc7e85c287150c084921e0984c640181f2a Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Sat, 9 Sep 2023 14:58:34 +0200 Subject: [PATCH 2/3] fix: test case failing issue fix and OCSR parameter description fixes --- app/main.py | 6 ++++-- app/routers/ocsr.py | 26 ++++++++++++++++---------- tests/test_tools.py | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/main.py b/app/main.py index 9933c78..b711b14 100644 --- a/app/main.py +++ b/app/main.py @@ -3,7 +3,9 @@ from fastapi.responses import RedirectResponse from fastapi_versioning import VersionedFastAPI -from .routers import tools, depict, converters, chem, ocsr +from .routers import tools, depict, converters, chem + +# , ocsr from fastapi.middleware.cors import CORSMiddleware from prometheus_fastapi_instrumentator import Instrumentator @@ -30,7 +32,7 @@ app.include_router(converters.router) app.include_router(depict.router) app.include_router(tools.router) -app.include_router(ocsr.router) +# app.include_router(ocsr.router) app = VersionedFastAPI( app, diff --git a/app/routers/ocsr.py b/app/routers/ocsr.py index c9d385a..9c14f05 100644 --- a/app/routers/ocsr.py +++ b/app/routers/ocsr.py @@ -3,12 +3,12 @@ from fastapi.responses import JSONResponse from urllib.request import urlopen from urllib.parse import urlsplit -from fastapi import Body, APIRouter, status, HTTPException +from fastapi import Body, APIRouter, status, HTTPException, File, UploadFile from app.modules.decimer import get_predicted_segments_from_file from app.schemas import HealthCheck from app.schemas.error import ErrorResponse, BadRequestModel, NotFoundModel from app.schemas.ocsr_schema import ExtractChemicalInfoResponse -from fastapi import UploadFile +from typing import Annotated router = APIRouter( prefix="/ocsr", @@ -63,7 +63,7 @@ async def Extract_ChemicalInfo_From_File( path: str = Body( None, embed=True, - description="URL or local file path to the chemical structure depiction image.", + description="Local or Remote path to the image file", openapi_examples={ "example1": { "summary": "Cheminformatics - Article example image", @@ -75,20 +75,24 @@ async def Extract_ChemicalInfo_From_File( }, }, ), - reference: str = Body(None, embed=True, description="Reference information."), + reference: str = Body( + None, + embed=True, + description="User defined reference information for tracking", + ), img: str = Body( None, embed=True, - description="Bytes content of the chemical structure depiction image.", + description="Image: Bytes content of the chemical structure depiction image", ), ): """ Detect, segment and convert a chemical structure depiction into a SMILES string using the DECIMER modules. Parameters: - - **path**: optional if img is provided (str): URL or local file path to the chemical structure depiction image. - - **reference**: optional (str): URL or local file path to the chemical structure depiction image. - - **img**: optional if a valid path is provided (str): URL or local file path to the chemical structure depiction image. + - **path**: optional if img is provided (str): Local or Remote path to the image file. + - **reference**: optional (str): User defined reference information for tracking. + - **img**: optional if a valid path is provided (str): Image: Bytes content of the chemical structure depiction image. Returns: - JSONResponse: A JSON response containing the extracted SMILES and the reference (if provided). @@ -139,12 +143,14 @@ async def Extract_ChemicalInfo_From_File( 422: {"description": "Unprocessable Entity", "model": ErrorResponse}, }, ) -async def extract_chemicalinfo_from_upload(file: UploadFile): +async def extract_chemicalinfo_from_upload( + file: Annotated[UploadFile, File(description="Chemical structure depiction image")], +): """ Detect, segment and convert a chemical structure depiction in the uploaded image file into a SMILES string using the DECIMER modules. Parameters: - - **file**: required (File): + - **file**: required (File): Chemical structure depiction image Returns: - JSONResponse: A JSON response containing the extracted SMILES and the reference (if provided). diff --git a/tests/test_tools.py b/tests/test_tools.py index 41965fc..d19662b 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -50,7 +50,7 @@ def test_sugars_info(input, response_text, response_code): "input,response_text, response_code", [ ("OCC(O)C(O)C(O)C(O)C1OC(CO)C(O)C(O)C1O", '"C(C1C(C(C(CO1)O)O)O)O"', 200), - ("INVALID_INPUT", "", 500), + ("INVALID_INPUT", "", 422), ], ) def test_remove_linear_sugars(input, response_text, response_code): From 4cd86e67184b86f06f851e95da97b44e6a5f859f Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Mon, 11 Sep 2023 10:12:57 +0200 Subject: [PATCH 3/3] fix: reenabled ocsr module --- app/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index b711b14..9933c78 100644 --- a/app/main.py +++ b/app/main.py @@ -3,9 +3,7 @@ from fastapi.responses import RedirectResponse from fastapi_versioning import VersionedFastAPI -from .routers import tools, depict, converters, chem - -# , ocsr +from .routers import tools, depict, converters, chem, ocsr from fastapi.middleware.cors import CORSMiddleware from prometheus_fastapi_instrumentator import Instrumentator @@ -32,7 +30,7 @@ app.include_router(converters.router) app.include_router(depict.router) app.include_router(tools.router) -# app.include_router(ocsr.router) +app.include_router(ocsr.router) app = VersionedFastAPI( app,