aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/correlation/correlation_gn3_api.py6
-rw-r--r--wqflask/wqflask/correlation/rust_correlation.py19
-rw-r--r--wqflask/wqflask/partial_correlations_views.py6
3 files changed, 20 insertions, 11 deletions
diff --git a/wqflask/wqflask/correlation/correlation_gn3_api.py b/wqflask/wqflask/correlation/correlation_gn3_api.py
index 1af54867..b09f3ae2 100644
--- a/wqflask/wqflask/correlation/correlation_gn3_api.py
+++ b/wqflask/wqflask/correlation/correlation_gn3_api.py
@@ -3,6 +3,8 @@ import json
import time
from functools import wraps
+from flask import current_app
+
from wqflask.correlation import correlation_functions
from wqflask.correlation.pre_computes import fetch_precompute_results
from wqflask.correlation.pre_computes import cache_compute_results
@@ -11,7 +13,7 @@ from base import data_set
from base.trait import create_trait
from base.trait import retrieve_sample_data
-from gn3.db_utils import database_connector
+from gn3.db_utils import database_connection
from gn3.commands import run_sample_corr_cmd
from gn3.computations.correlations import map_shared_keys_to_values
from gn3.computations.correlations import compute_all_lit_correlation
@@ -146,7 +148,7 @@ def lit_for_trait_list(corr_results, this_dataset, this_trait):
geneid_dict = {trait_name: geneid for (trait_name, geneid) in geneid_dict.items() if
trait_lists.get(trait_name)}
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
correlation_results = compute_all_lit_correlation(
conn=conn, trait_lists=list(geneid_dict.items()),
species=species, gene_id=this_trait_geneid)
diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py
index 188278d8..cfec1ae3 100644
--- a/wqflask/wqflask/correlation/rust_correlation.py
+++ b/wqflask/wqflask/correlation/rust_correlation.py
@@ -1,6 +1,9 @@
"""module contains integration code for rust-gn3"""
import json
from functools import reduce
+
+from flask import current_app
+
from utility.db_tools import mescape
from utility.db_tools import create_in_clause
from wqflask.correlation.correlation_functions\
@@ -15,7 +18,7 @@ from gn3.computations.correlations import compute_all_lit_correlation
from gn3.computations.rust_correlation import run_correlation
from gn3.computations.rust_correlation import get_sample_corr_data
from gn3.computations.rust_correlation import parse_tissue_corr_data
-from gn3.db_utils import database_connector
+from gn3.db_utils import database_connection
from wqflask.correlation.exceptions import WrongCorrelationType
@@ -26,7 +29,7 @@ def query_probes_metadata(dataset, trait_list):
if not bool(trait_list) or dataset.type!="ProbeSet":
return []
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
with conn.cursor() as cursor:
query = """
@@ -96,7 +99,7 @@ def chunk_dataset(dataset, steps, name):
ProbeSetXRef.ProbeSetId = ProbeSet.Id
""".format(name)
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
with conn.cursor() as curr:
curr.execute(query)
traits_name_dict = dict(curr.fetchall())
@@ -120,7 +123,7 @@ def compute_top_n_sample(start_vars, dataset, trait_list):
sample_data=json.loads(samples_vals),
dataset_samples=dataset.group.all_samples_ordered())
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
with conn.cursor() as curr:
curr.execute(
"""
@@ -138,7 +141,7 @@ def compute_top_n_sample(start_vars, dataset, trait_list):
if len(trait_list) == 0:
return {}
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
with conn.cursor() as curr:
# fetching strain data in bulk
query = (
@@ -174,7 +177,7 @@ def compute_top_n_lit(corr_results, target_dataset, this_trait) -> dict:
geneid_dict = {trait_name: geneid for (trait_name, geneid)
in geneid_dict.items() if
corr_results.get(trait_name)}
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
return reduce(
lambda acc, corr: {**acc, **corr},
compute_all_lit_correlation(
@@ -249,7 +252,7 @@ def __compute_sample_corr__(
if target_dataset.type == "ProbeSet" and start_vars.get("use_cache") == "true":
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
file_path = fetch_text_file(target_dataset.name, conn)
if file_path:
(sample_vals, target_data) = read_text_file(
@@ -336,7 +339,7 @@ def __compute_lit_corr__(
(this_trait_geneid, geneid_dict, species) = do_lit_correlation(
this_trait, target_dataset)
- with database_connector() as conn:
+ with database_connection(current_app.config["SQL_URI"]) as conn:
return reduce(
lambda acc, lit: {**acc, **lit},
compute_all_lit_correlation(
diff --git a/wqflask/wqflask/partial_correlations_views.py b/wqflask/wqflask/partial_correlations_views.py
index b3ebc4c5..a11d902c 100644
--- a/wqflask/wqflask/partial_correlations_views.py
+++ b/wqflask/wqflask/partial_correlations_views.py
@@ -348,7 +348,7 @@ def process_pcorrs_command_output(result):
@app.route("/partial_correlations/<command_id>", methods=["GET"])
def poll_partial_correlation_results(command_id):
response = requests.get(
- url=urljoin(GN_SERVER_URL, "async_commands/state/{command_id}"))
+ url=urljoin(GN_SERVER_URL, f"async_commands/state/{command_id}"))
if response.status_code == 200:
data = response.json()
@@ -366,3 +366,7 @@ def poll_partial_correlation_results(command_id):
return render_template(
"partial_correlations/pcorrs_poll_results.html",
command_id = command_id)
+ return render_error(
+ "We messed up, and the computation failed due to a system "
+ "error.",
+ command_id)