From 5589b24fac11d8dee0a82707ac0212c0be36945b Mon Sep 17 00:00:00 2001 From: Lukas Polak Date: Fri, 5 Apr 2024 17:37:20 +0200 Subject: [PATCH 1/5] Update API to use GET instead of POST for docking tasks --- documentation/prankweb.open-api.yaml | 42 ++++++++++--------- executor-docking/run_task.py | 4 +- frontend/client/tasks/server-docking-task.tsx | 25 ++--------- web-server/src/api_v2.py | 16 +++---- 4 files changed, 32 insertions(+), 55 deletions(-) diff --git a/documentation/prankweb.open-api.yaml b/documentation/prankweb.open-api.yaml index 8c666d8..ca8b9ad 100644 --- a/documentation/prankweb.open-api.yaml +++ b/documentation/prankweb.open-api.yaml @@ -2,7 +2,7 @@ openapi: 3.0.2 info: title: Prankweb API - version: 1.0.1 + version: 1.1.0 servers: - url: https://prankweb.cz/api/v2/ @@ -17,17 +17,17 @@ paths: schema: $ref: '#/components/schemas/DatabaseId' - in: path - name: task + name: prediction_task_id required: true schema: - $ref: '#/components/schemas/TaskId' + $ref: '#/components/schemas/PredictionTaskId' responses: '200': description: Success content: application/json: schema: - $ref: '#/components/schemas/Task' + $ref: '#/components/schemas/PredictionTask' /predictions/{database}/{task}/log: get: parameters: @@ -37,10 +37,10 @@ paths: schema: $ref: '#/components/schemas/DatabaseId' - in: path - name: task + name: prediction_task_id required: true schema: - $ref: '#/components/schemas/TaskId' + $ref: '#/components/schemas/PredictionTaskId' responses: '200': description: Success @@ -57,10 +57,15 @@ paths: schema: $ref: '#/components/schemas/DatabaseId' - in: path - name: task + name: prediction_task_id required: true schema: - $ref: '#/components/schemas/TaskId' + $ref: '#/components/schemas/PredictionTaskId' + - in: path + name: docking_task_hash + required: true + schema: + $ref: '#/components/schemas/DockingRequest' responses: '200': description: Success @@ -77,10 +82,10 @@ paths: schema: $ref: '#/components/schemas/DatabaseId' - in: path - name: task + name: prediction_task_id required: true schema: - $ref: '#/components/schemas/TaskId' + $ref: '#/components/schemas/PredictionTaskId' responses: '200': description: Success @@ -89,7 +94,7 @@ paths: schema: $ref: '#/components/schemas/DockingTaskList' /docking/{database}/{task}/public/result.json: - post: + get: parameters: - in: path name: database @@ -97,11 +102,11 @@ paths: schema: $ref: '#/components/schemas/DatabaseId' - in: path - name: task + name: prediction_task_id required: true schema: - $ref: '#/components/schemas/TaskId' - requestBody: + $ref: '#/components/schemas/PredictionTaskId' + queryParameters: description: The request needs to contain the hash of the docking task. required: true content: @@ -120,9 +125,9 @@ components: schemas: DatabaseId: type : string - TaskId: + PredictionTaskId: type : string - Task: + PredictionTask: type: object properties: id: @@ -224,10 +229,7 @@ components: pocket: type: string DockingRequest: - type: object - properties: - hash: - type: string + type: string DockingResponse: type: array items: diff --git a/executor-docking/run_task.py b/executor-docking/run_task.py index 67297c1..cd50cb4 100644 --- a/executor-docking/run_task.py +++ b/executor-docking/run_task.py @@ -142,7 +142,7 @@ def execute_directory_task(docking_directory: str, taskId: int): return #parse the prediction file and do some calculations - in this case just counting the number of residues per pocket - #API is /docking///public/ + #API is /docking////public/ #split docking_directory to get database_name and prediction_name result = [] database_name = docking_directory.split("/")[4] @@ -151,7 +151,7 @@ def execute_directory_task(docking_directory: str, taskId: int): else: prediction_name = docking_directory.split("/")[6] - result_url = "./api/v2/docking/" + database_name + "/" + prediction_name + "/public/results.zip" + result_url = "./api/v2/docking/" + database_name + "/" + prediction_name + "/" + status["tasks"][taskId]["initialData"]["hash"] + "/public/results.zip" result.append({ "url": result_url }) diff --git a/frontend/client/tasks/server-docking-task.tsx b/frontend/client/tasks/server-docking-task.tsx index 3b80184..eecb388 100644 --- a/frontend/client/tasks/server-docking-task.tsx +++ b/frontend/client/tasks/server-docking-task.tsx @@ -115,19 +115,8 @@ export async function dockingHash(pocket: string, smiles: string, exhaustiveness * @returns void */ export async function downloadDockingResult(smiles: string, fileURL: string, pocket: string, exhaustiveness: string) { - const hash = await dockingHash(pocket, smiles, exhaustiveness); - // https://stackoverflow.com/questions/50694881/how-to-download-file-in-react-js - fetch(fileURL, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - "hash": hash - }) - }) + fetch(fileURL) .then((response) => response.blob()) .then((blob) => { // Create blob link to download @@ -181,16 +170,8 @@ export async function pollForDockingTask(predictionInfo: PredictionInfo) { //download the computed data if (individualTask.status === "successful") { const hash = await dockingHash(task.pocket.toString(), individualTask.initialData.smiles, individualTask.initialData.exhaustiveness); - const data = await fetch(`./api/v2/docking/${predictionInfo.database}/${predictionInfo.id}/public/result.json`, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - "hash": hash - }) - }).then(res => res.json()).catch(err => console.log(err)); + const data = await fetch(`./api/v2/docking/${predictionInfo.database}/${predictionInfo.id}/${hash}/public/result.json`) + .then(res => res.json()).catch(err => console.log(err)); tasks[i].responseData = data; } diff --git a/web-server/src/api_v2.py b/web-server/src/api_v2.py index b47103f..67c4ca2 100644 --- a/web-server/src/api_v2.py +++ b/web-server/src/api_v2.py @@ -81,19 +81,13 @@ def route_post_docking_file(database_name: str, prediction_name: str): return dt.post_task(prediction_name.upper(), data) @api_v2.route( - "/docking///public/", - methods=["POST"] + "/docking////public/", + methods=["GET"] ) -def route_get_docking_file_with_param(database_name: str, prediction_name: str, file_name: str): - """Get a docking file from the server. - Request body should be a JSON object with the following fields: - - hash: str (a hash of the ligand with parameters)""" - data = request.get_json(force=True) - param = data.get("hash", None) - if data is None or param is None: - return "", 404 +def route_get_docking_file_with_param(database_name: str, prediction_name: str, task_hash: str, file_name: str): + """Get a docking file from the server.""" dt = DockingTask(database_name=database_name) - return dt.get_file_with_post_param(prediction_name.upper(), file_name, param) + return dt.get_file_with_post_param(prediction_name.upper(), file_name, task_hash) @api_v2.route( "/docking///tasks", From 6c0c70f31eb6135ef32b6b960ccd30387cbd19b3 Mon Sep 17 00:00:00 2001 From: Lukas Polak Date: Wed, 10 Apr 2024 00:26:07 +0200 Subject: [PATCH 2/5] Add option to turn on AlphaFold model for custom structures --- frontend/client/index/index.html | 7 ++++++- frontend/client/index/index.js | 25 +++++++++++++++---------- web-server/src/database_v3.py | 17 ++++++++++++++++- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/frontend/client/index/index.html b/frontend/client/index/index.html index b5045dc..be1158a 100644 --- a/frontend/client/index/index.html +++ b/frontend/client/index/index.html @@ -40,7 +40,7 @@

@@ -80,6 +80,11 @@

+
+ + +
- - - - -
-
- Conservation -
-
-
-
- + -
+
-