From a62805b8ae5f4dcebd8deadb786bcf874ad9611c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 29 Aug 2023 10:16:12 +0300 Subject: Retrieve InbredSet Group's samples/strains Retrieve the samples/strains that relate to a particular InbredSet group. --- gn3/case_attributes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gn3') 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("//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("//names", methods=["GET"]) def inbredset_case_attribute_names(inbredset_id: int) -> Response: """Retrieve ALL case-attributes for a specific InbredSet group.""" -- cgit v1.2.3