aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/wgcna.py
diff options
context:
space:
mode:
authorAlexander Kabui2021-10-05 15:09:10 +0300
committerBonfaceKilz2021-10-25 14:16:21 +0300
commitf73262a56745de17bdb582474e27726cb19bd95e (patch)
tree81cce89271c76e87f0f9445c725322a5c2faf2e1 /gn3/computations/wgcna.py
parentaff6704cdcaea388f14b71cc013b1a224afb87fc (diff)
downloadgenenetwork3-f73262a56745de17bdb582474e27726cb19bd95e.tar.gz
add function to process images
Diffstat (limited to 'gn3/computations/wgcna.py')
-rw-r--r--gn3/computations/wgcna.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/gn3/computations/wgcna.py b/gn3/computations/wgcna.py
index 0fb56e8..26040d3 100644
--- a/gn3/computations/wgcna.py
+++ b/gn3/computations/wgcna.py
@@ -4,6 +4,7 @@ import os
import json
import uuid
import subprocess
+import base64
from gn3.settings import TMPDIR
from gn3.commands import run_cmd
@@ -15,6 +16,8 @@ def dump_wgcna_data(request_data: dict):
temp_file_path = os.path.join(TMPDIR, filename)
+ request_data["TMPDIR"] = TMPDIR
+
with open(temp_file_path, "w") as output_file:
json.dump(request_data, output_file)
@@ -31,6 +34,16 @@ def stream_cmd_output(socket, cmd: str):
line = line.decode("utf-8").rstrip()
+def process_image(image_loc: str) ->bytes:
+ """encode the image"""
+
+ try:
+ with open(image_loc, "rb") as image_file:
+ return base64.b64encode(image_file.read())
+ except FileNotFoundError as e:
+ return b""
+
+
def compose_wgcna_cmd(rscript_path: str, temp_file_path: str):
"""function to componse wgcna cmd"""
# (todo):issue relative paths to abs paths
@@ -47,12 +60,18 @@ def call_wgcna_script(rscript_path: str, request_data: dict):
run_cmd_results = run_cmd(cmd)
+ print(run_cmd_results["output"])
+
with open(generated_file, "r") as outputfile:
+ output_file_data = json.load(outputfile)
+ output_file_data["image_1"] = process_image(
+ output_file_data["output"]["imageLoc"])
+
if run_cmd_results["code"] != 0:
return run_cmd_results
return {
- "data": json.load(outputfile),
+ "data": output_file_data,
**run_cmd_results
}
except FileNotFoundError: