about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-07-18 11:16:23 +0300
committerFrederick Muriuki Muriithi2023-07-18 11:16:23 +0300
commit088b6181457ef4e528b7dcbf04b7aca29b274d1f (patch)
tree708c272d1d688553a0270b2c7cab28c075f82425
parent82e44755eab2d129cdf766ba5d82e80d738add90 (diff)
downloadgenenetwork3-088b6181457ef4e528b7dcbf04b7aca29b274d1f.tar.gz
Bug: Fetch group name by dataset_id
Change the code to fetch the group name by the dataset ID, since according to
usage[1] of the `retrieve_group_name` function, the value passed in is the
`dataset_id` and not the `group_id`.

Change the name from `retrieve_group_name` to `retrieve_phenotype_group_name`
to more clearly indicate that this function concerns itself with the groups
that relate to phenotypes.

[1](https://github.com/genenetwork/genenetwork2/blob/1bbb0430732b7fa5102d7dcbda80ebda252f5424/wqflask/wqflask/metadata_edits.py)
-rw-r--r--gn3/db/datasets.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/gn3/db/datasets.py b/gn3/db/datasets.py
index 28fe0fe..9121ec2 100644
--- a/gn3/db/datasets.py
+++ b/gn3/db/datasets.py
@@ -38,22 +38,18 @@ def retrieve_sample_list(group: str):
                 samplelist = headers[3:]
     return samplelist
 
-def retrieve_group_name(
-        group_id: int, connection: Any):
+def retrieve_phenotype_group_name(connection: Any, dataset_id: int):
     """
-    Given the group id (InbredSet.Id in the database), retrieve its name
+    Given the dataset id (PublishFreeze.Id in the database), retrieve the name
+    of the group the dataset belongs to.
     """
     query = (
-        "SELECT Name "
-        "FROM InbredSet "
-        "WHERE "
-        "InbredSet.Id = %(group_id)s")
+        "SELECT iset.Name "
+        "FROM PublishFreeze AS pf INNER JOIN InbredSet AS iset "
+        "ON pf.InbredSetId=iset.Id "
+        "WHERE pf.Id = %(dataset_id)s")
     with connection.cursor() as cursor:
-        cursor.execute(
-            query,
-            {
-                "group_id": group_id
-            })
+        cursor.execute(query, {"dataset_id": dataset_id})
         res = cursor.fetchone()
         if res:
             return res[0]