Skip to content

Commit

Permalink
Merge pull request #389 from Steinbeck-Lab/dev-chandu
Browse files Browse the repository at this point in the history
fix: resolves #387, #388
  • Loading branch information
CS76 authored Sep 11, 2023
2 parents 7580214 + 4cd86e6 commit 55b8c10
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
6 changes: 3 additions & 3 deletions app/modules/tools/sugar_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions app/modules/tools/surge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
26 changes: 16 additions & 10 deletions app/routers/ocsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion app/routers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: CM 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 CM 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.
---
2 changes: 1 addition & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 55b8c10

Please sign in to comment.