diff options
author | Frederick Muriuki Muriithi | 2023-08-29 10:16:12 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-10-10 11:12:48 +0300 |
commit | a62805b8ae5f4dcebd8deadb786bcf874ad9611c (patch) | |
tree | cfa58343bb5134b78a3ba9b68e1dc1a3d5aa6164 | |
parent | 9773e7642972f958ed7b1f9a9c47a04f9eb7d593 (diff) | |
download | genenetwork3-a62805b8ae5f4dcebd8deadb786bcf874ad9611c.tar.gz |
Retrieve InbredSet Group's samples/strains
Retrieve the samples/strains that relate to a particular InbredSet group.
-rw-r--r-- | gn3/case_attributes.py | 16 |
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.""" |