aboutsummaryrefslogtreecommitdiff
path: root/uploader/phenotypes
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-26 16:02:12 -0500
committerFrederick Muriuki Muriithi2024-09-26 17:02:58 -0500
commitd3122c73497650d7165afb8fc6c75f2650ef956c (patch)
treea395dcb34dbc54892f213cbeb9659c7c1765b730 /uploader/phenotypes
parente9c343766ac9ca5831b223960941a5fe8d837e30 (diff)
downloadgn-uploader-d3122c73497650d7165afb8fc6c75f2650ef956c.tar.gz
List the phenotype datasets.
Diffstat (limited to 'uploader/phenotypes')
-rw-r--r--uploader/phenotypes/models.py22
-rw-r--r--uploader/phenotypes/views.py22
2 files changed, 44 insertions, 0 deletions
diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py
new file mode 100644
index 0000000..1f72dbd
--- /dev/null
+++ b/uploader/phenotypes/models.py
@@ -0,0 +1,22 @@
+"""Database and utility functions for phenotypes."""
+from typing import Optional
+
+import MySQLdb as mdb
+from MySQLdb.cursors import DictCursor
+
+from uploader.db_utils import debug_query
+
+def datasets_by_population(
+ conn: mdb.Connection,
+ species_id: int,
+ population_id: int
+) -> tuple[dict, ...]:
+ """Retrieve all of a population's phenotype studies."""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute(
+ "SELECT s.SpeciesId, pf.* FROM Species AS s "
+ "INNER JOIN InbredSet AS iset ON s.Id=iset.SpeciesId "
+ "INNER JOIN PublishFreeze AS pf ON iset.Id=pf.InbredSetId "
+ "WHERE s.Id=%s AND iset.Id=%s;",
+ (species_id, population_id))
+ return tuple(dict(row) for row in cursor.fetchall())
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 9185f4c..7ad32ad 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -14,6 +14,8 @@ from uploader.request_checks import with_species, with_population
from uploader.population.models import (populations_by_species,
population_by_species_and_id)
+from .models import datasets_by_population
+
phenotypesbp = Blueprint("phenotypes", __name__)
@phenotypesbp.route("/phenotypes", methods=["GET"])
@@ -61,3 +63,23 @@ def select_population(species: dict, **kwargs):
return redirect(url_for("species.populations.phenotypes.list_datasets",
species_id=species["SpeciesId"],
population_id=population["Id"]))
+
+
+
+@phenotypesbp.route(
+ "<int:species_id>/populations/<int:population_id>/phenotypes/datasets",
+ methods=["GET"])
+@require_login
+@with_population(species_redirect_uri="species.populations.phenotypes.index",
+ redirect_uri="species.populations.phenotypes.select_population")
+def list_datasets(species: int, population: int, **kwargs):
+ """List available phenotype datasets."""
+ with database_connection(app.config["SQL_URI"]) as conn:
+ return render_template("phenotypes/list-datasets.html",
+ species=species,
+ population=population,
+ datasets=datasets_by_population(
+ conn,
+ species["SpeciesId"],
+ population["Id"]),
+ activelink="list-datasets")