diff options
author | Frederick Muriuki Muriithi | 2025-05-19 10:45:11 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-05-19 10:45:11 -0500 |
commit | 672debb68ad649756735adef64071327f38cbb8c (patch) | |
tree | bc1dba161550821e4e6f995cbac7432c3cd30623 | |
parent | 318287f726e167b5f08c14e88bfbba8b81f3b38c (diff) | |
download | gn-uploader-672debb68ad649756735adef64071327f38cbb8c.tar.gz |
Fetch next available PublishXRef.DataId value for the phenotypes.
-rw-r--r-- | scripts/load_phenotypes_to_db.py | 13 |
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 |