about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-09-17 15:05:51 -0500
committerFrederick Muriuki Muriithi2026-09-17 15:05:51 -0500
commit76677ddadda4b7d695ced39f0ad94d3b38e296a1 (patch)
tree24efc880f8a714d399eb1a3f890f6780ed7566fb
parent3564304b55f25ac93fb0e9364cf7411cfdc313a9 (diff)
downloadgn-uploader-76677ddadda4b7d695ced39f0ad94d3b38e296a1.tar.gz
Add outline of conversion of file to R/qtl2 format. HEAD main
-rw-r--r--uploader/genotypes/views.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py
index e475986..454fee7 100644
--- a/uploader/genotypes/views.py
+++ b/uploader/genotypes/views.py
@@ -1,5 +1,6 @@
 """Views for the genotypes."""
 import logging
+from uuid import uuid4
 
 from MySQLdb.cursors import DictCursor
 from pymonad.either import Left, Right, Either
@@ -214,6 +215,12 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable=
             __success__)
 
 
+def genotype_csv_to_r_qtl2(uploadsdir: Path, csvfile, csv_meta: dict) -> Path:
+    """Convert given CSV genotype file into the R/qtl2 format."""
+    bundlepath = Path(uploadsdir, f"{uuid.uuid4()}.zip".replace("-", ""))
+    raise NotImplementedError("This is not implemented yet.")
+
+
 @genotypesbp.route(
     "/<int:species_id>/populations/<int:population_id>/genotypes/datasets/"
     "<int:dataset_id>/add-records",
@@ -234,6 +241,22 @@ def add_genotype_records(species: dict, population: dict, dataset: dict, **kwarg
                                dataset=dataset,
                                activelink="add-genotypes-records")
 
+    # request.method is POST from here
+    # T0D0: Handle direct uploads (i.e. Not via javascript)
+    form = dict(request.form) # Request comes in as multipart/formdata
+
+    bundlepath = genotype_csv_to_r_qtl2(
+        # T0D0: Actually, rather than generating the R/qtl2 bundle here, first
+        #  off, do basic check through the data to collect the alleles and other
+        # necessary information. Also do basic QC.
+        Path(uploads_dir(app)),
+        form["uploaded-file"],
+        csv_meta: {
+            "sep": form.get("file-separator", ","),
+            "comment.char": form.get("file-comment-char", "#"),
+            "na.strings": form.get("file-na", "- NA N/A").split(" ")
+        })
+
     if "application/json" in request.headers.get("Accept"):
         return make_response(
             jsonify({