aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/wgcna.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/computations/wgcna.py')
-rw-r--r--gn3/computations/wgcna.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/gn3/computations/wgcna.py b/gn3/computations/wgcna.py
index ab12fe7..c985491 100644
--- a/gn3/computations/wgcna.py
+++ b/gn3/computations/wgcna.py
@@ -19,7 +19,7 @@ def dump_wgcna_data(request_data: dict):
request_data["TMPDIR"] = TMPDIR
- with open(temp_file_path, "w") as output_file:
+ with open(temp_file_path, "w", encoding="utf-8") as output_file:
json.dump(request_data, output_file)
return temp_file_path
@@ -31,20 +31,18 @@ def stream_cmd_output(socketio, request_data, cmd: str):
socketio.emit("output", {"data": f"calling you script {cmd}"},
namespace="/", room=request_data["socket_id"])
- results = subprocess.Popen(
- cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
+ with subprocess.Popen(
+ cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) as results:
+ if results.stdout is not None:
+ for line in iter(results.stdout.readline, b""):
+ socketio.emit("output",
+ {"data": line.decode("utf-8").rstrip()},
+ namespace="/", room=request_data["socket_id"])
- if results.stdout is not None:
-
- for line in iter(results.stdout.readline, b""):
- socketio.emit("output",
- {"data": line.decode("utf-8").rstrip()},
- namespace="/", room=request_data["socket_id"])
-
- socketio.emit(
- "output", {"data":
- "parsing the output results"}, namespace="/",
- room=request_data["socket_id"])
+ socketio.emit(
+ "output", {"data":
+ "parsing the output results"}, namespace="/",
+ room=request_data["socket_id"])
def process_image(image_loc: str) -> bytes:
@@ -75,7 +73,7 @@ def call_wgcna_script(rscript_path: str, request_data: dict):
run_cmd_results = run_cmd(cmd)
- with open(generated_file, "r") as outputfile:
+ with open(generated_file, "r", encoding="utf-8") as outputfile:
if run_cmd_results["code"] != 0:
return run_cmd_results