about summary refs log tree commit diff
path: root/gn3/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-25 09:31:58 +0300
committerFrederick Muriuki Muriithi2021-10-25 12:07:22 +0300
commitdf8185078a52c89cc5a75ff9be413a236da29a6e (patch)
treea1600abfe4ddad81fdca668ed5e83be7406a614f /gn3/db
parent4ee600c07ba3888cc2f6448e8b5e3a5786df5699 (diff)
downloadgenenetwork3-df8185078a52c89cc5a75ff9be413a236da29a6e.tar.gz
Implement `get_filename` for correlations
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi

* Implement `get_filename` for the correlations, to be used to determine
  whether to do fast or normal correlations.

  This is a migration of the
  `web.webqtl.correlation.CorrelationPage.getFileName` function in GN1
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/correlations.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/gn3/db/correlations.py b/gn3/db/correlations.py
new file mode 100644
index 0000000..fa8e7ca
--- /dev/null
+++ b/gn3/db/correlations.py
@@ -0,0 +1,26 @@
+"""
+This module will hold functions that are used in the (partial) correlations
+feature to access the database to retrieve data needed for computations.
+"""
+
+from typing import Any
+def get_filename(target_db_name: str, conn: Any) -> str:
+    """
+    Retrieve the name of the reference database file with which correlations are
+    computed.
+
+    This is a migration of the
+    `web.webqtl.correlation.CorrelationPage.getFileName` function in
+    GeneNetwork1.
+    """
+    with conn.cursor() as cursor:
+        cursor.execute(
+            "SELECT Id, FullName from ProbeSetFreeze WHERE Name-%s",
+            target_db_name)
+        result = cursor.fetchone()
+        if result:
+            return "ProbeSetFreezeId_{tid}_FullName_{fname}.txt".format(
+                tid=result[0],
+                fname=result[1].replace(' ', '_').replace('/', '_'))
+
+    return ""