diff options
author | zsloan | 2021-11-11 11:23:39 -0600 |
---|---|---|
committer | GitHub | 2021-11-11 11:23:39 -0600 |
commit | 8c77af63efae6f06d7c7c3269fc0e41811a8037a (patch) | |
tree | 9ffa4b84fd36f09e772db3e218bc980999324c41 /gn3/db/species.py | |
parent | 607c6e627c23c1bce3b199b145855182ab51b211 (diff) | |
parent | 249b85102063debfeeb1b0565956059b8a3af1cf (diff) | |
download | genenetwork3-8c77af63efae6f06d7c7c3269fc0e41811a8037a.tar.gz |
Merge branch 'main' into feature/add_rqtl_pairscan
Diffstat (limited to 'gn3/db/species.py')
-rw-r--r-- | gn3/db/species.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gn3/db/species.py b/gn3/db/species.py index 0deae4e..702a9a8 100644 --- a/gn3/db/species.py +++ b/gn3/db/species.py @@ -30,3 +30,30 @@ 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: + 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 |