aboutsummaryrefslogtreecommitdiff
path: root/scripts/rqtl2
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-10 06:48:23 +0300
committerFrederick Muriuki Muriithi2024-01-10 07:19:37 +0300
commit4f2934d16a6dba52a7676fab48acc41e59b5bf29 (patch)
tree5794db09c83eda53957d6a1e80a22b4a3730d965 /scripts/rqtl2
parent26ca17cf2bd08a7b75e4094e2903966cfedefb0f (diff)
downloadgn-uploader-4f2934d16a6dba52a7676fab48acc41e59b5bf29.tar.gz
Insert any new individuals/samples into the database.
Diffstat (limited to 'scripts/rqtl2')
-rw-r--r--scripts/rqtl2/install_genotypes.py15
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: