aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-01 06:01:58 +0300
committerBonfaceKilz2021-11-04 12:45:57 +0300
commit4a6be7e1b6514f3c7db8c672970b27e27ecde305 (patch)
tree18e5f5d935c25524d3b53fba9201639acfe282d6 /gn3
parent5a81b7ae59702d6393e9f74a00d8394131b5192a (diff)
downloadgenenetwork3-4a6be7e1b6514f3c7db8c672970b27e27ecde305.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')
-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