From 2009ff99ca7d07304bc182c01c76e7a84c5a0246 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Thu, 19 Jan 2023 04:43:01 +0300 Subject: Feature/toggle switch caching (#762) * add optional use cache checkbox * add check for use_cache--- wqflask/wqflask/correlation/rust_correlation.py | 13 ++++++++++++- wqflask/wqflask/static/new/javascript/show_trait.js | 14 ++++++++++++-- .../templates/show_trait_calculate_correlations.html | 8 ++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index 5ae5e89c..188278d8 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -247,22 +247,31 @@ def __compute_sample_corr__( if not bool(sample_data): return {} - if target_dataset.type == "ProbeSet": + + if target_dataset.type == "ProbeSet" and start_vars.get("use_cache") == "true": with database_connector() as conn: file_path = fetch_text_file(target_dataset.name, conn) if file_path: (sample_vals, target_data) = read_text_file( sample_data, file_path) + + return run_correlation(target_data, sample_vals, method, ",", corr_type, n_top) + + write_db_to_textfile(target_dataset.name, conn) file_path = fetch_text_file(target_dataset.name, conn) if file_path: (sample_vals, target_data) = read_text_file( sample_data, file_path) + + return run_correlation(target_data, sample_vals, method, ",", corr_type, n_top) + + target_dataset.get_trait_data(list(sample_data.keys())) def __merge_key_and_values__(rows, current): @@ -277,6 +286,7 @@ def __compute_sample_corr__( if len(target_data) == 0: return {} + return run_correlation( target_data, list(sample_data.values()), method, ",", corr_type, n_top) @@ -352,6 +362,7 @@ def compute_correlation_rust( "tissue": __compute_tissue_corr__, "lit": __compute_lit_corr__ } + results = corr_type_fns[corr_type]( start_vars, corr_type, method, n_top, target_trait_info) diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 1f76dbdf..6d412ab0 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -567,27 +567,37 @@ $('select[name=location_type]').change(on_dataset_change); submit_special = function(url) { $("input[name=sample_vals]").val(JSON.stringify(fetchSampleValues())) $("#trait_data_form").attr("action", url); + $("#trait_data_form").submit(); }; var corrInputList = ['sample_vals', 'corr_type', 'primary_samples', 'trait_id', 'dataset', 'group', 'tool_used', 'form_url', 'corr_sample_method', 'corr_samples_group', 'corr_dataset', 'min_expr', - 'corr_return_results', 'location_type', 'loc_chr', 'min_loc_mb', 'max_loc_mb', 'p_range_lower', 'p_range_upper'] + 'corr_return_results', 'location_type', 'loc_chr', 'min_loc_mb', 'max_loc_mb', 'p_range_lower', 'p_range_upper',"use_cache"] $(".test_corr_compute").on("click", (function(_this) { return function() { $('input[name=tool_used]').val("Correlation"); $('input[name=form_url]').val("/test_corr_compute"); $('input[name=wanted_inputs]').val(corrInputList.join(",")); + + url = "/loading"; return submit_special(url); }; })(this)); $(".corr_compute").on("click", (function(_this) { - return function() { + + return function() { + + $('input[name=tool_used]').val("Correlation"); $('input[name=form_url]').val("/corr_compute"); $('input[name=wanted_inputs]').val(corrInputList.join(",")); + + + $('input[name=use_cache]').val($('#use_cache').is(":checked") ? "true": "false"); + url = "/loading"; return submit_special(url); }; diff --git a/wqflask/wqflask/templates/show_trait_calculate_correlations.html b/wqflask/wqflask/templates/show_trait_calculate_correlations.html index 28f2141c..33100484 100644 --- a/wqflask/wqflask/templates/show_trait_calculate_correlations.html +++ b/wqflask/wqflask/templates/show_trait_calculate_correlations.html @@ -113,6 +113,14 @@ + +