diff options
| author | Munyoki Kilyungi | 2025-04-22 19:34:21 +0300 |
|---|---|---|
| committer | BonfaceKilz | 2025-04-22 19:47:14 +0300 |
| commit | d08c883251b21b508a11191d7fd2bbeeb92baf44 (patch) | |
| tree | 2b50457020b7ecb0d544cfc0d44b5a8eb70809e9 | |
| parent | 482b6f6ba5d4fe4c2cef314323b88b908db3e1a6 (diff) | |
| download | genenetwork3-d08c883251b21b508a11191d7fd2bbeeb92baf44.tar.gz | |
Auto-pep8 files.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
| -rw-r--r-- | gn3/api/correlation.py | 9 | ||||
| -rw-r--r-- | gn3/commands.py | 17 |
2 files changed, 18 insertions, 8 deletions
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py index 6bc3931..6af96d7 100644 --- a/gn3/api/correlation.py +++ b/gn3/api/correlation.py @@ -90,6 +90,7 @@ def compute_tissue_corr(corr_method="pearson"): return jsonify(results) + @correlation.route("/partial", methods=["POST"]) def partial_correlation(): """API endpoint for partial correlations.""" @@ -113,9 +114,9 @@ def partial_correlation(): args = request.get_json() with_target_db = args.get("with_target_db", True) request_errors = __errors__( - args, ("primary_trait", "control_traits", - ("target_db" if with_target_db else "target_traits"), - "method")) + args, ("primary_trait", "control_traits", + ("target_db" if with_target_db else "target_traits"), + "method")) if request_errors: return build_response({ "status": "error", @@ -129,7 +130,7 @@ def partial_correlation(): tuple( trait_fullname(trait) for trait in args["control_traits"]), args["method"], target_database=args["target_db"], - criteria = int(args.get("criteria", 500))) + criteria=int(args.get("criteria", 500))) else: command = compose_pcorrs_command( trait_fullname(args["primary_trait"]), diff --git a/gn3/commands.py b/gn3/commands.py index 73252a6..ee3e32b 100644 --- a/gn3/commands.py +++ b/gn3/commands.py @@ -47,6 +47,7 @@ def compose_gemma_cmd(gemma_wrapper_cmd: str = "gemma-wrapper", cmd += " ".join([f"{arg}" for arg in gemma_args]) return cmd + def compose_rqtl_cmd(rqtl_wrapper_cmd: str, rqtl_wrapper_kwargs: Dict, rqtl_wrapper_bool_kwargs: list) -> str: @@ -63,12 +64,14 @@ def compose_rqtl_cmd(rqtl_wrapper_cmd: str, return cmd + def compose_pcorrs_command_for_selected_traits( prefix_cmd: Tuple[str, ...], target_traits: Tuple[str, ...]) -> Tuple[ str, ...]: """Build command for partial correlations against selected traits.""" return prefix_cmd + ("against-traits", ",".join(target_traits)) + def compose_pcorrs_command_for_database( prefix_cmd: Tuple[str, ...], target_database: str, criteria: int = 500) -> Tuple[str, ...]: @@ -76,6 +79,7 @@ def compose_pcorrs_command_for_database( return prefix_cmd + ( "against-db", f"{target_database}", f"--criteria={criteria}") + def compose_pcorrs_command( primary_trait: str, control_traits: Tuple[str, ...], method: str, **kwargs): @@ -86,7 +90,8 @@ def compose_pcorrs_command( return "pearsons" if "spearmans" in mthd: return "spearmans" - raise Exception(f"Invalid method '{method}'")# pylint: disable=[broad-exception-raised] + raise Exception( + f"Invalid method '{method}'") # pylint: disable=[broad-exception-raised] prefix_cmd = ( f"{sys.executable}", "-m", "scripts.partial_correlations", @@ -100,7 +105,9 @@ def compose_pcorrs_command( kwargs.get("target_database") is None and kwargs.get("target_traits") is not None): return compose_pcorrs_command_for_selected_traits(prefix_cmd, **kwargs) - raise Exception("Invalid state: I don't know what command to generate!")# pylint: disable=[broad-exception-raised] + raise Exception( + "Invalid state: I don't know what command to generate!") # pylint: disable=[broad-exception-raised] + def queue_cmd(conn: Redis, job_queue: str, @@ -134,6 +141,7 @@ Returns the name of the specific redis hash for the specific task. conn.hset(name=unique_id, key="env", value=json.dumps(env)) return unique_id + def run_sample_corr_cmd(method, this_trait_data, target_dataset_data): "Run the sample correlations in an external process, returning the results." with tempfile.TemporaryDirectory() as tempdir: @@ -156,6 +164,7 @@ def run_sample_corr_cmd(method, this_trait_data, target_dataset_data): return correlation_results + def run_cmd(cmd: str, success_codes: Tuple = (0,), env: Optional[str] = None) -> Dict: """Run CMD and return the CMD's status code and output as a dict""" try: @@ -171,7 +180,7 @@ def run_cmd(cmd: str, success_codes: Tuple = (0,), env: Optional[str] = None) -> out = str(results.stdout, 'utf-8') if results.returncode not in success_codes: # Error! out = str(results.stderr, 'utf-8') - (# We do not always run this within an app context + ( # We do not always run this within an app context current_app.logger.debug if current_app else logging.debug)(out) return {"code": results.returncode, "output": out} @@ -201,7 +210,7 @@ def run_async_cmd( "--log-level", log_level ] logging.debug("Launching the worker: %s", worker_command) - subprocess.Popen( # pylint: disable=[consider-using-with] + subprocess.Popen( # pylint: disable=[consider-using-with] worker_command) return cmd_id |
