about summary refs log tree commit diff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-27 10:24:28 +0300
committerBonfaceKilz2021-11-04 12:45:57 +0300
commit84aaf880f32f5293e5e4f1c74a3f284e3c95df2f (patch)
treee156686b8313bdac5f86c7e9cb2135336f34c73d /gn3
parent5079e5077adafdbfd0b7e7c0ef12431e9aed443d (diff)
downloadgenenetwork3-84aaf880f32f5293e5e4f1c74a3f284e3c95df2f.tar.gz
Remove if clauses: replace with dict
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi

* Remove the if clauses to simplify the code flow: use a dictionary of queries
  and select the appropriate query from the dictionary instead.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/db/species.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/gn3/db/species.py b/gn3/db/species.py
index 1e5015f..abcbf64 100644
--- a/gn3/db/species.py
+++ b/gn3/db/species.py
@@ -47,17 +47,13 @@ def translate_to_mouse_gene_id(species: str, geneid: int, conn: Any) -> int:
         return geneid
 
     with conn.cursor as cursor:
-        if species == "rat":
-            cursor.execute(
-                "SELECT mouse FROM GeneIDXRef WHERE rat = %s", geneid)
-            rat_geneid = cursor.fetchone()
-            if rat_geneid:
-                return rat_geneid[0]
-
-        cursor.execute(
-            "SELECT mouse FROM GeneIDXRef WHERE human = %s", geneid)
-        human_geneid = cursor.fetchone()
-        if human_geneid:
-            return human_geneid[0]
+        query = {
+            "rat": "SELECT mouse FROM GeneIDXRef WHERE rat = %s"
+            "human": "SELECT mouse FROM GeneIDXRef WHERE human = %s"
+        }
+        cursor.execute(query[species], geneid)
+        translated_gene_id = cursor.fetchone()
+        if translated_gene_id:
+            return translated_gene_id[0]
 
     return 0 # default if all else fails