From 096ab99a2d961e864f340c39252b4c8eecc72191 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 14 Dec 2023 19:22:58 +0300 Subject: samples: Create external script and fix some bugs. --- qc_app/samples.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'qc_app/samples.py') diff --git a/qc_app/samples.py b/qc_app/samples.py index dee08e5..88a0fde 100644 --- a/qc_app/samples.py +++ b/qc_app/samples.py @@ -159,6 +159,10 @@ def cross_reference_samples(conn: mdb.Connection, strain_names: Iterator[str]): """Link samples to their population.""" with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "SELECT MAX(OrderId) AS loid FROM StrainXRef WHERE InbredSetId=%s", + (population_id,)) + last_order_id = cursor.fetchone()["loid"] while True: batch = take(strain_names, 5000) if len(batch) == 0: @@ -171,10 +175,13 @@ def cross_reference_samples(conn: mdb.Connection, f"({params_str}) AND sx.StrainId IS NULL", (species_id,) + tuple(batch)) strain_ids = (sid["Id"] for sid in cursor.fetchall()) - cursor.execute( - "SELECT MAX(OrderId) AS loid FROM StrainXRef WHERE InbredSetId=%s", - (population_id,)) - last_order_id = cursor.fetchone()["loid"] + params = tuple({ + "pop_id": population_id, + "strain_id": strain_id, + "order_id": last_order_id + (order_id * 10), + "mapping": "N", + "pedigree": None + } for order_id, strain_id in enumerate(strain_ids, start=1)) cursor.executemany( "INSERT INTO StrainXRef( " " InbredSetId, StrainId, OrderId, Used_for_mapping, PedigreeStatus" @@ -183,14 +190,8 @@ def cross_reference_samples(conn: mdb.Connection, " %(pop_id)s, %(strain_id)s, %(order_id)s, %(mapping)s, " " %(pedigree)s" ")", - tuple({ - "pop_id": population_id, - "strain_id": strain_id, - "order_id": order_id, - "mapping": "N", - "pedigree": None - } for order_id, strain_id in - enumerate(strain_ids, start=(last_order_id+10)))) + params) + last_order_id += (len(params) * 10) @samples.route("/upload/samples", methods=["POST"]) def upload_samples(): -- cgit v1.2.3