From 3cc448e8ee95173dda7f2d50c0cf2ce743cd1926 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 10 Aug 2022 12:02:54 +0300 Subject: Fix formatting for legibility --- test/requests/correlation_tests.py | 44 ++++++++++++++++++++++ test/requests/test-website.py | 2 + wqflask/wqflask/correlation/correlation_gn3_api.py | 23 +++++------ wqflask/wqflask/correlation/rust_correlation.py | 39 +++++++++---------- 4 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 test/requests/correlation_tests.py diff --git a/test/requests/correlation_tests.py b/test/requests/correlation_tests.py new file mode 100644 index 00000000..b0213ff5 --- /dev/null +++ b/test/requests/correlation_tests.py @@ -0,0 +1,44 @@ +import requests +from lxml.html import parse +from link_checker import check_page + +def do_request(host, data): + return request.get( + f"{host}/corr_compute", + params={ + **data, + "corr_dataset": "HC_M2_0606_P", + "corr_return_results": "100", + "corr_samples_group": "samples_primary",}) + +def check_sample_correlations(baseurl): + data = { + "corr_type": "sample", + "corr_sample_method": "pearson", + "location_type": "gene" + } + result = do_request(host, data) + assert result.status == 200 + assert (result.text.find("Values of record 1435464_at") >= 0), "" + +def check_tissue_correlations(baseurl): + data = { + "corr_type": "tissue" + } + result = do_request(host, data) + assert False, "Not implemented yet." + +def check_lit_correlations(baseurl): + data = { + "corr_type": "lit" + } + result = do_request(host, data) + assert False, "Not implemented yet." + +def check_correlations(args_obj, parser): + print("") + print("Checking the correlations...") + host = args_obj.host + check_sample_correlations(host) + check_tissue_correlations(host) + check_lit_correlations(host) diff --git a/test/requests/test-website.py b/test/requests/test-website.py index 71055fca..8062bff1 100755 --- a/test/requests/test-website.py +++ b/test/requests/test-website.py @@ -9,6 +9,7 @@ from link_checker import check_links from link_checker import check_packaged_js_files from mapping_tests import check_mapping from navigation_tests import check_navigation +from correlation_tests import check_correlations from main_web_functionality import check_main_web_functionality import link_checker import sys @@ -28,6 +29,7 @@ def run_all(args_obj, parser): check_links(args_obj, parser) check_packaged_js_files(args_obj, parser) check_mapping(args_obj, parser) + check_correlations(args_obj, parser) # TODO: Add other functions as they are created. diff --git a/wqflask/wqflask/correlation/correlation_gn3_api.py b/wqflask/wqflask/correlation/correlation_gn3_api.py index e1e2613d..6df4eafe 100644 --- a/wqflask/wqflask/correlation/correlation_gn3_api.py +++ b/wqflask/wqflask/correlation/correlation_gn3_api.py @@ -224,19 +224,16 @@ def compute_correlation(start_vars, method="pearson", compute_all=False): correlation_results = correlation_results[0:corr_return_results] if (compute_all): - correlation_results = compute_corr_for_top_results(start_vars, - correlation_results, - this_trait, - this_dataset, - target_dataset, - corr_type) - - correlation_data = {"correlation_results": correlation_results, - "this_trait": this_trait.name, - "target_dataset": start_vars['corr_dataset'], - "return_results": corr_return_results} - - return correlation_data + correlation_results = compute_corr_for_top_results( + start_vars, correlation_results, this_trait, this_dataset, + target_dataset, corr_type) + + return { + "correlation_results": correlation_results, + "this_trait": this_trait.name, + "target_dataset": start_vars['corr_dataset'], + "return_results": corr_return_results + } def compute_corr_for_top_results(start_vars, diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index 8431f179..8a5021cc 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -33,8 +33,11 @@ def compute_top_n_tissue(this_dataset, this_trait, traits, method): # refactor lots of rpt - trait_symbol_dict = dict({trait_name: symbol for ( - trait_name, symbol) in this_dataset.retrieve_genes("Symbol").items() if traits.get(trait_name)}) + trait_symbol_dict = dict({ + trait_name: symbol + for (trait_name, symbol) + in this_dataset.retrieve_genes("Symbol").items() + if traits.get(trait_name)}) corr_result_tissue_vals_dict = get_trait_symbol_and_tissue_values( symbol_list=list(trait_symbol_dict.values())) @@ -73,8 +76,9 @@ def merge_results(dict_a, dict_b, dict_c): return correlation_results -def compute_correlation_rust(start_vars: dict, corr_type: str, - method: str = "pearson", n_top: int = 500): +def compute_correlation_rust( + start_vars: dict, corr_type: str, method: str = "pearson", + n_top: int = 500): """function to compute correlation""" (this_dataset, this_trait, target_dataset, @@ -96,25 +100,15 @@ def compute_correlation_rust(start_vars: dict, corr_type: str, target_data.append(r) - results = run_correlation(target_data, - list(sample_data.values()), - method, - ",", - corr_type, - n_top) + results = run_correlation( + target_data, list(sample_data.values()), method, ",", corr_type, + n_top) # example compute of compute both correlation - - - top_tissue_results = compute_top_n_tissue(this_dataset,this_trait,results,method) - - top_lit_results = compute_top_n_lit(results,this_dataset,this_trait) - # merging the results - results = merge_results(results,top_tissue_results,top_lit_results) if corr_type == "tissue": @@ -134,8 +128,9 @@ def compute_correlation_rust(start_vars: dict, corr_type: str, results = run_correlation( data[1], data[0], method, ",", "tissue") - return {"correlation_results": results, - "this_trait": this_trait.name, - "target_dataset": start_vars['corr_dataset'], - "return_results": n_top - } + return { + "correlation_results": results, + "this_trait": this_trait.name, + "target_dataset": start_vars['corr_dataset'], + "return_results": n_top + } -- cgit v1.2.3