added new fetures to API
This commit is contained in:
parent
be097fa937
commit
0eff94b6fc
62
api.py
62
api.py
|
@ -1,10 +1,20 @@
|
||||||
from app import app as flask_app
|
from app import app as flask_app
|
||||||
#app.run(debug=True, host="0.0.0.0", port=8080)
|
#app.run(debug=True, host="0.0.0.0", port=8080)
|
||||||
|
from random import choice, shuffle
|
||||||
|
from string import digits, ascii_lowercase
|
||||||
from fastapi import Body,FastAPI
|
from fastapi import Body,FastAPI
|
||||||
from fastapi.middleware.wsgi import WSGIMiddleware
|
from fastapi.middleware.wsgi import WSGIMiddleware
|
||||||
from flask import Flask, escape, request
|
from flask import Flask, escape, request
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
import os, subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def gen_word(N, min_N_dig, min_N_low):
|
||||||
|
choose_from = [digits]*min_N_dig + [ascii_lowercase]*min_N_low
|
||||||
|
choose_from.extend([digits + ascii_lowercase] * (N-min_N_low-min_N_dig))
|
||||||
|
chars = [choice(bet) for bet in choose_from]
|
||||||
|
shuffle(chars)
|
||||||
|
return ''.join(chars)
|
||||||
|
|
||||||
import mysql.connector as con
|
import mysql.connector as con
|
||||||
mycon = con.connect(host=flask_app.config['DB_HOST'],user=flask_app.config['DB_USER'],password=flask_app.config['DB_PASSWORD'],port=flask_app.config['DB_PORT'],database=flask_app.config['DB_NAME'])
|
mycon = con.connect(host=flask_app.config['DB_HOST'],user=flask_app.config['DB_USER'],password=flask_app.config['DB_PASSWORD'],port=flask_app.config['DB_PORT'],database=flask_app.config['DB_NAME'])
|
||||||
|
@ -18,18 +28,16 @@ def flask_main():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
app = FastAPI(title="Curie-API",
|
app = FastAPI(title="Curie-API",
|
||||||
description="API for accessing most of the features.",
|
description="API for accessing some of the features.",
|
||||||
version="0.1",)
|
version="0.1",)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/v1")
|
@app.get("/v1")
|
||||||
def API_Version():
|
async def API_Version():
|
||||||
return {"message":"Curie-API v1"}
|
return {"message":"Curie-API v1"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/v1/status/{job_id}")
|
@app.get("/v1/status/{job_id}")
|
||||||
def get_status(job_id: str):
|
async def get_status(job_id: str):
|
||||||
sqlQuery = 'select id, protein_name, ligand_name, date, description, done from curieweb where id="%s"' % (job_id)
|
sqlQuery = 'select id, protein_name, ligand_name, date, description, done from curieweb where id="%s"' % (job_id)
|
||||||
mycursor.execute(sqlQuery)
|
mycursor.execute(sqlQuery)
|
||||||
records = mycursor.fetchall()
|
records = mycursor.fetchall()
|
||||||
|
@ -38,5 +46,47 @@ def get_status(job_id: str):
|
||||||
r = records[0]
|
r = records[0]
|
||||||
return {"job_id":r[0],"Protein Name":r[1],"Ligand Name":r[2],"Submitted On":r[3],"Job Description":r[4],"Job Status":r[5]}
|
return {"job_id":r[0],"Protein Name":r[1],"Ligand Name":r[2],"Submitted On":r[3],"Job Description":r[4],"Job Status":r[5]}
|
||||||
|
|
||||||
|
@app.get("/v1/3DModels/{job_id}")
|
||||||
|
async def get_models(job_id: str):
|
||||||
|
sqlQuery = 'select done from curieweb where id="%s"' % (job_id)
|
||||||
|
mycursor.execute(sqlQuery)
|
||||||
|
records = mycursor.fetchall()
|
||||||
|
if records == []:
|
||||||
|
return {"message":"Invalid Job ID"}
|
||||||
|
if records[0][0] == 0:
|
||||||
|
return {"message": "The job is still qeued"}
|
||||||
|
return {"USDZ":"/static/uploads/3DModels/" + str(job_id) + ".usdz","glTF":"/static/uploads/3DModels/" + str(job_id) + ".gltf"}
|
||||||
|
|
||||||
|
@app.get("/v1/Report/{job_id}")
|
||||||
|
async def get_report(job_id:str):
|
||||||
|
sqlQuery = 'select done from curieweb where id="%s"' % (job_id)
|
||||||
|
mycursor.execute(sqlQuery)
|
||||||
|
records = mycursor.fetchall()
|
||||||
|
if records == []:
|
||||||
|
return {"message":"Invalid Job ID"}
|
||||||
|
if records[0][0] == 0:
|
||||||
|
return {"message": "The job is still qeued"}
|
||||||
|
return {"PDF Report":"/static/uploads/reports/"+str(job_id)+".pdf"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/v1/docking/automatic")
|
||||||
|
async def docking_automatic(pdb: str, smiles:str,compound_name:str,email:str,description:str):
|
||||||
|
if len(pdb) != 0:
|
||||||
|
return {"message": "Invalid PDB ID"}
|
||||||
|
|
||||||
|
sqlQuery = "insert into curieweb (id, email, pdb, ligand_smile, ligand_name, date, description) values (%s,%s,%s,%s,%s,CURDATE(),%s) "
|
||||||
|
jobID = gen_word(16, 1, 1)
|
||||||
|
insert_tuple = (jobID,email,pdb,smiles,compound_name,description)
|
||||||
|
"""
|
||||||
|
mycursor.execute(sqlQuery,insert_tuple)
|
||||||
|
mycon.commit()
|
||||||
|
if flask_app.config['INSTANT_EXEC']:
|
||||||
|
cwd = os.path.join(os.getcwd(),"app")
|
||||||
|
subprocess.Popen(['python3', 'dock-single.py'],cwd=cwd)
|
||||||
|
"""
|
||||||
|
|
||||||
|
return {"jobID":jobID,"message":"Sucessfuly Submitted","PDB ID":pdb,"SMILES":smiles,"email":email}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.mount("/", WSGIMiddleware(flask_app))
|
app.mount("/", WSGIMiddleware(flask_app))
|
||||||
|
|
Loading…
Reference in New Issue