aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/computations/wgcna.py15
-rw-r--r--tests/unit/computations/test_wgcna.py14
2 files changed, 17 insertions, 12 deletions
diff --git a/gn3/computations/wgcna.py b/gn3/computations/wgcna.py
index f7463c5..90db455 100644
--- a/gn3/computations/wgcna.py
+++ b/gn3/computations/wgcna.py
@@ -66,26 +66,25 @@ def call_wgcna_script(rscript_path: str, request_data: dict):
generated_file = dump_wgcna_data(request_data)
cmd = compose_wgcna_cmd(rscript_path, generated_file)
- stream_cmd_output(request_data, cmd)
+ # stream_cmd_output(request_data, cmd) disable streaming of data
try:
- # run_cmd_results = run_cmd(cmd)
+ run_cmd_results = run_cmd(cmd)
with open(generated_file, "r") as outputfile:
+ if run_cmd_results["code"] != 0:
+ return run_cmd_results
+
output_file_data = json.load(outputfile)
- # json format only supports unicode string// to get image data reconvert
output_file_data["output"]["image_data"] = process_image(
output_file_data["output"]["imageLoc"]).decode("ascii")
- output_file_data["output"]["image_data2"] = process_image(
- output_file_data["output"]["heatMap"]).decode("ascii")
+ # json format only supports unicode string// to get image data reconvert
- # if run_cmd_results["code"] != 0:
- # return run_cmd_results
return {
"data": output_file_data,
- "output": ""
+ **run_cmd_results
}
except FileNotFoundError:
# relook at handling errors gn3
diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py
index ec81d94..5f23a86 100644
--- a/tests/unit/computations/test_wgcna.py
+++ b/tests/unit/computations/test_wgcna.py
@@ -10,13 +10,16 @@ from gn3.computations.wgcna import call_wgcna_script
class TestWgcna(TestCase):
"""test class for wgcna"""
+ @mock.patch("gn3.computations.wgcna.process_image")
@mock.patch("gn3.computations.wgcna.run_cmd")
@mock.patch("gn3.computations.wgcna.compose_wgcna_cmd")
@mock.patch("gn3.computations.wgcna.dump_wgcna_data")
def test_call_wgcna_script(self,
mock_dumping_data,
mock_compose_wgcna,
- mock_run_cmd):
+ mock_run_cmd,
+ mock_img,
+ ):
"""test for calling wgcna script"""
# pylint: disable = line-too-long
@@ -50,7 +53,7 @@ class TestWgcna(TestCase):
"output": "Flagging genes and samples with too many missing values...\n ..step 1\nAllowing parallel execution with up to 3 working processes.\npickSoftThreshold: will use block size 7.\n pickSoftThreshold: calculating connectivity for given powers...\n ..working on genes 1 through 7 of 7\n Flagging genes and samples with too many missing values...\n ..step 1\n ..Working on block 1 .\n TOM calculation: adjacency..\n ..will not use multithreading.\nclustering..\n ....detecting modules..\n ....calculating module eigengenes..\n ....checking kME in modules..\n ..merging modules that are too close..\n mergeCloseModules: Merging modules whose distance is less than 0.15\n mergeCloseModules: less than two proper modules.\n ..color levels are turquoise\n ..there is nothing to merge.\n Calculating new MEs...\n"
}
- json_output = "{\"inputdata\":{\"trait_sample_data \":{},\"minModuleSize\":30,\"TOMtype\":\"unsigned\"},\"outputdata\":{\"eigengenes\":[],\"colors\":[]}}"
+ json_output = "{\"inputdata\":{\"trait_sample_data \":{},\"minModuleSize\":30,\"TOMtype\":\"unsigned\"},\"output\":{\"eigengenes\":[],\"imageLoc\":[],\"colors\":[]}}"
expected_output = {
@@ -61,9 +64,11 @@ class TestWgcna(TestCase):
"TOMtype": "unsigned"
},
- "outputdata": {
+ "output": {
"eigengenes": [],
- "colors": []
+ "imageLoc": [],
+ "colors": [],
+ "image_data": "AFDSFNBSDGJJHH"
}
},
@@ -74,6 +79,7 @@ class TestWgcna(TestCase):
with mock.patch("builtins.open", mock.mock_open(read_data=json_output)):
mock_run_cmd.return_value = mock_run_cmd_results
+ mock_img.return_value = b"AFDSFNBSDGJJHH"
results = call_wgcna_script(
"Rscript/GUIX_PATH/scripts/r_file.R", request_data)