diff options
author | Pjotr Prins | 2016-06-19 16:41:01 +0000 |
---|---|---|
committer | Pjotr Prins | 2016-06-19 16:41:01 +0000 |
commit | 2bae8718f4d4ec185586d12ae007f79a8dd89136 (patch) | |
tree | 28d608fdc2c0784393ac28187bc0f4d50998e25c /wqflask | |
parent | aae827674cdbe46c7f1ce5d2246bf485a24dbbb3 (diff) | |
download | genenetwork2-2bae8718f4d4ec185586d12ae007f79a8dd89136.tar.gz |
gn_server: Species info can be fetched from gn_server
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/dbFunction/webqtlDatabaseFunction.py | 38 | ||||
-rw-r--r-- | wqflask/utility/logger.py | 5 |
2 files changed, 30 insertions, 13 deletions
diff --git a/wqflask/dbFunction/webqtlDatabaseFunction.py b/wqflask/dbFunction/webqtlDatabaseFunction.py index 5b968d7e..d7e160d0 100644 --- a/wqflask/dbFunction/webqtlDatabaseFunction.py +++ b/wqflask/dbFunction/webqtlDatabaseFunction.py @@ -25,8 +25,11 @@ from flask import Flask, g import MySQLdb import string +import urllib2 +import json from base import webqtlConfig from utility.tools import USE_GN_SERVER +from utility.benchmark import Bench from utility.logger import getLogger logger = getLogger(__name__ ) @@ -44,24 +47,37 @@ def getCursor(): except: return None -def fetchone(cursor,query): - result = g.db.execute("""select Species.Name from Species, InbredSet where InbredSet.Name = %s and InbredSet.SpeciesId = Species.Id""", (group)).fetchone()[0] - return cursor.execute(query) +def fetchone(callername,query): + """Return tuple containing one row by calling SQL directly + + """ + with Bench("SQL took"): + def helper(query): + res = g.db.execute(query) + return res.fetchone() + return logger.sql(callername, query, helper) + +def gn_server(path): + """Return JSON record by calling GN_SERVER + + """ + with Bench("GN_SERVER took"): + res = urllib2.urlopen("http://localhost:8880/"+path) + rest = res.read() + res2 = json.loads(rest) + logger.info(res2) + return res2 def retrieve_species(group): """Get the species of a group (e.g. returns string "mouse" on "BXD" """ if USE_GN_SERVER: - raise Exception("NYI") + result = gn_server("/cross/"+group) + return result["species"] else: - res = logger.sql(stack()[0][3],"select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % (group), g.db.execute) - result = res.fetchone()[0] - - # result = g.db.execute("""select Species.Name from Species, InbredSet where InbredSet.Name = %s and InbredSet.SpeciesId = Species.Id""", (group)).fetchone()[0] - - logger.info(result,type(result)) - return result + result = fetchone(stack()[0][3],"select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % (group)) + return result[0] ########################################################################### #input: cursor, groupName (string) diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index 0d374f1a..6a8b3e7e 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -78,8 +78,9 @@ class GNLogger: """Log SQL command, optionally invoking a timed fun""" self.info(description,sqlcommand) if fun: - self.info("Invoking function") - return fun(sqlcommand) + result = fun(sqlcommand) + self.info("result:",result) + return result def collect(self,fun,*args): """Collect arguments and use fun to output one by one""" |