diff options
-rw-r--r-- | test/requests/correlation_tests.py | 4 | ||||
-rw-r--r-- | wqflask/wqflask/correlation/rust_correlation.py | 4 | ||||
-rw-r--r-- | wqflask/wqflask/database.py | 36 | ||||
-rw-r--r-- | wqflask/wqflask/marker_regression/gemma_mapping.py | 2 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/view.html | 13 |
5 files changed, 35 insertions, 24 deletions
diff --git a/test/requests/correlation_tests.py b/test/requests/correlation_tests.py index 2d314833..abb5794a 100644 --- a/test/requests/correlation_tests.py +++ b/test/requests/correlation_tests.py @@ -48,7 +48,7 @@ def check_lit_correlations(baseurl): "corr_type": "lit", "corr_return_results": "200" } - top_n_message = "The top 200 correlations ranked by the Lit Correlation" + top_n_message = "The top 200 correlations ranked by the Literature Correlation" result = do_request(f"{baseurl}/corr_compute", data) assert result.status_code == 200 assert (result.text.find("Values of record 1435464_at") >= 0), result.text @@ -60,7 +60,7 @@ def check_correlations(args_obj, parser): corr_type_fns = { "sample": check_sample_correlations, "tissue": check_tissue_correlations, - "tissue": check_lit_correlations + "lit": check_lit_correlations } host = args_obj.host for corr_type, corr_type_fn in corr_type_fns.items(): diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index c7dc665f..5109c72e 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -252,14 +252,14 @@ def __compute_lit_corr__( target_dataset_type = target_dataset.type this_dataset_type = this_dataset.type (this_trait_geneid, geneid_dict, species) = do_lit_correlation( - this_trait, this_dataset) + this_trait, target_dataset) with database_connector() as conn: return reduce( lambda acc, lit: {**acc, **lit}, compute_all_lit_correlation( conn=conn, trait_lists=list(geneid_dict.items()), - species=species, gene_id=this_trait_geneid), + species=species, gene_id=this_trait_geneid)[:n_top], {}) return {} diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index f0ce0a77..2063190c 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -5,19 +5,10 @@ from string import Template from typing import Tuple from urllib.parse import urlparse import importlib +import contextlib import MySQLdb -from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker -from sqlalchemy.ext.declarative import declarative_base - -def read_from_pyfile(pyfile, setting): - orig_sys_path = sys.path[:] - sys.path.insert(0, os.path.dirname(pyfile)) - module = importlib.import_module(os.path.basename(pyfile).strip(".py")) - sys.path = orig_sys_path[:] - return module.__dict__.get(setting) def sql_uri(): """Read the SQL_URI from the environment or settings file.""" @@ -37,8 +28,27 @@ def parse_db_url(sql_uri: str) -> Tuple: parsed_db.hostname, parsed_db.username, parsed_db.password, parsed_db.path[1:], parsed_db.port) + +@contextlib.contextmanager def database_connection(): - """Returns a database connection""" + """Provide a context manager for opening, closing, and rolling + back - if supported - a database connection. Should an error occur, + and if the table supports transactions, the connection will be + rolled back. + + """ host, user, passwd, db_name, port = parse_db_url(sql_uri()) - return MySQLdb.connect( - db=db_name, user=user, passwd=passwd, host=host, port=port) + connection = MySQLdb.connect( + db=db_name, user=user, passwd=passwd, host=host, port=port, + autocommit=False # Required for roll-backs + ) + try: + yield connection + connection.close() + except Exception: + connection.rollback() + raise + else: + connection.commit() + finally: + connection.close() diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py index ec12f9b7..6b525733 100644 --- a/wqflask/wqflask/marker_regression/gemma_mapping.py +++ b/wqflask/wqflask/marker_regression/gemma_mapping.py @@ -220,7 +220,7 @@ def parse_loco_output(this_dataset, gwa_output_filename, loco="True"): marker['chr'] = line.split("\t")[0] marker['Mb'] = float(line.split("\t")[2]) / 1000000 marker['p_value'] = float(line.split("\t")[10]) - marker['additive'] = -(float(line.split("\t")[7])) + marker['additive'] = -(float(line.split("\t")[7])/2) if math.isnan(marker['p_value']) or (marker['p_value'] <= 0): marker['lod_score'] = 0 else: diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index 39df161d..2f385987 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -19,7 +19,7 @@ <h3>This collection has {{ '{}'.format(numify(trait_obs|count, "record", "records")) }}</h3> <div class="tool-button-container"> - <form id="collection_form" action="/delete" method="post" target="_blank"> + <form id="collection_form" action="/delete" method="post"> <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> <input type="hidden" name="collection_name" id="collection_name" value="{{ uc.name }}" /> <input type="hidden" name="tool_used" value="" /> @@ -242,13 +242,14 @@ submit_special = function(url) { $("#collection_form").attr("action", url); - e.stopImmediatePropagation(); - return $("#collection_form").submit(); + $("#collection_form").attr('target', '_blank').submit(); + return false; }; $("#delete").on("click", function() { url = $(this).data("url") - return submit_special(url) + $("#collection_form").attr("action", url); + return $("#collection_form").removeAttr('target').submit(); }); $("#remove").on("click", function() { @@ -257,8 +258,8 @@ return $(this).val(); }).get(); $("#trait_list").val(traits) - - return submit_special(url) + $("#collection_form").attr("action", url); + return $("#collection_form").removeAttr('target').submit(); }); $("#change_collection_name").on("click", function() { |