Skip to content

Commit

Permalink
feat: end points order update, standardised endpoints naming and othe…
Browse files Browse the repository at this point in the history
…r formatting changes
  • Loading branch information
CS76 committed Jun 13, 2023
1 parent d20b06a commit e6d5a6c
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 176 deletions.
2 changes: 1 addition & 1 deletion app/modules/alldescriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
checkSMILES,
getTanimotoSimilarityRDKit,
)
from app.modules.toolkits.cdkmodules import (
from app.modules.toolkits.cdk import (
getCDKSDG,
JClass,
cdk_base,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app.modules.toolkits.rdkitmodules import getRDKitDescriptors, checkSMILES
from app.modules.toolkits.cdkmodules import (
from app.modules.toolkits.cdk import (
getSugarInfo,
getMurkoFramework,
getCDKDescriptors,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rdkit import Chem
import app.modules.toolkits.rdkitmodules as rdkitmodules
import app.modules.toolkits.cdkmodules as cdkmodules
from app.modules.coconutdescriptors import getCOCONUTDescriptors
import app.modules.toolkits.cdk as cdk
from app.modules.coconut.descriptors import getCOCONUTDescriptors


def getMolBlock(input_text: str):
Expand All @@ -14,9 +14,7 @@ def getMolBlock(input_text: str):
check = rdkitmodules.is_valid_molecule(input_text)

if check == "smiles":
mol_block = cdkmodules.getCDKSDGMol(input_text, V3000=False).replace(
"$$$$\n", ""
)
mol_block = cdk.getCDKSDGMol(input_text, V3000=False).replace("$$$$\n", "")
return mol_block
elif check == "mol":
return input_text
Expand Down Expand Up @@ -55,7 +53,7 @@ def getRepresentations(smiles: str):
if mol:
InChI = Chem.inchi.MolToInchi(mol)
InChI_Key = Chem.inchi.MolToInchiKey(mol)
Murko = cdkmodules.getMurkoFramework(smiles)
Murko = cdk.getMurkoFramework(smiles)
return {"InChI": InChI, "InChI_Key": InChI_Key, "Murko": Murko}


Expand All @@ -72,22 +70,22 @@ def COCONUTpreprocessing(input_text: str):
)
molecule_hash = getMolculeHash(standardised_SMILES)
parent_canonical_smiles = molecule_hash["Canonical_SMILES"]
parent_2D_molblock = cdkmodules.getCDKSDGMol(
parent_canonical_smiles, V3000=False
).replace("$$$$\n", "")
parent_2D_molblock = cdk.getCDKSDGMol(parent_canonical_smiles, V3000=False).replace(
"$$$$\n", ""
)
parent_3D_molblock = rdkitmodules.get3Dconformers(parent_canonical_smiles)
parent_2D_molblock_v3 = cdkmodules.getCDKSDGMol(
parent_2D_molblock_v3 = cdk.getCDKSDGMol(
parent_canonical_smiles, V3000=True
).replace("$$$$\n", "")
parent_representations = getRepresentations(parent_canonical_smiles)
parent_descriptors = getCOCONUTDescriptors(parent_canonical_smiles, "rdkit")

if rdkitmodules.has_stereochemistry(standardised_SMILES):
variant_isomeric_smiles = molecule_hash["Isomeric_SMILES"]
variant_2D_molblock = cdkmodules.getCDKSDGMol(
variant_2D_molblock = cdk.getCDKSDGMol(
variant_isomeric_smiles, V3000=False
).replace("$$$$\n", "")
variant_2D_molblock_v3 = cdkmodules.getCDKSDGMol(
variant_2D_molblock_v3 = cdk.getCDKSDGMol(
variant_isomeric_smiles, V3000=True
).replace("$$$$\n", "")
variant_3D_molblock = rdkitmodules.get3Dconformers(variant_isomeric_smiles)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/modules/depiction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rdkit import Chem
from rdkit.Chem import rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from app.modules.toolkits.cdkmodules import getCDKSDG, getCIPAnnotation
from app.modules.toolkits.cdk import getCDKSDG, getCIPAnnotation
from jpype import JClass


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/modules/toolkits/rdkitmodules.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from chembl_structure_pipeline import standardizer
from rdkit import Chem, DataStructs
from rdkit.Chem import AllChem, Descriptors, QED, Lipinski, rdMolDescriptors, rdmolops
from app.modules.toolkits.cdkmodules import getCDKSDGMol
from app.modules.toolkits.cdk import getCDKSDGMol
from hosegen import HoseGenerator


Expand Down
190 changes: 92 additions & 98 deletions app/routers/chem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
from fastapi.responses import Response, JSONResponse
from app.modules.npscorer import getNPScore
from app.modules.classyfire import classify, result
from app.modules.toolkits.cdkmodules import (
from app.modules.toolkits.cdk import (
getTanimotoSimilarityCDK,
getCDKHOSECodes,
)
from app.modules.toolkits.rdkitmodules import (
getTanimotoSimilarityRDKit,
getRDKitHOSECodes,
)
from app.modules.coconutdescriptors import getCOCONUTDescriptors
from app.modules.coconut.descriptors import getCOCONUTDescriptors
from app.modules.alldescriptors import getTanimotoSimilarity
from app.modules.coconutpreprocess import COCONUTpreprocessing
from app.modules.coconut.preprocess import COCONUTpreprocessing
import pandas as pd
from fastapi.templating import Jinja2Templates

Expand Down Expand Up @@ -58,28 +58,6 @@ async def SMILES_to_Stereo_Isomers(smiles: str):
return "Error reading SMILES string, check again."


@router.post("/standardize")
async def Standardize_Mol(mol: Annotated[str, Body(embed=True)]):
"""
Standardize molblock using the ChEMBL curation pipeline routine
and return the Standardized molecule, SMILES, InChI and InCHI-Key:
- **mol**: required
"""
if mol:
standardized_mol = standardizer.standardize_molblock(mol)
rdkit_mol = Chem.MolFromMolBlock(standardized_mol)
smiles = Chem.MolToSmiles(rdkit_mol, kekuleSmiles=True)
response = {}
response["standardized_mol"] = standardized_mol
response["cannonical_smiles"] = smiles
response["inchi"] = Chem.inchi.MolToInchi(rdkit_mol)
response["inchikey"] = Chem.inchi.MolToInchiKey(rdkit_mol)
return response
else:
return "Error reading SMILES string, check again."


@router.get("/descriptors")
async def SMILES_Descriptors(
smiles: str, format: Optional[str] = "json", toolkit: Optional[str] = "rdkit"
Expand Down Expand Up @@ -110,71 +88,53 @@ async def SMILES_Descriptors(
return getCOCONUTDescriptors(smiles, toolkit)


@router.get("/npscore")
async def NPlikeliness_Score(smiles: str):
"""
Generate natural product likeliness score based on RDKit implementation
- **SMILES**: required (query)
"""
if smiles:
np_score = getNPScore(smiles)
return np_score


@router.get("/classyfire/classify")
async def ClassyFire_Classify(smiles: str):
@router.get("/HOSEcode")
async def HOSE_Codes(
smiles: str,
spheres: int,
toolkit: Optional[str] = "cdk",
ringsize: Optional[bool] = False,
):
"""
Generate ClassyFire-based classifications using SMILES as input.
Generates HOSE Codes using CDK/RDKit.
- **SMILES**: required (query)
- **spheres**: required (query)
- **toolkit**: Optional (default:CDK)
- **ringsize**: Optional (default:False)
"""
if smiles:
data = await classify(smiles)
return data


@router.get("/classyfire/{id}/result")
async def ClassyFire_result(id: str):
"""
Get the ClassyFire classification results using ID.
- **ID**: required (query)
"""
if id:
data = await result(id)
return data
if toolkit == "cdk":
return await getCDKHOSECodes(smiles, spheres, ringsize)
elif toolkit == "rdkit":
return await getRDKitHOSECodes(smiles, spheres)
else:
return "Error reading SMILES string, check again."


@router.get("/tanimoto")
async def Tanimoto_Similarity(smiles: str, toolkit: Optional[str] = "cdk"):
@router.post("/standardize")
async def Standardize_Mol(mol: Annotated[str, Body(embed=True)]):
"""
Generate the Tanimoto similarity index for a given pair of SMILES strings.
Standardize molblock using the ChEMBL curation pipeline routine
and return the Standardized molecule, SMILES, InChI and InCHI-Key:
- **SMILES**: required (query)
- **toolkit**: optional (defaults: cdk)
- **mol**: required
"""
if len(smiles.split(",")) == 2:
try:
smiles1, smiles2 = smiles.split(",")
if toolkit == "rdkit":
Tanimoto = getTanimotoSimilarityRDKit(smiles1, smiles2)
else:
Tanimoto = getTanimotoSimilarityCDK(smiles1, smiles2)
return Tanimoto
except ValueError:
return 'Please give a SMILES pair with "," separated. (Example: api.naturalproducts.net/chem/tanimoto?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CN1C=NC2=C1C(=O)NC(=O)N2C)'
elif len(smiles.split(",")) > 2:
try:
matrix = getTanimotoSimilarity(smiles, toolkit)
return Response(content=matrix, media_type="text/html")
except ValueError:
return 'Please give a SMILES pair with "," separated. (Example: api.naturalproducts.net/chem/tanimoto?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CN1C=NC2=C1C(=O)NC(=O)N2C)'
if mol:
standardized_mol = standardizer.standardize_molblock(mol)
rdkit_mol = Chem.MolFromMolBlock(standardized_mol)
smiles = Chem.MolToSmiles(rdkit_mol, kekuleSmiles=True)
response = {}
response["standardized_mol"] = standardized_mol
response["cannonical_smiles"] = smiles
response["inchi"] = Chem.inchi.MolToInchi(rdkit_mol)
response["inchikey"] = Chem.inchi.MolToInchiKey(rdkit_mol)
return response
else:
return 'Please give a SMILES pair with "," separated. (Example: api.naturalproducts.net/chem/tanimoto?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CN1C=NC2=C1C(=O)NC(=O)N2C)'
return "Error reading SMILES string, check again."


@router.get("/checkerrors")
@router.get("/errors")
async def Check_Errors(smiles: str, fix: Optional[bool] = False):
"""
Check issues for a given SMILES string and standardize it using the ChEMBL curation pipeline.
Expand Down Expand Up @@ -220,31 +180,47 @@ async def Check_Errors(smiles: str, fix: Optional[bool] = False):
return "Error reading SMILES string, check again."


@router.get("/hosecode")
async def HOSE_Codes(
smiles: str,
spheres: int,
toolkit: Optional[str] = "cdk",
ringsize: Optional[bool] = False,
):
@router.get("/nplikeness/score")
async def NPlikeliness_Score(smiles: str):
"""
Generates HOSE Codes using CDK/RDKit.
Generate natural product likeliness score based on RDKit implementation
- **SMILES**: required (query)
- **spheres**: required (query)
- **toolkit**: Optional (default:CDK)
- **ringsize**: Optional (default:False)
"""
if smiles:
if toolkit == "cdk":
return await getCDKHOSECodes(smiles, spheres, ringsize)
elif toolkit == "rdkit":
return await getRDKitHOSECodes(smiles, spheres)
np_score = getNPScore(smiles)
return np_score


@router.get("/tanimoto")
async def Tanimoto_Similarity(smiles: str, toolkit: Optional[str] = "cdk"):
"""
Generate the Tanimoto similarity index for a given pair of SMILES strings.
- **SMILES**: required (query)
- **toolkit**: optional (defaults: cdk)
"""
if len(smiles.split(",")) == 2:
try:
smiles1, smiles2 = smiles.split(",")
if toolkit == "rdkit":
Tanimoto = getTanimotoSimilarityRDKit(smiles1, smiles2)
else:
Tanimoto = getTanimotoSimilarityCDK(smiles1, smiles2)
return Tanimoto
except ValueError:
return 'Please give a SMILES pair with "," separated. (Example: api.naturalproducts.net/chem/tanimoto?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CN1C=NC2=C1C(=O)NC(=O)N2C)'
elif len(smiles.split(",")) > 2:
try:
matrix = getTanimotoSimilarity(smiles, toolkit)
return Response(content=matrix, media_type="text/html")
except ValueError:
return 'Please give a SMILES pair with "," separated. (Example: api.naturalproducts.net/chem/tanimoto?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CN1C=NC2=C1C(=O)NC(=O)N2C)'
else:
return "Error reading SMILES string, check again."
return 'Please give a SMILES pair with "," separated. (Example: api.naturalproducts.net/chem/tanimoto?smiles=CN1C=NC2=C1C(=O)N(C(=O)N2C)C,CN1C=NC2=C1C(=O)NC(=O)N2C)'


@router.get("/coconutpreprocessing")
@router.get("/coconut/pre-processing")
async def COCONUT_Preprocessing(smiles: str):
"""
Generate Input JSON file for COCONUT.
Expand All @@ -258,7 +234,25 @@ async def COCONUT_Preprocessing(smiles: str):
return "Error reading SMILES string, check again."


# @app.get("/molecules/", response_model=List[schemas.Molecule])
# def read_molecules(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
# molecules = crud.get_molecules(db, skip=skip, limit=limit)
# return molecules
@router.get("/classyfire/classify")
async def ClassyFire_Classify(smiles: str):
"""
Generate ClassyFire-based classifications using SMILES as input.
- **SMILES**: required (query)
"""
if smiles:
data = await classify(smiles)
return data


@router.get("/classyfire/{id}/result")
async def ClassyFire_result(id: str):
"""
Get the ClassyFire classification results using ID.
- **ID**: required (query)
"""
if id:
data = await result(id)
return data
Loading

0 comments on commit e6d5a6c

Please sign in to comment.