From 640e2f1485a055e6b060c5b67863bc986d079f70 Mon Sep 17 00:00:00 2001 From: pjotrp Date: Tue, 12 May 2015 15:57:01 -0500 Subject: Move path search into tools.py --- wqflask/utility/tools.py | 37 ++++++++++++++++++++++ .../wqflask/marker_regression/marker_regression.py | 14 ++------ 2 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 wqflask/utility/tools.py (limited to 'wqflask') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py new file mode 100644 index 00000000..3c972557 --- /dev/null +++ b/wqflask/utility/tools.py @@ -0,0 +1,37 @@ +# Tools/paths finder resolves external paths from settings and/or environment +# variables +# +# Currently supported: +# +# PYLMM_PATH finds the root of the git repository of the pylmm_gn2 tool + +import os + +def get_setting(): + """ + Resolve a setting from the environment or the global settings in app.config + """ + pass + +def pylmm_command(default=None): + def get_valid_path(path): + if path and os.path.isfile(path+'/lmm.py'): + return path + else: + None + + # ---- Check whether environment exists + path = get_valid_path(os.environ['PYLMM_PATH']) + # ---- Check whether setting exists + if not path: + path = get_valid_path(app.config.get('PYLMM_PATH')) + # ---- Check whether default exists + if not path: + path = get_valid_path(default) + home = get_valid_path(os.environ['HOME']+'/pylmm_gn2') + if not path: + path = get_valid_path(home) + if not path: + raise Exception('PYLMM_PATH '+home+' unknown or faulty (add PYLMM_PATH to settings.py)') + pylmm_command = 'python '+path+'/lmm.py' + return path,pylmm_command diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 999a32b8..b210173b 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -36,23 +36,13 @@ from utility import webqtlUtil #from wqflask.marker_regression import plink_mapping from wqflask.marker_regression import gemma_mapping #from wqflask.marker_regression import rqtl_mapping -from wqflask.my_pylmm.data import prep_data -# from wqflask.my_pylmm.pyLMM import lmm -# from wqflask.my_pylmm.pyLMM import input from utility import helper_functions from utility import Plot, Bunch from utility import temp_data - from utility.benchmark import Bench +from utility.tools import pylmm_command -import os -if os.environ.get('PYLMM_PATH') is None: - PYLMM_PATH=app.config.get('PYLMM_PATH') - if PYLMM_PATH is None: - PYLMM_PATH=os.environ['HOME']+'/gene/wqflask/wqflask/my_pylmm/pyLMM' -if not os.path.isfile(PYLMM_PATH+'/lmm.py'): - raise Exception('PYLMM_PATH '+PYLMM_PATH+' unknown or faulty') -PYLMM_COMMAND= 'python '+PYLMM_PATH+'/lmm.py' +PYLMM_PATH,PYLMM_COMMAND = pylmm_command() class MarkerRegression(object): -- cgit v1.2.3 From c64c322c70ea4d30bf9d80b790a125efa277fb27 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 12 May 2015 21:45:14 +0000 Subject: More elaborate handling of finding pylmm --- wqflask/utility/tools.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'wqflask') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 3c972557..3eabd044 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -6,32 +6,46 @@ # PYLMM_PATH finds the root of the git repository of the pylmm_gn2 tool import os +import sys +from wqflask import app -def get_setting(): +def get_setting(id,default,guess,get_valid_path): """ Resolve a setting from the environment or the global settings in app.config """ - pass - -def pylmm_command(default=None): - def get_valid_path(path): - if path and os.path.isfile(path+'/lmm.py'): - return path - else: - None - # ---- Check whether environment exists - path = get_valid_path(os.environ['PYLMM_PATH']) + path = get_valid_path(os.environ.get(id)) # ---- Check whether setting exists + setting = app.config.get(id) if not path: - path = get_valid_path(app.config.get('PYLMM_PATH')) + path = get_valid_path(setting) # ---- Check whether default exists if not path: path = get_valid_path(default) - home = get_valid_path(os.environ['HOME']+'/pylmm_gn2') + # ---- Guess directory if not path: - path = get_valid_path(home) + if not setting: + setting = guess + path = get_valid_path(guess) if not path: - raise Exception('PYLMM_PATH '+home+' unknown or faulty (add PYLMM_PATH to settings.py)') - pylmm_command = 'python '+path+'/lmm.py' + raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?)') + + return path + +def pylmm_command(default=None): + """ + Return the path to the repository and the python command to call + """ + def get_valid_path(path): + """Test for a valid repository""" + if path: + sys.stderr.write("Trying PYLMM_PATH in "+path+"\n") + if path and os.path.isfile(path+'/pylmm_gn2/lmm.py'): + return path + else: + None + + guess = os.environ.get('HOME')+'/pylmm_gn2' + path = get_setting('PYLMM_PATH',default,guess,get_valid_path) + pylmm_command = 'python '+path+'/pylmm_gn2/lmm.py' return path,pylmm_command -- cgit v1.2.3 From 799ea994a74f690cd36cbaf8d0a90ca4178f5fea Mon Sep 17 00:00:00 2001 From: pjotrp Date: Tue, 12 May 2015 16:46:12 -0500 Subject: Remove app line --- wqflask/wqflask/marker_regression/marker_regression.py | 1 - 1 file changed, 1 deletion(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index b210173b..2b0e89b3 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -25,7 +25,6 @@ from redis import Redis Redis = Redis() from flask import Flask, g -from wqflask import app from base.trait import GeneralTrait from base import data_set -- cgit v1.2.3 From db649c16e41e22b33be90d66639936699f2038ce Mon Sep 17 00:00:00 2001 From: pjotrp Date: Tue, 12 May 2015 17:45:55 -0500 Subject: Add info to warning --- wqflask/utility/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wqflask') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 3eabd044..1a5c19d9 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -28,7 +28,7 @@ def get_setting(id,default,guess,get_valid_path): setting = guess path = get_valid_path(guess) if not path: - raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?)') + raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the root of the git repository') return path -- cgit v1.2.3