From 672debb68ad649756735adef64071327f38cbb8c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 19 May 2025 10:45:11 -0500 Subject: Fetch next available PublishXRef.DataId value for the phenotypes. --- scripts/load_phenotypes_to_db.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'scripts') 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 -- cgit v1.2.3