From c5e4153a9a7bb3ce07f406773bbbf95dc729b32b Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Mon, 6 Dec 2021 17:15:31 +0300 Subject: handle connection error & other exceptions --- wqflask/wqflask/wgcna/gn3_wgcna.py | 43 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/wgcna/gn3_wgcna.py b/wqflask/wqflask/wgcna/gn3_wgcna.py index 6692a890..17599711 100644 --- a/wqflask/wqflask/wgcna/gn3_wgcna.py +++ b/wqflask/wqflask/wgcna/gn3_wgcna.py @@ -26,7 +26,6 @@ def process_dataset(trait_list): traits = [] strains = [] - for trait in trait_list: traits.append(trait[0].name) @@ -82,26 +81,36 @@ def run_wgcna(form_data): trait_dataset = fetch_trait_data(form_data) form_data["minModuleSize"] = int(form_data["MinModuleSize"]) + form_data["SoftThresholds"] = [int(threshold.strip()) + for threshold in form_data['SoftThresholds'].rstrip().split(",")] + try: + response = requests.post(wgcna_api, json={ + "sample_names": list(set(trait_dataset["sample_names"])), + "trait_names": trait_dataset["trait_names"], + "trait_sample_data": list(trait_dataset["input"].values()), + **form_data - form_data["SoftThresholds"] = [int(threshold.strip()) - for threshold in form_data['SoftThresholds'].rstrip().split(",")] - - + } + ) - response = requests.post(wgcna_api, json={ - "sample_names": list(set(trait_dataset["sample_names"])), - "trait_names": trait_dataset["trait_names"], - "trait_sample_data": list(trait_dataset["input"].values()), - **form_data + status_code = response.status_code + response = response.json() - } - ).json() + if status_code != 200: + return { + "error": response + } + return { + "error": 'null', + "results": response, + "data": process_wgcna_data(response["data"]), + "image": process_image(response["data"]) + } - return { - "results": response, - "data": process_wgcna_data(response["data"]), - "image": process_image(response["data"]) - } + except requests.exceptions.ConnectionError: + return { + "error": "A connection error to perform computation occurred" + } -- cgit v1.2.3