diff --git a/Dockerfile b/Dockerfile index c033df7..ff46e4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,10 @@ RUN apt-get update && \ apt-get update -y && \ apt-get install -y openjdk-11-jre +RUN wget -O surge "https://github.com/StructureGenerator/surge/releases/download/v1.0/surge-linux-v1.0" +RUN chmod +x surge +RUN mv surge /usr/bin + RUN conda install -c conda-forge python>=PYTHON_VERSION RUN conda install -c conda-forge rdkit>=RDKIT_VERSION RUN conda install -c conda-forge openbabel>=OPENBABEL_VERSION @@ -41,4 +45,4 @@ RUN pip3 install --no-cache-dir chembl_structure_pipeline --no-deps COPY ./app /code/app -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--workers", "4"] \ No newline at end of file +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--workers", "4"] diff --git a/app/main.py b/app/main.py index 221704b..fae1e46 100644 --- a/app/main.py +++ b/app/main.py @@ -2,7 +2,7 @@ from fastapi.responses import RedirectResponse from fastapi_versioning import VersionedFastAPI -from .routers import chem, converters, depict, ocsr +from .routers import chem, converters, depict, tools # , ocsr from fastapi.middleware.cors import CORSMiddleware from prometheus_fastapi_instrumentator import Instrumentator @@ -35,7 +35,8 @@ app.include_router(chem.router) app.include_router(converters.router) app.include_router(depict.router) -app.include_router(ocsr.router) +app.include_router(tools.router) +# app.include_router(ocsr.router) app = VersionedFastAPI( app, diff --git a/app/modules/tools/surge.py b/app/modules/tools/surge.py new file mode 100644 index 0000000..11a137b --- /dev/null +++ b/app/modules/tools/surge.py @@ -0,0 +1,20 @@ +from subprocess import Popen, PIPE + + +def generateStructures(mf: str): + """This function uses the sugar removal utility and checks + whether a molecule has ring or linear sugars + Args: + smiles (string): SMILES string given by the user. + Returns: + (boolean): True or false values whtehr or not molecule has sugar. + """ + smiles = [] + process = Popen( + ["surge", "-P", "-T", "-B1,2,3,4,5,7,9", "-t0", "-f0", "-S", mf], + stdout=PIPE, + stderr=PIPE, + ) + for line in iter(process.stdout.readline, b""): + smiles.append(line.decode("utf-8").rstrip()) + return smiles diff --git a/app/routers/tools.py b/app/routers/tools.py new file mode 100644 index 0000000..64c11bd --- /dev/null +++ b/app/routers/tools.py @@ -0,0 +1,24 @@ +from fastapi import APIRouter +from app.modules.tools.surge import generateStructures + +router = APIRouter( + prefix="/tools", + tags=["tools"], + dependencies=[], + responses={404: {"description": "Not found"}}, +) + + +@router.get("/") +async def tools_index(): + return {"module": "tools", "message": "Successful", "status": 200} + + +@router.get("/generate-structures") +async def Generate_Structures(molecular_formula: str): + """ + Extract chemical structure depictions and convert them into SMILES using DECIMER: + + - **Images**: required (query) + """ + return generateStructures(molecular_formula)