From 0d0b284a76bee863b97c46e8275cd62e02552a93 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 10 Jan 2024 07:16:55 +0300 Subject: Cross-reference genotype data to the dataset. --- scripts/rqtl2/install_genotypes.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/rqtl2/install_genotypes.py b/scripts/rqtl2/install_genotypes.py index 63e6113..a555d46 100644 --- a/scripts/rqtl2/install_genotypes.py +++ b/scripts/rqtl2/install_genotypes.py @@ -106,6 +106,18 @@ def insert_genotype_data(dbconn: mdb.Connection, "markerid": row["markerid"] } for row in data) +def cross_reference_genotypes(dbconn: mdb.Connection, + datasetid: int, + dataids: tuple[int, ...]) -> int: + """Cross-reference the data to the relevant dataset.""" + with dbconn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "INSERT INTO GenoXRef(GenoFreezeId, GenoId, DataId) " + "VALUES(%(datasetid)s, %(markerid)s, %(dataid)s) " + "ON DUPLICATE KEY UPDATE GenoFreezeId=GenoFreezeId", + tuple({**row, "datasetid": datasetid} for row in dataids)) + return cursor.rowcount + def install_genotypes(dbconn: mdb.Connection, speciesid: int, populationid: int, @@ -141,8 +153,9 @@ def install_genotypes(dbconn: mdb.Connection, insert_individuals(dbconn, speciesid, individuals) cross_reference_individuals( dbconn, speciesid, populationid, individuals) - _num_rows, data_ids = insert_genotype_data( + _num_rows, dataids = insert_genotype_data( dbconn, speciesid, batch, individuals) + cross_reference_genotypes(dbconn, datasetid, dataids) count = count + len(batch) if "gmap" in cdata: -- cgit v1.2.3