From 4f2934d16a6dba52a7676fab48acc41e59b5bf29 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 10 Jan 2024 06:48:23 +0300 Subject: Insert any new individuals/samples into the database. --- scripts/rqtl2/install_genotypes.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'scripts/rqtl2') diff --git a/scripts/rqtl2/install_genotypes.py b/scripts/rqtl2/install_genotypes.py index 88f776b..3016f1f 100644 --- a/scripts/rqtl2/install_genotypes.py +++ b/scripts/rqtl2/install_genotypes.py @@ -35,6 +35,19 @@ def insert_markers(dbconn: mdb.Connection, tuple({"speciesid": speciesid, "marker": marker} for marker in markers)) return cursor.rowcount + +def insert_individuals(dbconn: mdb.Connection, + speciesid: int, + individuals: tuple[str, ...]) -> int: + """Insert individuals/samples into the database.""" + with dbconn.cursor() as cursor: + cursor.executemany( + "INSERT INTO Strain(Name, Name2, SpeciesId) " + "VALUES(%(id)s, %(id)s, %(speciesid)s) " + "ON DUPLICATE KEY UPDATE Name=Name", + tuple({"speciesid": speciesid, "id": individual} + for individual in individuals)) + return cursor.rowcount # TODO: Install geno data: GenoData return cursor.rowcount @@ -69,6 +82,8 @@ def install_genotypes(dbconn: mdb.Connection, dbconn, speciesid, tuple(key for key in batch[0].keys() if key != "id")) + individuals = tuple(row["id"] for row in batch) + insert_individuals(dbconn, speciesid, individuals) count = count + len(batch) if "gmap" in cdata: -- cgit v1.2.3