diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rqtl2/install_genotypes.py | 15 |
1 files changed, 15 insertions, 0 deletions
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: |