about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--scripts/load_phenotypes_to_db.py37
-rw-r--r--uploader/phenotypes/views.py13
2 files changed, 29 insertions, 21 deletions
diff --git a/scripts/load_phenotypes_to_db.py b/scripts/load_phenotypes_to_db.py
index 5ce37f3..08ee558 100644
--- a/scripts/load_phenotypes_to_db.py
+++ b/scripts/load_phenotypes_to_db.py
@@ -410,23 +410,26 @@ def load_data(conn: mysqldb.Connection, job: dict) -> int:
         conn, tuple(dataidmap.values()))
     # 5. If standard errors and N exist, save them too
     #    (use IDs returned in `3. b.` above).
-    logger.info("Saving new phenotypes standard errors.")
-    _num_se_rows = save_phenotypes_se(conn=conn,
-                                      dataidmap=dataidmap,
-                                      pheno_name2id=pheno_name2id,
-                                      samples=samples,
-                                      control_data=_control_data,
-                                      filesdir=_outdir)
-    logger.info("Saved %s new phenotype standard error rows.", _num_se_rows)
-
-    logger.info("Saving new phenotypes sample counts.")
-    _num_n_rows = save_phenotypes_n(conn=conn,
-                                    dataidmap=dataidmap,
-                                    pheno_name2id=pheno_name2id,
-                                    samples=samples,
-                                    control_data=_control_data,
-                                    filesdir=_outdir)
-    logger.info("Saved %s new phenotype sample counts rows.", _num_n_rows)
+    if _control_data.get("phenose"):
+        logger.info("Saving new phenotypes standard errors.")
+        _num_se_rows = save_phenotypes_se(conn=conn,
+                                          dataidmap=dataidmap,
+                                          pheno_name2id=pheno_name2id,
+                                          samples=samples,
+                                          control_data=_control_data,
+                                          filesdir=_outdir)
+        logger.info("Saved %s new phenotype standard error rows.", _num_se_rows)
+
+    if _control_data.get("phenonum"):
+        logger.info("Saving new phenotypes sample counts.")
+        _num_n_rows = save_phenotypes_n(conn=conn,
+                                        dataidmap=dataidmap,
+                                        pheno_name2id=pheno_name2id,
+                                        samples=samples,
+                                        control_data=_control_data,
+                                        filesdir=_outdir)
+        logger.info("Saved %s new phenotype sample counts rows.", _num_n_rows)
+
     return (_species, _population, _dataset, _xrefs)
 
 
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 97bcafe..8e47242 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -374,10 +374,15 @@ def process_phenotypes_individual_files(error_uri):
     bundlepath = Path(app.config["UPLOAD_FOLDER"],
                       f"{str(uuid.uuid4()).replace('-', '')}.zip")
     with ZipFile(bundlepath,mode="w") as zfile:
-        for rqtlkey, formkey in (("phenocovar", "phenotype-descriptions"),
-                                 ("pheno", "phenotype-data"),
-                                 ("phenose", "phenotype-se"),
-                                 ("phenonum", "phenotype-n")):
+        for rqtlkey, formkey, _type in (
+                ("phenocovar", "phenotype-descriptions", "mandatory"),
+                ("pheno", "phenotype-data", "mandatory"),
+                ("phenose", "phenotype-se", "optional"),
+                ("phenonum", "phenotype-n", "optional")):
+            if _type == "optional" and not bool(form.get(formkey)):
+                # skip if an optional key does not exist.
+                continue
+
             cdata[f"{rqtlkey}_transposed"] = (
                 (form.get(f"{formkey}-transposed") or "off") == "on")