diff options
Diffstat (limited to 'qc_app/samples.py')
-rw-r--r-- | qc_app/samples.py | 25 |
1 files changed, 13 insertions, 12 deletions
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(): |