aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-01 06:01:58 +0300
committerFrederick Muriuki Muriithi2021-11-01 06:01:58 +0300
commit1a7b59a4d58c21759c265e5b5f413a533c1a2293 (patch)
treef44dd10663e0a8b89f481acfc007d9b3053b461e /gn3/db
parentbfe73a913836395fbcebea442e3118e73ac9255f (diff)
downloadgenenetwork3-1a7b59a4d58c21759c265e5b5f413a533c1a2293.tar.gz
Add some condition checking functions
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * Add the `check_for_literature_info` and `check_symbol_for_tissue_correlation` functions to check for the presence of specific data.
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/correlations.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/gn3/db/correlations.py b/gn3/db/correlations.py
index d94759a..06b3310 100644
--- a/gn3/db/correlations.py
+++ b/gn3/db/correlations.py
@@ -339,3 +339,43 @@ def fetch_tissue_correlations(# pylint: disable=R0913
return {
trait_name: (tiss_corr, tiss_p_val)
for trait_name, tiss_corr, tiss_p_val in results}
+
+def check_for_literature_info(conn: Any, geneid: int) -> bool:
+ """
+ Checks the database to find out whether the trait with `geneid` has any
+ associated literature.
+
+ This is a migration of the
+ `web.webqtl.correlation.CorrelationPage.checkForLitInfo` function in
+ GeneNetwork1.
+ """
+ query = "SELECT 1 FROM LCorrRamin3 WHERE GeneId1=%s LIMIT 1"
+ with conn.cursor() as cursor:
+ cursor.execute(query, geneid)
+ result = cursor.fetchone()
+ if result:
+ return True
+
+ return False
+
+def check_symbol_for_tissue_correlation(
+ conn: Any, tissue_probeset_freeze_id: int, symbol: str = "") -> bool:
+ """
+ Checks whether a symbol has any associated tissue correlations.
+
+ This is a migration of the
+ `web.webqtl.correlation.CorrelationPage.checkSymbolForTissueCorr` function
+ in GeneNetwork1.
+ """
+ query = (
+ "SELECT 1 FROM TissueProbeSetXRef "
+ "WHERE TissueProbeSetFreezeId=%(probeset_freeze_id)s "
+ "AND Symbol=%(symbol)s LIMIT 1")
+ with conn.cursor() as cursor:
+ cursor.execute(
+ query, probeset_freeze_id=tissue_probeset_freeze_id, symbol=symbol)
+ result = cursor.fetchone()
+ if result:
+ return True
+
+ return False