aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/tools.py
diff options
context:
space:
mode:
authorLei Yan2015-07-10 20:12:00 +0000
committerLei Yan2015-07-10 20:12:00 +0000
commitaa159a17785cc415e81346963aa76f05f5f9d4ad (patch)
treeae0502dac39d8cf20115b58817df4931a03b727c /wqflask/utility/tools.py
parent239c5ff97a88bd9ae3c439ca244daca2696fe68b (diff)
parent840285e3533790760b763aaa43d3099f9b0a5d69 (diff)
downloadgenenetwork2-aa159a17785cc415e81346963aa76f05f5f9d4ad.tar.gz
Merge https://github.com/genenetwork/genenetwork2
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r--wqflask/utility/tools.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
new file mode 100644
index 00000000..760ded7c
--- /dev/null
+++ b/wqflask/utility/tools.py
@@ -0,0 +1,84 @@
+# 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
+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
+ """
+ # ---- Check whether environment exists
+ path = get_valid_path(os.environ.get(id))
+ # ---- Check whether setting exists
+ setting = app.config.get(id)
+ if not path:
+ path = get_valid_path(setting)
+ # ---- Check whether default exists
+ if not path:
+ path = get_valid_path(default)
+ # ---- Guess directory
+ if not path:
+ if not setting:
+ setting = guess
+ path = get_valid_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')
+
+ 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
+
+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
+
+ guess = os.environ.get('HOME')+'/plink'
+ path = get_setting('PLINK_PATH',default,guess,get_valid_path)
+ plink_command = path+'/plink'
+ return path,plink_command
+
+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
+
+ 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