diff options
author | Alexander Kabui | 2021-12-06 17:15:31 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-12-13 15:48:00 +0300 |
commit | c5e4153a9a7bb3ce07f406773bbbf95dc729b32b (patch) | |
tree | 3824e093ea24df86deececb461d1605475ef22c0 | |
parent | 9cea1a8d757461ea2359f4c72afa96c7180e417f (diff) | |
download | genenetwork2-c5e4153a9a7bb3ce07f406773bbbf95dc729b32b.tar.gz |
handle connection error & other exceptions
-rw-r--r-- | wqflask/wqflask/wgcna/gn3_wgcna.py | 43 |
1 files changed, 26 insertions, 17 deletions
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" + } |