aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/correlations.py37
-rw-r--r--gn3/db/species.py20
2 files changed, 41 insertions, 16 deletions
diff --git a/gn3/db/correlations.py b/gn3/db/correlations.py
index 87ab082..f43b8a5 100644
--- a/gn3/db/correlations.py
+++ b/gn3/db/correlations.py
@@ -265,14 +265,41 @@ def fetch_tissue_probeset_xref_info(
results or tuple(),
(tuple(), {}, {}, {}, {}, {}, {}))
-def correlations_of_all_tissue_traits() -> Tuple[dict, dict]:
+def fetch_gene_symbol_tissue_value_dict_for_trait(
+ gene_name_list: Tuple[str, ...], probeset_freeze_id: int,
+ conn: Any) -> dict:
"""
+ Fetches a map of the gene symbols to the tissue values.
+
This is a migration of the
- `web.webqtl.correlation.CorrelationPage.calculateCorrOfAllTissueTrait`
+ `web.webqtl.correlation.correlationFunction.getGeneSymbolTissueValueDictForTrait`
function in GeneNetwork1.
"""
- raise Exception("Unimplemented!!!")
- return ({}, {})
+ xref_info = fetch_tissue_probeset_xref_info(
+ gene_name_list, probeset_freeze_id, conn)
+ if xref_info[0]:
+ return fetch_gene_symbol_tissue_value_dict(xref_info[0], xref_info[2], conn)
+ return {}
+
+def correlations_of_all_tissue_traits(
+ trait_symbol: str, probeset_freeze_id: int,
+ method: str, conn: Any) -> Tuple[dict, dict]:
+ """
+ Computes and returns the correlation of all tissue traits.
+
+ This is a migration of the
+ `web.webqtl.correlation.correlationFunction.calculateCorrOfAllTissueTrait`
+ function in GeneNetwork1.
+ """
+ primary_trait_symbol_value_dict = fetch_gene_symbol_tissue_value_dict_for_trait(
+ (trait_symbol,), probeset_freeze_id, conn)
+ primary_trait_value = primary_trait_symbol_value_dict.vlaues()[0]
+ symbol_value_dict = fetch_gene_symbol_tissue_value_dict_for_trait(
+ tuple(), probeset_freeze_id, conn)
+ if method == "1":
+ return batch_computed_tissue_correlation(
+ primaryTraitValue,SymbolValueDict,method='spearman')
+ return batch_computed_tissue_correlation(primaryTraitValue,SymbolValueDict)
def build_temporary_tissue_correlations_table(
trait_symbol: str, probeset_freeze_id: int, method: str,
@@ -283,6 +310,8 @@ def build_temporary_tissue_correlations_table(
This is a migration of the
`web.webqtl.correlation.CorrelationPage.getTempTissueCorrTable` function in
GeneNetwork1."""
+ symbol_corr_dict, symbol_p_value_dict = correlations_of_all_tissue_traits(
+ trait_symbol, probeset_freeze_id, method, conn)
raise Exception("Unimplemented!!!")
return ""
diff --git a/gn3/db/species.py b/gn3/db/species.py
index 1e5015f..702a9a8 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