From bfb581115cb5306cf2b95bb940d22b4c1dfca7d3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 10 Sep 2026 14:13:26 -0500 Subject: PoC: UI for genotype records. Implement a proof-of-concept (PoC) UI for genotype records. --- uploader/genotypes/views.py | 66 ++++-- uploader/templates/genotypes/base.html | 7 +- uploader/templates/genotypes/index.html | 129 ++++++++++++ uploader/templates/genotypes/list-genotypes.html | 227 --------------------- .../genotypes/macro-display-dataset-card.html | 24 +++ 5 files changed, 207 insertions(+), 246 deletions(-) create mode 100644 uploader/templates/genotypes/index.html delete mode 100644 uploader/templates/genotypes/list-genotypes.html create mode 100644 uploader/templates/genotypes/macro-display-dataset-card.html diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index f27671c..c18c330 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -4,11 +4,13 @@ import logging from MySQLdb.cursors import DictCursor from pymonad.either import Left, Right, Either from gn_libs.mysqldb import database_connection +from werkzeug.exceptions import UnsupportedMediaType from flask import (flash, request, jsonify, redirect, Blueprint, + make_response, render_template, current_app as app) @@ -16,17 +18,16 @@ from uploader.flask_extensions import url_for from uploader.ui import make_template_renderer from uploader.oauth2.client import oauth2_post from uploader.authorisation import require_login -from uploader.route_utils import generic_select_population -from uploader.datautils import safe_int, enumerate_sequence -from uploader.species.models import all_species, species_by_id +from uploader.species.models import species_by_id from uploader.monadic_requests import make_either_error_handler from uploader.population.models import population_by_species_and_id -from uploader.request_checks import with_species, with_dataset, with_population +from uploader.request_checks import with_population + from .models import (genotype_markers, + genotype_records, genotype_dataset, save_new_dataset, - genotype_markers_count, genocode_by_population) logger = logging.getLogger(__name__) @@ -40,20 +41,49 @@ render_template = make_template_renderer("genotypes") @require_login @with_population(species_redirect_uri="species.list_species", redirect_uri="species.populations.list_species_populations") -def list_genotypes(species: dict, population: dict, **kwargs):# pylint: disable=[unused-argument] - """List genotype details for species and population.""" +def index(species: dict, population: dict, **kwargs):# pylint: disable=[unused-argument] + """Entry-point to the genotypes management section.""" with database_connection(app.config["SQL_URI"]) as conn: - return render_template("genotypes/list-genotypes.html", - species=species, - population=population, - genocode=genocode_by_population( - conn, population["Id"]), - total_markers=genotype_markers_count( - conn, species["SpeciesId"]), - dataset=genotype_dataset(conn, - species["SpeciesId"], - population["Id"]), - activelink="list-genotypes") + offset = int(request.args.get("start", "0")) + number_of_records = int(request.args.get("count", "10")) + _markers, _total_markers, = genotype_markers( + conn, species["SpeciesId"], population["Id"]) + _genotype_records, _count = genotype_records( + conn, + species["SpeciesId"], + population["Id"], + offset, + number_of_records) + _genotype_records = tuple( + {**_record, "index": _idx} + for _idx, _record + in enumerate(_genotype_records, start=offset+1)) + + ## Order these correctly + _samples = tuple(_genotype_records[0]["data"].keys()) + + if "application/json" in request.headers["Accept"]: + return make_response( + jsonify({ + "genotype_records": _genotype_records, + "total_genotype_records": _count, + "fetched_genotype_records": len(_genotype_records), + "sample_order": _samples + }), 200) + + if "text/html" in request.headers["Accept"]: + return render_template( + "genotypes/index.html", + species=species, + population=population, + genocode=genocode_by_population(conn, population["Id"]), + dataset=genotype_dataset( + conn, species["SpeciesId"], population["Id"]), + genotype_records=_genotype_records, + samples=_samples, + activelink="list-genotypes") + + raise UnsupportedMediaType("This endpoint can only server HTML or JSON") @genotypesbp.route( diff --git a/uploader/templates/genotypes/base.html b/uploader/templates/genotypes/base.html index 8d1b951..c2abc63 100644 --- a/uploader/templates/genotypes/base.html +++ b/uploader/templates/genotypes/base.html @@ -1,10 +1,11 @@ {%extends "populations/base.html"%} {%from "populations/macro-display-population-card.html" import display_sui_population_card%} +{%from "genotypes/macro-display-dataset-card.html" import display_dataset_card%} {%block breadcrumbs%} {{super()}}
| # | +Index | +Locus | +Chr | +cM | +Mb | + {%for sample in samples%} +{{sample}} | + {%endfor%} +
|---|---|---|---|---|---|---|
| + + | +{{record.index}} | +{{record.Name}} | +{{record.Chr}} | +{{record.cM}} | +{{record.Mb}} | + {%for sample in samples%} +{{record.data[sample]}} | + {%endfor%} +
| + There are no records + | +||||||
The numerical values in the table above are mapped from the following allele symbols:
+ +| Allele Type | +Allele Symbol | +Mapped To | +
|---|---|---|
| + {{row.AlleleType}} | +{{row.AlleleSymbol}} | +{{row.DatabaseValue if row.DatabaseValue is not none}} | +
| + There is no genotype encoding defined for this data. + | +||
We need to create a dataset to hold the genotype information for this + species/population, before we can proceed to upload the genotype data.
+Please click the button below to create the dataset.
+ + +- The genotype encoding used for the "{{population.FullName}}" population from - the "{{species.FullName}}" species is as shown in the table below. -
-| Allele Type | -Allele Symbol | -Allele Value | -||||
|---|---|---|---|---|---|---|
| {{row.AlleleType}} | -{{row.AlleleSymbol}} | -{{row.DatabaseValue if row.DatabaseValue is not none else "NULL"}} | -||||
| - - There is no explicit genotype encoding defined for this population. - | -||||||
| Name | -Full Name | -
|---|---|
| {{dataset.Name}} | -- {{dataset.FullName}} | -
- To see more information regarding this dataset (e.g. which markers have - sample allele data, the allele data itself, etc) click on the "Full Name" - link above.
-- The table below lists all of the markers that exist for species - {{species.SpeciesName}} ({{species.FullName}}), regardless of whether - (or not) we have corresponding sample allele data for a particular marker. -
-| # | -Index | -Marker Name | -Chr | -- Location (Mb) | -Source | -Source2 | -
|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - |
- Your genotype data will need to be under a dataset. Unfortunately there is - currently no dataset defined for this population. -
- -- - Click the button below to define the genotype dataset for this population. -
- -- - NOTE: Currently the GN2 (and related) system(s) expect a - single genotype dataset per population. If there is more than one, the - system apparently fails in unpredictable ways. -
-| Name | +{{dataset.Name}} | +
|---|---|
| Full Name | +{{dataset.FullName}} | +
| Short Name | +{{dataset.ShortName}} | +