aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-05-19 10:45:11 -0500
committerFrederick Muriuki Muriithi2025-05-19 10:45:11 -0500
commit672debb68ad649756735adef64071327f38cbb8c (patch)
treebc1dba161550821e4e6f995cbac7432c3cd30623
parent318287f726e167b5f08c14e88bfbba8b81f3b38c (diff)
downloadgn-uploader-672debb68ad649756735adef64071327f38cbb8c.tar.gz
Fetch next available PublishXRef.DataId value for the phenotypes.
-rw-r--r--scripts/load_phenotypes_to_db.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/scripts/load_phenotypes_to_db.py b/scripts/load_phenotypes_to_db.py
index fdf711b..e6623fe 100644
--- a/scripts/load_phenotypes_to_db.py
+++ b/scripts/load_phenotypes_to_db.py
@@ -74,6 +74,14 @@ def save_phenotypes(
if idx != 0))
+def __fetch_next_dataid__(conn: mysqldb.Connection) -> int:
+ """Fetch the next available DataId value from the database."""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute(
+ "SELECT MAX(DataId) AS CurrentMaxDataId FROM PublishXRef")
+ return int(cursor.fetchone()) + 1
+
+
def save_phenotypes_data(conn: mysqldb.Connection, dataidmap, samples, datafiles):
"""Read the `datafiles` and save the data in the database."""
pass
@@ -107,13 +115,12 @@ def load_data(conn, job):
logger.info("Saving basic phenotype data.")
_phenos = save_phenotypes(cursor, _control_data)
- _next_data_id = fetch_next_dataid(...)
dataidmap = {
row["phenotype_id"]: {
"phenotype_id": row["phenotype_id"],
- "data_id": _nextid
+ "data_id": dataid
}
- for _nextid, row in enumerate(_phenos, start=_next_data_id)
+ for dataid, row in enumerate(_phenos, start=__fetch_next_dataid__(conn))
}
# 2. Save any new publications (in multi-file bundle):
# -> return publication IDS