aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-16 12:48:43 +0300
committerFrederick Muriuki Muriithi2024-01-16 12:53:46 +0300
commit6222ebc5ca0fdeaac9ce7addd07ee4dd900a1afb (patch)
tree7fc9add59eaf6d505a8dcfcc20b5af9c11bb211b /qc_app/db
parentd809997e8ca76d2441b58693078c6c9698e769bb (diff)
downloadgn-uploader-6222ebc5ca0fdeaac9ce7addd07ee4dd900a1afb.tar.gz
UI: Create UI to select from existing genotype datasets.
Diffstat (limited to 'qc_app/db')
-rw-r--r--qc_app/db/__init__.py1
-rw-r--r--qc_app/db/datasets.py16
2 files changed, 17 insertions, 0 deletions
diff --git a/qc_app/db/__init__.py b/qc_app/db/__init__.py
index 0b48461..270f1a0 100644
--- a/qc_app/db/__init__.py
+++ b/qc_app/db/__init__.py
@@ -5,3 +5,4 @@ from .populations import (
population_by_id,
populations_by_species,
population_by_species_and_id)
+from .datasets import geno_dataset_by_species_and_population
diff --git a/qc_app/db/datasets.py b/qc_app/db/datasets.py
new file mode 100644
index 0000000..3a27706
--- /dev/null
+++ b/qc_app/db/datasets.py
@@ -0,0 +1,16 @@
+"""Functions for accessing the database relating to datasets."""
+import MySQLdb as mdb
+from MySQLdb.cursors import DictCursor
+
+def geno_dataset_by_species_and_population(
+ conn: mdb.Connection,
+ speciesid: int,
+ populationid: int) -> tuple[dict, ...]:
+ """Retrieve all genotypes datasets by species and population"""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute(
+ "SELECT gf.* FROM InbredSet AS iset INNER JOIN GenoFreeze AS gf "
+ "ON iset.InbredSetId=gf.InbredSetId "
+ "WHERE iset.SpeciesId=%(sid)s AND iset.InbredSetId=%(pid)s",
+ {"sid": speciesid, "pid": populationid})
+ return tuple(dict(row) for row in cursor.fetchall())