about summary refs log tree commit diff
path: root/gn3/api/rqtl2.py
diff options
context:
space:
mode:
authorAlexander_Kabui2024-11-26 15:10:43 +0300
committerAlexander_Kabui2024-11-26 15:10:43 +0300
commit56cc3f94e9b66ea3bd677eb1e46584bad5bfaa39 (patch)
treeccb2a60e83756b027688104c4884d2c36b35de76 /gn3/api/rqtl2.py
parenta408abf9539de083c0d58b002c647ab67c2c622d (diff)
downloadgenenetwork3-56cc3f94e9b66ea3bd677eb1e46584bad5bfaa39.tar.gz
feat: Implement reading from file functionality
Implement read from the last position for a file.
Diffstat (limited to 'gn3/api/rqtl2.py')
-rw-r--r--gn3/api/rqtl2.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/gn3/api/rqtl2.py b/gn3/api/rqtl2.py
index cc857da..8ac5ce3 100644
--- a/gn3/api/rqtl2.py
+++ b/gn3/api/rqtl2.py
@@ -15,12 +15,13 @@ def compute():
     """Endpoint for computing QTL analysis using R/QTL2"""
     wkdir = current_app.config.get("TMPDIR")
     output_file = os.path.join(wkdir, "output.txt")
+    # this should be computed locally not via files
     rscript_cmd = (
         f"Rscript ./scripts/rqtl2_wrapper.R "
         f"-i /home/kabui/r_playground/meta_grav.json "
         f"-d /home/kabui/r_playground "
         f"-o /home/kabui/r_playground/rqtl_output.json "
-        f"--nperm 100 --threshold 1 --cores 0"
+        f"--nperm 100  --threshold 1 --cores 0"
     )
     process = subprocess.Popen(
         rscript_cmd, shell=True,
@@ -28,9 +29,11 @@ def compute():
         stderr=subprocess.STDOUT
     )
     # TODO rethink where we write this file
-    with open(output_file, "a+") as file_handler:
-        for line in iter(process.stdout.readline, b""):
+    for line in iter(process.stdout.readline, b""):
+        # dont modify
+        with open(output_file, "a+") as file_handler:
             file_handler.write(line.decode("utf-8"))
+
     process.stdout.close()
     process.wait()
     if process.returncode == 0:
@@ -46,8 +49,9 @@ def stream(indetifier):
     # add seek position to this
     output_file = os.path.join(current_app.config.get("TMPDIR"),
                                f"{indetifier}.txt")
-    # raise error if file does not exist
+    seek_position = int(request.args.get("peak", 0))
     with open(output_file) as file_handler:
         # rethink how we do the read should this be stream / yield/peak ????
+        file_handler.seek(seek_position)
         return jsonify({"data": file_handler.readlines(),
                         "pointer": file_handler.tell()})