aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-06-22 16:31:18 +0300
committerzsloan2023-06-22 10:18:31 -0500
commit971d29e82391cc269405f59b5aad5f31061b633d (patch)
treebfcb63ab18aebfa1aa13c3f7319ce28e734fceb6 /wqflask/base
parent18e2c59a2eb9b1bf952bec6ddfec0cd1abc7cc89 (diff)
downloadgenenetwork2-971d29e82391cc269405f59b5aad5f31061b633d.tar.gz
Update calls to `database_connection` function
Pass in the database URI at call time.
Diffstat (limited to 'wqflask/base')
-rw-r--r--wqflask/base/data_set/__init__.py4
-rw-r--r--wqflask/base/data_set/dataset.py11
-rw-r--r--wqflask/base/data_set/datasetgroup.py5
-rw-r--r--wqflask/base/data_set/genotypedataset.py3
-rw-r--r--wqflask/base/data_set/mrnaassaydataset.py7
-rw-r--r--wqflask/base/data_set/phenotypedataset.py5
-rw-r--r--wqflask/base/data_set/probably_unused.py3
-rw-r--r--wqflask/base/data_set/utils.py6
-rw-r--r--wqflask/base/trait.py4
9 files changed, 27 insertions, 21 deletions
diff --git a/wqflask/base/data_set/__init__.py b/wqflask/base/data_set/__init__.py
index e49c6a93..69eaab53 100644
--- a/wqflask/base/data_set/__init__.py
+++ b/wqflask/base/data_set/__init__.py
@@ -10,7 +10,7 @@ from redis import Redis
# local imports
from .dataset import DataSet
from base import webqtlConfig
-from utility.tools import USE_REDIS
+from utility.tools import get_setting, USE_REDIS
from .datasettype import DatasetType
from .tempdataset import TempDataSet
from .datasetgroup import DatasetGroup
@@ -54,7 +54,7 @@ def create_dataset(dataset_name, dataset_type=None,
def datasets(group_name, this_group=None, redis_conn=Redis()):
key = "group_dataset_menu:v2:" + group_name
dataset_menu = []
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute('''
(SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name
FROM PublishFreeze,InbredSet
diff --git a/wqflask/base/data_set/dataset.py b/wqflask/base/data_set/dataset.py
index feab2b23..435d74a9 100644
--- a/wqflask/base/data_set/dataset.py
+++ b/wqflask/base/data_set/dataset.py
@@ -7,6 +7,7 @@ from redis import Redis
from base import species
from utility import chunks
+from utility.tools import get_setting
from gn3.monads import MonadicDict, query_sql
from pymonad.maybe import Maybe, Nothing
from .datasetgroup import DatasetGroup
@@ -64,7 +65,7 @@ class DataSet:
"""Get the accession_id of this dataset depending on the
dataset type."""
__query = ""
- with database_connection() as conn:
+ with database_connection(get_setting("SQL_URI")) as conn:
if self.type == "Publish":
__query = (
"SELECT InfoFiles.GN_AccesionId AS accession_id FROM "
@@ -115,7 +116,7 @@ class DataSet:
all is passed.
"""
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
try:
if self.type == "ProbeSet":
cursor.execute(
@@ -148,7 +149,7 @@ class DataSet:
results = {}
traits_name_dict = ()
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT ProbeSetXRef.DataId,ProbeSet.Name "
"FROM ProbeSet, ProbeSetXRef, ProbeSetFreeze "
@@ -179,7 +180,7 @@ class DataSet:
if self.group.parlist != None and self.group.f1list != None:
if (self.group.parlist + self.group.f1list) in self.samplelist:
self.samplelist += self.group.parlist + self.group.f1list
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT Strain.Name, Strain.Id FROM "
"Strain, Species WHERE Strain.Name IN "
@@ -219,7 +220,7 @@ class DataSet:
if (self.group.parlist + self.group.f1list) in self.samplelist:
self.samplelist += self.group.parlist + self.group.f1list
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT Strain.Name, Strain.Id FROM Strain, Species "
f"WHERE Strain.Name IN {create_in_clause(self.samplelist)} "
diff --git a/wqflask/base/data_set/datasetgroup.py b/wqflask/base/data_set/datasetgroup.py
index 72577f38..95dc976f 100644
--- a/wqflask/base/data_set/datasetgroup.py
+++ b/wqflask/base/data_set/datasetgroup.py
@@ -15,6 +15,7 @@ from utility.tools import (
locate,
USE_REDIS,
flat_files,
+ get_setting,
flat_file_exists,
locate_ignore_error)
@@ -29,7 +30,7 @@ class DatasetGroup:
def __init__(self, dataset, name=None):
"""This sets self.group and self.group_id"""
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
if not name:
cursor.execute(dataset.query_for_group,
(dataset.name,))
@@ -64,7 +65,7 @@ class DatasetGroup:
def get_mapping_methods(self):
mapping_id = ()
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT MappingMethodId FROM "
"InbredSet WHERE Name= %s",
diff --git a/wqflask/base/data_set/genotypedataset.py b/wqflask/base/data_set/genotypedataset.py
index 2381a42a..b903cd72 100644
--- a/wqflask/base/data_set/genotypedataset.py
+++ b/wqflask/base/data_set/genotypedataset.py
@@ -2,6 +2,7 @@
from .dataset import DataSet
from utility import webqtlUtil
+from utility.tools import get_setting
from db import webqtlDatabaseFunction
from .utils import geno_mrna_confidentiality
from wqflask.database import database_connection
@@ -46,7 +47,7 @@ GenoFreeze.Name = %s"""
def retrieve_sample_data(self, trait):
results = []
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT Strain.Name, GenoData.value, "
"GenoSE.error, 'N/A', Strain.Name2 "
diff --git a/wqflask/base/data_set/mrnaassaydataset.py b/wqflask/base/data_set/mrnaassaydataset.py
index b76c5a74..4eb998b5 100644
--- a/wqflask/base/data_set/mrnaassaydataset.py
+++ b/wqflask/base/data_set/mrnaassaydataset.py
@@ -6,6 +6,7 @@ import codecs
from .dataset import DataSet
from .utils import geno_mrna_confidentiality
from wqflask.database import database_connection
+from utility.tools import get_setting
class MrnaAssayDataSet(DataSet):
'''
@@ -73,7 +74,7 @@ ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND ProbeSetFreeze.Name = %s"""
# Note: setting trait_list to [] is probably not a great idea.
if not trait_list:
trait_list = []
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
for this_trait in trait_list:
if not this_trait.haveinfo:
@@ -144,7 +145,7 @@ ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND ProbeSetFreeze.Name = %s"""
return trait_list
def retrieve_sample_data(self, trait):
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT Strain.Name, ProbeSetData.value, "
"ProbeSetSE.error, NStrain.count, "
@@ -168,7 +169,7 @@ ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND ProbeSetFreeze.Name = %s"""
return cursor.fetchall()
def retrieve_genes(self, column_name):
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
f"SELECT ProbeSet.Name, ProbeSet.{column_name} "
"FROM ProbeSet,ProbeSetXRef WHERE "
diff --git a/wqflask/base/data_set/phenotypedataset.py b/wqflask/base/data_set/phenotypedataset.py
index bdf28a7a..5a39418a 100644
--- a/wqflask/base/data_set/phenotypedataset.py
+++ b/wqflask/base/data_set/phenotypedataset.py
@@ -2,6 +2,7 @@
from .dataset import DataSet
from base import webqtlConfig
+from utility.tools import get_setting
from wqflask.database import database_connection
class PhenotypeDataSet(DataSet):
@@ -96,7 +97,7 @@ SELECT InbredSet.Name, InbredSet.Id, InbredSet.GeneticType, InbredSet.InbredSetC
this_trait.LRS_location_repr = "N/A"
if this_trait.lrs:
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT Geno.Chr, Geno.Mb FROM "
"Geno, Species WHERE "
@@ -113,7 +114,7 @@ SELECT InbredSet.Name, InbredSet.Id, InbredSet.GeneticType, InbredSet.InbredSetC
LRS_Chr, float(LRS_Mb))
def retrieve_sample_data(self, trait):
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT Strain.Name, PublishData.value, "
"PublishSE.error, NStrain.count, "
diff --git a/wqflask/base/data_set/probably_unused.py b/wqflask/base/data_set/probably_unused.py
index 4e54bcff..abd3ad07 100644
--- a/wqflask/base/data_set/probably_unused.py
+++ b/wqflask/base/data_set/probably_unused.py
@@ -3,6 +3,7 @@
import pickle as pickle
from wqflask.database import database_connection
+from utility.tools import get_setting
def create_datasets_list():
if USE_REDIS:
@@ -19,7 +20,7 @@ def create_datasets_list():
'Geno': 'GenoFreeze'}
for dataset_type in type_dict:
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute("SELECT Name FROM %s",
(type_dict[dataset_type],))
results = cursor.fetchall(query)
diff --git a/wqflask/base/data_set/utils.py b/wqflask/base/data_set/utils.py
index 703fee04..d18180c4 100644
--- a/wqflask/base/data_set/utils.py
+++ b/wqflask/base/data_set/utils.py
@@ -7,12 +7,12 @@ import hashlib
from typing import List
-from utility.tools import SQL_URI
+from utility.tools import get_setting, SQL_URI
from base.webqtlConfig import TMPDIR
from wqflask.database import parse_db_url, database_connection
def geno_mrna_confidentiality(ob):
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
cursor.execute(
"SELECT confidentiality, "
f"AuthorisedUsers FROM {ob.type}Freeze WHERE Name = %s",
@@ -26,7 +26,7 @@ def query_table_timestamp(dataset_type: str):
"""function to query the update timestamp of a given dataset_type"""
# computation data and actions
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
fetch_db_name = parse_db_url(SQL_URI)
cursor.execute(
"SELECT UPDATE_TIME FROM "
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py
index 37085448..103ff0c0 100644
--- a/wqflask/base/trait.py
+++ b/wqflask/base/trait.py
@@ -7,7 +7,7 @@ from base import webqtlConfig
from base.webqtlCaseData import webqtlCaseData
from base.data_set import create_dataset
from utility.authentication_tools import check_resource_availability
-from utility.tools import GN2_BASE_URL
+from utility.tools import get_setting, GN2_BASE_URL
from utility.redis_tools import get_redis_conn, get_resource_id
from flask import g, request, url_for
@@ -394,7 +394,7 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
if not dataset:
raise ValueError("Dataset doesn't exist")
- with database_connection() as conn, conn.cursor() as cursor:
+ with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor:
trait_info = ()
if dataset.type == 'Publish':
cursor.execute(