aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2016-06-26 09:50:29 +0000
committerPjotr Prins2016-06-26 09:50:29 +0000
commitd1192b1f244e8976fb53c260179eb3715029ebf4 (patch)
tree9f2e94682b34c8ffa019d4beda90f8c2b1080319
parenteb68b396be51c98e9e9a9027f8b1bb9b05e692c0 (diff)
downloadgenenetwork2-d1192b1f244e8976fb53c260179eb3715029ebf4.tar.gz
gn_server: introduced one new query to fetch a dataset record and force fetch1 to return a tuple
-rw-r--r--wqflask/base/data_set.py34
-rw-r--r--wqflask/db/call.py12
-rw-r--r--wqflask/db/webqtlDatabaseFunction.py5
-rw-r--r--wqflask/utility/logger.py7
4 files changed, 35 insertions, 23 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index c70738f7..ec3750dd 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -466,14 +466,20 @@ class DataSet(object):
Weve_Renamed_This_As_Group
def retrieve_other_names(self):
- """
- If the data set name parameter is not found in the 'Name' field of the data set table,
- check if it is actually the FullName or ShortName instead.
+ """This method fetches the the dataset names in search_result.
+
+ If the data set name parameter is not found in the 'Name' field of
+ the data set table, check if it is actually the FullName or
+ ShortName instead.
- This is not meant to retrieve the data set info if no name at all is passed.
+ This is not meant to retrieve the data set info if no name at
+ all is passed.
"""
+ def helper(r):
+ return r["id"],r["name"],r["full_name"],r["short_name"],r["data_scale"],r["tissue"]
+
try:
if self.type == "ProbeSet":
query_args = tuple(escape(x) for x in (
@@ -482,14 +488,18 @@ class DataSet(object):
self.name,
self.name))
- self.id, self.name, self.fullname, self.shortname, self.data_scale, self.tissue = fetchone("""
- SELECT ProbeSetFreeze.Id, ProbeSetFreeze.Name, ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, ProbeSetFreeze.DataScale, Tissue.Name
- FROM ProbeSetFreeze, ProbeFreeze, Tissue
- WHERE ProbeSetFreeze.public > %s AND
- ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id AND
- ProbeFreeze.TissueId = Tissue.Id AND
- (ProbeSetFreeze.Name = '%s' OR ProbeSetFreeze.FullName = '%s' OR ProbeSetFreeze.ShortName = '%s')
- """ % (query_args))
+ # self.id, self.name, self.fullname, self.shortname, self.data_scale, self.tissue =
+ result = fetch1("""
+SELECT ProbeSetFreeze.Id, ProbeSetFreeze.Name, ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, ProbeSetFreeze.DataScale, Tissue.Name
+FROM ProbeSetFreeze, ProbeFreeze, Tissue
+WHERE ProbeSetFreeze.public > %s
+AND ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id
+AND ProbeFreeze.TissueId = Tissue.Id
+AND (ProbeSetFreeze.Name = '%s' OR ProbeSetFreeze.FullName = '%s' OR ProbeSetFreeze.ShortName = '%s')
+ """ % (query_args),
+ "/dataset/"+self.name+".json",helper)
+ self.id, self.name, self.fullname, self.shortname, self.data_scale, self.tissue = result
+ logger.debug("retrieve_other_names result:",result)
else:
query_args = tuple(escape(x) for x in (
(self.type + "Freeze"),
diff --git a/wqflask/db/call.py b/wqflask/db/call.py
index 194a7650..6c195afa 100644
--- a/wqflask/db/call.py
+++ b/wqflask/db/call.py
@@ -14,17 +14,19 @@ logger = getLogger(__name__ )
# from inspect import stack
def fetch1(query, path=None, func=None):
- """Fetch one result using either a SQL query or the URI path to
-GN_SERVER (when USE_GN_SERVER is True). Apply func to GN_SERVER result
-when set.
+ """Fetch one result as a Tuple using either a SQL query or the URI
+path to GN_SERVER (when USE_GN_SERVER is True). Apply func to
+GN_SERVER result when set (which should return a Tuple)
"""
if USE_GN_SERVER and path:
result = gn_server(path)
if func != None:
- return [func(result)]
+ res2 = func(result)
else:
- return [result]
+ res2 = result,
+ logger.debug(path,query,res2)
+ return res2
else:
return fetchone(query)
diff --git a/wqflask/db/webqtlDatabaseFunction.py b/wqflask/db/webqtlDatabaseFunction.py
index 7fc096a9..ba998e91 100644
--- a/wqflask/db/webqtlDatabaseFunction.py
+++ b/wqflask/db/webqtlDatabaseFunction.py
@@ -21,6 +21,7 @@
# This module is used by GeneNetwork project (www.genenetwork.org)
from db.call import fetch1
+from utility.tools import USE_GN_SERVER
from utility.logger import getLogger
logger = getLogger(__name__ )
@@ -42,13 +43,13 @@ def retrieve_species(group):
"""Get the species of a group (e.g. returns string "mouse" on "BXD"
"""
- result = fetch1("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % (group),"/cross/"+group+".json",lambda r: r["species"])[0]
+ result = fetch1("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % (group),"/cross/"+group+".json",lambda r: (r["species"],))[0]
logger.debug("retrieve_species result:",result)
return result
def retrieve_species_id(group):
- result = fetch1("select SpeciesId from InbredSet where Name = '%s'" % (group),"/cross/"+group+".json",lambda r: r["species_id"])[0]
+ result = fetch1("select SpeciesId from InbredSet where Name = '%s'" % (group),"/cross/"+group+".json",lambda r: (r["species_id"],))[0]
logger.debug("retrieve_species_id result:",result)
return result
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py
index 86ee1c52..ddc0ea82 100644
--- a/wqflask/utility/logger.py
+++ b/wqflask/utility/logger.py
@@ -48,13 +48,12 @@ class GNLogger:
"""Set the undelying log level"""
self.logger.setLevel(value)
- def debug(self,level=0,*args):
+ def debug(self,*args):
"""Call logging.debug for multiple args. Use level=num to filter on
-LOG_LEVEL_DEBUG.
+LOG_LEVEL_DEBUG (NYI).
"""
- if level <= LOG_LEVEL_DEBUG:
- self.collect(self.logger.debug,*args)
+ self.collect(self.logger.debug,*args)
def info(self,*args):
"""Call logging.info for multiple args"""