aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-08-03 13:06:40 +0300
committerFrederick Muriuki Muriithi2022-08-03 13:06:40 +0300
commitf6d9b2fba94ae363846df0b5ecd619c192d7d2bf (patch)
tree20e05a313d1c3a7cc0c2e521ee8629616ad02059 /gn3/computations
parent85a6b9e556bd3f0d289ad01e56d6c0267431aa65 (diff)
downloadgenenetwork3-f6d9b2fba94ae363846df0b5ecd619c192d7d2bf.tar.gz
Refactor: Remove unnecessary whitespace and name
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/rust_correlation.py52
1 files changed, 16 insertions, 36 deletions
diff --git a/gn3/computations/rust_correlation.py b/gn3/computations/rust_correlation.py
index 276013a..07e0e56 100644
--- a/gn3/computations/rust_correlation.py
+++ b/gn3/computations/rust_correlation.py
@@ -17,63 +17,43 @@ from gn3.settings import TMPDIR
def generate_input_files(dataset: list[str],
output_dir: str = TMPDIR) -> tuple[str, str]:
"""function generates outputfiles and inputfiles"""
-
tmp_dir = f"{output_dir}/correlation"
-
create_output_directory(tmp_dir)
-
tmp_file = os.path.join(tmp_dir, f"{random_string(10)}.txt")
-
with open(tmp_file, "w", encoding="utf-8") as file_writer:
-
file_writer.write("\n".join(dataset))
+
return (tmp_dir, tmp_file)
-def generate_json_file(tmp_dir, tmp_file,
- method, delimiter, x_vals) -> tuple[str, str]:
+def generate_json_file(
+ tmp_dir, tmp_file, method, delimiter, x_vals) -> tuple[str, str]:
"""generating json input file required by cargo"""
-
tmp_json_file = os.path.join(tmp_dir, f"{random_string(10)}.json")
-
output_file = os.path.join(tmp_dir, f"{random_string(10)}.txt")
- correlation_args = {
- "method": method,
- "file_path": tmp_file,
- "x_vals": x_vals,
- "sample_values": "bxd1",
- "output_file": output_file,
- "file_delimiter": delimiter
- }
-
with open(tmp_json_file, "w", encoding="utf-8") as outputfile:
- json.dump(correlation_args, outputfile)
+ json.dump({
+ "method": method,
+ "file_path": tmp_file,
+ "x_vals": x_vals,
+ "sample_values": "bxd1",
+ "output_file": output_file,
+ "file_delimiter": delimiter
+ }, outputfile)
return (output_file, tmp_json_file)
-def run_correlation(dataset, trait_vals:
- str,
- method: str,
- delimiter: str):
+def run_correlation(dataset, trait_vals: str, method: str, delimiter: str):
"""entry function to call rust correlation"""
-
(tmp_dir, tmp_file) = generate_input_files(dataset)
-
- (output_file, json_file) = generate_json_file(tmp_dir=tmp_dir,
- tmp_file=tmp_file,
- method=method,
- delimiter=delimiter,
- x_vals=trait_vals)
-
+ (output_file, json_file) = generate_json_file(
+ tmp_dir=tmp_dir, tmp_file=tmp_file, method=method, delimiter=delimiter,
+ x_vals=trait_vals)
command_list = [CORRELATION_COMMAND, json_file, TMPDIR]
-
subprocess.run(command_list, check=True)
-
- results = parse_correlation_output(output_file, 500)
-
- return results
+ return parse_correlation_output(output_file, 500)
def parse_correlation_output(result_file: str, top_n: int = 500) -> list[dict]: