aboutsummaryrefslogtreecommitdiff
path: root/gn3/db/species.py
diff options
context:
space:
mode:
authorBonfaceKilz2021-10-26 08:48:30 +0300
committerGitHub2021-10-26 08:48:30 +0300
commit0cfff99e22155b6b15e23cbeff596f5f8f08709c (patch)
treec831f28534ebf6432972e107dbd6da5daef81088 /gn3/db/species.py
parent5440bfcd6940db08c4479a39ba66dbc802b2c426 (diff)
parentc13afb3af166d2b01e4f9fd9b09bb231f0a63cb1 (diff)
downloadgenenetwork3-0cfff99e22155b6b15e23cbeff596f5f8f08709c.tar.gz
Merge pull request #46 from genenetwork/partial-correlations
Partial correlations
Diffstat (limited to 'gn3/db/species.py')
-rw-r--r--gn3/db/species.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/gn3/db/species.py b/gn3/db/species.py
index 0deae4e..1e5015f 100644
--- a/gn3/db/species.py
+++ b/gn3/db/species.py
@@ -30,3 +30,34 @@ def get_chromosome(name: str, is_species: bool, conn: Any) -> Optional[Tuple]:
with conn.cursor() as cursor:
cursor.execute(_sql)
return cursor.fetchall()
+
+def translate_to_mouse_gene_id(species: str, geneid: int, conn: Any) -> int:
+ """
+ Translate rat or human geneid to mouse geneid
+
+ This is a migration of the
+ `web.webqtl.correlation/CorrelationPage.translateToMouseGeneID` function in
+ GN1
+ """
+ assert species in ("rat", "mouse", "human"), "Invalid species"
+ if geneid is None:
+ return 0
+
+ if species == "mouse":
+ 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]
+
+ return 0 # default if all else fails