diff options
author | Pjotr Prins | 2016-04-20 08:28:44 +0000 |
---|---|---|
committer | Pjotr Prins | 2016-04-20 08:28:44 +0000 |
commit | beb6a9360ecc9edca19692e4081efc15292fb7d1 (patch) | |
tree | c736745b7bfac9eec844bbdbc582e44960e3d487 | |
parent | 73ef712f3fd02df7ffa84a2b35ee5648f689d31b (diff) | |
download | genenetwork2-beb6a9360ecc9edca19692e4081efc15292fb7d1.tar.gz |
[PATCH 018/100] Find external tools: refactored code to work with GNU Guix
-rw-r--r-- | etc/default_settings.py | 8 | ||||
-rw-r--r-- | wqflask/utility/tools.py | 92 | ||||
-rw-r--r-- | wqflask/wqflask/marker_regression/marker_regression.py | 8 |
3 files changed, 56 insertions, 52 deletions
diff --git a/etc/default_settings.py b/etc/default_settings.py index 0c7d7bad..929bd687 100644 --- a/etc/default_settings.py +++ b/etc/default_settings.py @@ -1,3 +1,5 @@ +import os + LOGFILE = "/var/log/genenetwork/wqflask.log" # This is needed because Flask turns key errors into a @@ -20,5 +22,7 @@ SERVER_PORT = 5003 SECRET_HMAC_CODE = '\x08\xdf\xfa\x93N\x80\xd9\\H@\\\x9f`\x98d^\xb4a;\xc6OM\x946a\xbc\xfc\x80:*\xebc' # Path overrides for Genenetwork -# PYLMM_PATH = 'UNUSED' - +HOME=os.environ.get('HOME') +PYLMM_PATH = HOME+"/izip/git/opensource/python/pylmm_gn2/" +PLINK_PATH = HOME+"/.guix-profile/bin" +GEMMA_PATH = HOME+"/.guix-profile/bin" diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index b8a41f60..0db195df 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -9,76 +9,70 @@ import os import sys from wqflask import app -def get_setting(id,default,guess,get_valid_path): - """ - Resolve a setting from the environment or the global settings in app.config +def get_setting(id,default,guess,find_path): + """Resolve a setting from the environment or the global settings in + app.config, with get_valid_path is a function checking whether the + path points to an expected directory an returns the full path e.g. + + guess = os.environ.get('HOME')+'/pylmm' + get_setting('PYLMM_PATH',default,guess,get_valid_path) + + first tries the environment variable in +id+, next gets the Flask + app setting for the same +id+, next tries the path passed in with + +default+ and finally does an educated +guess+. + + In all, the environment overrides the others, next is the flask + setting, then the default and finally the guess (which is + $HOME/repo). A valid path is returned. If none is resolved an + exception is thrown. + + Note that we do not use the system path. This is on purpose + because it will mess up controlled (reproducible) deployment. The + proper way is to either use the GNU Guix defaults as listed in + etc/default_settings.py or override them yourself by creating a + different settings.py file (or setting the environment). + """ # ---- Check whether environment exists - path = get_valid_path(os.environ.get(id)) + path = find_path(os.environ.get(id)) # ---- Check whether setting exists setting = app.config.get(id) if not path: - path = get_valid_path(setting) + path = find_path(setting) # ---- Check whether default exists if not path: - path = get_valid_path(default) + path = find_path(default) # ---- Guess directory if not path: + guess = os.environ.get('HOME')+guess if not setting: setting = guess - path = get_valid_path(guess) + path = find_path(guess) if not path: - raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the root of the git repository') - + raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the path') return path -def pylmm_command(default=None): - """ - Return the path to the repository and the python command to call - """ - def get_valid_path(path): +def find_command(command,id1,default,guess): + def find_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'): + sys.stderr.write("Trying "+id1+" in "+path+"\n") + binary = str.split(command)[0] + if path and os.path.isfile(path+'/'+binary): 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 - -def plink_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 PLINK_PATH in "+path+"\n") - if path and os.path.isfile(path+'/plink'): - return path - else: - None + path = get_setting(id1,default,guess,find_path) + binary = path+'/'+command + sys.stderr.write("Found "+binary+"\n") + return path,binary - guess = os.environ.get('HOME')+'/plink_gemma' - path = get_setting('PLINK_PATH',default,guess,get_valid_path) - plink_command = path+'/plink' - return path,plink_command +def pylmm_command(default=None): + return find_command('pylmm_gn2/lmm.py',"PYLMM_PATH",default,'/pylmm2') def gemma_command(default=None): - def get_valid_path(path): - """Test for a valid repository""" - if path: - sys.stderr.write("Trying PLINK_PATH in "+path+"\n") - if path and os.path.isfile(path+'/plink'): - return path - else: - None + return find_command('gemma',"GEMMA_PATH",default,'/gemma') - guess = os.environ.get('HOME')+'/plink' - path = get_setting('PLINK_PATH',default,guess,get_valid_path) - gemma_command = path+'/gemma' - return path, gemma_command
\ No newline at end of file +def plink_command(default=None): + return find_command('plink2',"PLINK_PATH",default,'/plink') diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index af320f65..a657510d 100644 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -42,9 +42,15 @@ from wqflask.marker_regression import gemma_mapping #from wqflask.marker_regression import plink_mapping #from wqflask.marker_regression import rqtl_mapping +# Check for valid binary paths of pylmm, plink, rqtl etc. This code +# runs at startup, so a missing binary will balk before running the +# service + +GEMMA_PATH,GEMMA_COMMAND = gemma_command() PYLMM_PATH,PYLMM_COMMAND = pylmm_command() PLINK_PATH,PLINK_COMMAND = plink_command() -GEMMA_PATH,GEMMA_COMMAND = gemma_command() +# RQTL_PATH,RQTL_COMMAND = rqtl_command() + class MarkerRegression(object): |