aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-12-14 19:22:58 +0300
committerFrederick Muriuki Muriithi2023-12-14 19:22:58 +0300
commit096ab99a2d961e864f340c39252b4c8eecc72191 (patch)
tree1404b11e73edd78d2bb404a12ffc25c392f5adf9 /qc_app
parent8e9abe8eccd1a95d34ab9a6bc7b92d1e660dcae7 (diff)
downloadgn-uploader-096ab99a2d961e864f340c39252b4c8eecc72191.tar.gz
samples: Create external script and fix some bugs.
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/samples.py25
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():