about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--uploader/phenotypes/views.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index f10ba09..8ae3ae4 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -369,12 +369,53 @@ def process_phenotypes_rqtl2_bundle(
                             job_id=str(_job["jobid"])))
 
 
-def process_phenotypes_individual_files(rconn, species, population, dataset):
+def process_phenotypes_individual_files(rconn, species, population, dataset, error_uri):
     """Process the uploaded individual files."""
-    ## Handle huge file uploads here...
+    form = request.form
+    cdata = {
+        "sep": form["file-separator"],
+        "comment.char": form["file-comment-character"],
+        "na.strings": form["file-na"].split(" "),
+    }
+    with ZipFile(
+            Path(app.config["UPLOAD_FOLDER"],
+                 f"{str(uuid.uuid4()).replace('-', '')}.zip"),
+            mode="w"
+    ) as zfile:
+        for rqtlkey, formkey in (("phenocovar", "phenotype-descriptions"),
+                                 ("pheno", "phenotype-data"),
+                                 ("phenose", "phenotype-se"),
+                                 ("phenonum", "phenotype-n")):
+            if form.get("resumable-upload", False):
+                # Chunked upload of large files was used
+                filedata = json.loads(form[formkey])
+                zfile.write(
+                    Path(app.config["UPLOAD_FOLDER"], filedata["uploaded-file"]),
+                    arcname=filedata["original-name"])
+                cdata[rqtlkey] = cdata.get(rqtlkey, []) + [filedata["original-name"]]
+            else:
+                # TODO: Check this path: fix any bugs.
+                _sentfile = request.files[formkey]
+                if not bool(_sentfile):
+                    flash(f"Expected file ('{formkey}') was not provided.",
+                          "alert-danger")
+                    return error_uri
+
+                filepath = save_file(
+                    _sentfile, Path(app.config["UPLOAD_FOLDER"]))
+                zfile.write(
+                    Path(app.config["UPLOAD_FOLDER"], filepath),
+                    arcname=filepath.name)
+                cdata[rqtlkey] = cdata.get(rqtlkey, []) + [filepath.name]
+
+        zfile.writestr("control_data.json", data=json.dumps(cdata, indent=2))
+
     ## Convert files and settings to R/qtl2 bundle
     ## Use same processing as R/qtl2 bundle (after some refactoring)
-    raise NotImplementedError("Implement this!")
+    print(f"FORM: {request.form}")
+    print(f"FILES: {request.files}")
+    print(f"CDATA: {cdata}")
+    return "Would process individual files…"
 
 
 @phenotypesbp.route(