about summary refs log tree commit diff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-29 10:16:12 +0300
committerFrederick Muriuki Muriithi2023-10-10 11:12:48 +0300
commita62805b8ae5f4dcebd8deadb786bcf874ad9611c (patch)
treecfa58343bb5134b78a3ba9b68e1dc1a3d5aa6164 /gn3
parent9773e7642972f958ed7b1f9a9c47a04f9eb7d593 (diff)
downloadgenenetwork3-a62805b8ae5f4dcebd8deadb786bcf874ad9611c.tar.gz
Retrieve InbredSet Group's samples/strains
Retrieve the samples/strains that relate to a particular InbredSet group.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/case_attributes.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/gn3/case_attributes.py b/gn3/case_attributes.py
index f79612d..89b3c63 100644
--- a/gn3/case_attributes.py
+++ b/gn3/case_attributes.py
@@ -26,6 +26,16 @@ def __inbredset_group__(conn, inbredset_id):
             {"inbredset_id": inbredset_id})
         return dict(cursor.fetchone())
 
+def __inbred_set_strains__(conn, inbredset_id):
+    """Return all samples/strains for given InbredSet group."""
+    with conn.cursor(cursorclass=DictCursor) as cursor:
+        cursor.execute(
+            "SELECT s.* FROM StrainXRef AS sxr INNER JOIN Strain AS s "
+            "ON sxr.StrainId=s.Id WHERE sxr.InbredSetId=%(inbredset_id)s "
+            "ORDER BY s.Name ASC",
+            {"inbredset_id": inbredset_id})
+        return tuple(dict(row) for row in cursor.fetchall())
+
 def __case_attribute_labels_by_inbred_set__(conn, inbredset_id):
     """Return the case-attribute labels/names for the given InbredSet group."""
     with conn.cursor(cursorclass=DictCursor) as cursor:
@@ -40,6 +50,12 @@ def inbredset_group(inbredset_id: int) -> Response:
     with database_connection(current_app.config["SQL_URI"]) as conn:
         return jsonify(__inbredset_group__(conn, inbredset_id))
 
+@caseattr.route("/<int:inbredset_id>/strains", methods=["GET"])
+def inbredset_strains(inbredset_id: int) -> Response:
+    """Retrieve ALL strains/samples relating to a specific InbredSet group."""
+    with database_connection(current_app.config["SQL_URI"]) as conn:
+        return jsonify(__inbred_set_strains__(conn, inbredset_id))
+
 @caseattr.route("/<int:inbredset_id>/names", methods=["GET"])
 def inbredset_case_attribute_names(inbredset_id: int) -> Response:
     """Retrieve ALL case-attributes for a specific InbredSet group."""