about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-04-13 11:53:38 -0500
committerFrederick Muriuki Muriithi2026-04-13 13:55:10 -0500
commit354b27383beb1dacdb58f338b652007f0aa591ed (patch)
treeefc075e741393cc977cbaf3aaee1b60d89f9c2bd
parent857f73f00e789a8701e03c22016af16bec183ed6 (diff)
downloadgn-uploader-354b27383beb1dacdb58f338b652007f0aa591ed.tar.gz
Rework `list_markers`: return list of markers and basic metadata.
-rw-r--r--uploader/genotypes/views.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py
index 3fa2131..42f41a8 100644
--- a/uploader/genotypes/views.py
+++ b/uploader/genotypes/views.py
@@ -6,6 +6,7 @@ from pymonad.either import Left, Right, Either
 from gn_libs.mysqldb import database_connection
 from flask import (flash,
                    request,
+                   jsonify,
                    redirect,
                    Blueprint,
                    render_template,
@@ -19,8 +20,8 @@ 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.monadic_requests import make_either_error_handler
-from uploader.request_checks import with_species, with_population
 from uploader.population.models import population_by_species_and_id
+from uploader.request_checks import with_species, with_dataset, with_population
 
 from .models import (genotype_markers,
                      genotype_dataset,
@@ -56,34 +57,33 @@ def list_genotypes(species: dict, population: dict, **kwargs):# pylint: disable=
 
 
 @genotypesbp.route(
-    "/<int:species_id>/populations/<int:population_id>/genotypes/list-markers",
+    "/<int:species_id>/populations/<int:population_id>/genotypes/<int:dataset_id>/list-markers",
     methods=["GET"])
 @require_login
-@with_population(species_redirect_uri="species.list_species",
-                 redirect_uri="species.populations.list_species_populations")
-def list_markers(
-        species: dict,
-        population: dict,
-        **kwargs
-):# pylint: disable=[unused-argument]
-    """List a species' genetic markers."""
+@with_dataset(species_redirect_uri="species.list_species",
+              population_redirect_uri="species.populations.list_species_populations",
+              redirect_uri="species.populations.genotypes.list_genotypes",
+              dataset_by_id=genotype_dataset)
+def list_markers(species: dict, population: dict, dataset: dict, **_kwargs):
+    """List the markers uploaded for this dataset."""
+    args = request.args
+    offset = int(args.get("start") or 0)
     with database_connection(app.config["SQL_URI"]) as conn:
-        start_from = max(safe_int(request.args.get("start_from") or 0), 0)
-        count = safe_int(request.args.get("count") or 20)
-        return render_template("genotypes/list-markers.html",
-                               species=species,
-                               population=population,
-                               total_markers=genotype_markers_count(
-                                   conn, species["SpeciesId"]),
-                               start_from=start_from,
-                               count=count,
-                               markers=enumerate_sequence(
-                                   genotype_markers(conn,
-                                                    species["SpeciesId"],
-                                                    offset=start_from,
-                                                    limit=count),
-                                   start=start_from+1),
-                               activelink="list-markers")
+        markers, total_records = genotype_markers(
+            conn, species["SpeciesId"], dataset["Id"],
+            offset=offset,
+            limit=int(args.get("length") or 0))
+        return jsonify({
+            **({"draw": int(args.get("draw"))}
+               if bool(args.get("draw") or False)
+               else {}),
+            "recordsTotal": total_records,
+            "recordsFiltered": len(markers),
+            "markers": tuple({**marker, "index": idx}
+                             for idx, marker in
+                             enumerate(markers, start=offset+1))
+        })
+
 
 @genotypesbp.route(
     "/<int:species_id>/populations/<int:population_id>/genotypes/datasets/"