aboutsummaryrefslogtreecommitdiff
path: root/gn3/api
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-05-06 15:35:57 +0300
committerFrederick Muriuki Muriithi2022-05-06 15:35:57 +0300
commitd04241d0e49a50d9aa775042fffe5a7d8cfaf551 (patch)
tree7577b1dd72eed9e32670d9240a632b27831e1417 /gn3/api
parent081bd53222a40a610257c3d67e9186c09da49106 (diff)
downloadgenenetwork3-d04241d0e49a50d9aa775042fffe5a7d8cfaf551.tar.gz
Hook up pcorrs with target traits computations
Enable the endpoint to actually compute partial correlations with selected target traits rather than against an entire dataset. Fix some issues caused by recent refactor that broke pcorrs against a dataset
Diffstat (limited to 'gn3/api')
-rw-r--r--gn3/api/correlation.py44
1 files changed, 33 insertions, 11 deletions
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py
index 7eb7cd6..aeb7f8c 100644
--- a/gn3/api/correlation.py
+++ b/gn3/api/correlation.py
@@ -16,6 +16,8 @@ from gn3.computations.correlations import map_shared_keys_to_values
from gn3.computations.correlations import compute_tissue_correlation
from gn3.computations.correlations import compute_all_lit_correlation
from gn3.computations.correlations import compute_all_sample_correlation
+from gn3.computations.partial_correlations import (
+ partial_correlations_with_target_traits)
correlation = Blueprint("correlation", __name__)
@@ -111,22 +113,42 @@ def partial_correlation():
return reduce(__field_errors__(request_data), fields, errors)
args = request.get_json()
- request_errors = __errors__(
- args, ("primary_trait", "control_traits", "target_db", "method"))
+ with_target_db = args.get("with_target_db", True)
+ request_errors = None
+ if with_target_db:
+ request_errors = __errors__(
+ args, ("primary_trait", "control_traits", "target_db", "method"))
+ else:
+ request_errors = __errors__(
+ args, ("primary_trait", "control_traits", "target_traits", "method"))
if request_errors:
return build_response({
"status": "error",
"messages": request_errors,
"error_type": "Client Error"})
- return build_response({
- "status": "success",
- "results": queue_cmd(
- conn=redis.Redis(),
- cmd=compose_pcorrs_command(
+
+ if with_target_db:
+ return build_response({
+ "status": "queued",
+ "results": queue_cmd(
+ conn=redis.Redis(),
+ cmd=compose_pcorrs_command(
+ trait_fullname(args["primary_trait"]),
+ tuple(
+ trait_fullname(trait) for trait in args["control_traits"]),
+ args["method"], args["target_db"],
+ int(args.get("criteria", 500))),
+ job_queue=current_app.config.get("REDIS_JOB_QUEUE"),
+ env = {"PYTHONPATH": ":".join(sys.path), "SQL_URI": SQL_URI})})
+ else:
+ with database_connector() as conn:
+ results = partial_correlations_with_target_traits(
+ conn,
trait_fullname(args["primary_trait"]),
tuple(
trait_fullname(trait) for trait in args["control_traits"]),
- args["method"], args["target_db"],
- int(args.get("criteria", 500))),
- job_queue=current_app.config.get("REDIS_JOB_QUEUE"),
- env = {"PYTHONPATH": ":".join(sys.path), "SQL_URI": SQL_URI})})
+ tuple(
+ trait_fullname(trait) for trait in args["target_traits"]),
+ args["method"])
+
+ return build_response({"status": "success", "results": results})