aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/computations/rust_correlation.py22
-rw-r--r--tests/unit/computations/test_rust_correlation.py27
2 files changed, 39 insertions, 10 deletions
diff --git a/gn3/computations/rust_correlation.py b/gn3/computations/rust_correlation.py
index a3802ae..e739382 100644
--- a/gn3/computations/rust_correlation.py
+++ b/gn3/computations/rust_correlation.py
@@ -4,10 +4,30 @@ from gn3.settings import CORRELATION_COMMAND
from gn3.settings import TMPDIR
-def run_correlation(file_name: & str, outputdir: str = TMPDIR):
+def run_correlation(file_name: str, outputdir: str = TMPDIR):
command_list = [CORRELATION_COMMAND, file_name, outputdir]
results = subprocess.run(command_list, check=True)
return results
+
+
+def parse_correlation_output(result_file: str):
+
+ corr_results = []
+
+ with open(result_file, "r") as file_reader:
+
+ for line in file_reader:
+
+ (trait_name, corr_coeff, p_val) = line.rstrip().split(",")
+ corr_data = {
+ "trait_name": trait_name,
+ "corr_coeff": corr_coeff,
+ "p_val": p_val
+ }
+
+ corr_results.append(corr_data)
+
+ return corr_results
diff --git a/tests/unit/computations/test_rust_correlation.py b/tests/unit/computations/test_rust_correlation.py
index 1398645..121c330 100644
--- a/tests/unit/computations/test_rust_correlation.py
+++ b/tests/unit/computations/test_rust_correlation.py
@@ -2,23 +2,32 @@ import pytest
from gn3.computations.rust_correlation import CORRELATION_COMMAND
from gn3.computations.rust_correlation import run_correlation
+from gn3.computations.rust_correlation import parse_correlation_output
@pytest.mark.unit_test
+def test_run_correlation():
+ """test calling rusts' correlation """
-def test_equality():
- """initial test for sum """
-
- assert 4 == 4
+ results = run_correlation(
+ file_name="/home/kabui/correlation_rust/tests/data/sample_json_file.json", outputdir="/")
+ assert results == "hello"
@pytest.mark.unit_test
+def test_parse_results():
-def test_run_correlation():
- """test calling rusts' correlation """
-
+ raw_data = [
+ ["63.62", "0.97", "0.00"],
+ ["19", "-0.96", "0.22"],
+ ["77.92", "-0.94", "0.31"],
+ ["84.04", "0.94", "0.11"],
+ ["23", "-0.91", "0.11"]
+ ]
- results = run_correlation("./tests/data/sample_json_file.json")
+ expected_results = [{"trait_name": name, "corr_coeff": corr,
+ "p_val": pval} for (name, corr, pval) in raw_data]
- assert results == "hello"
+ assert parse_correlation_output(
+ "tests/unit/computations/data/correlation/sorted_results.txt") == expected_results