about summary refs log tree commit diff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rwxr-xr-xwqflask/base/data_set.py3
-rw-r--r--wqflask/utility/tools.py82
-rwxr-xr-xwqflask/wqflask/database.py5
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression.py6
-rwxr-xr-xwqflask/wqflask/show_trait/show_trait.py10
5 files changed, 49 insertions, 57 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index e37a838f..0e5a3ac1 100755
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -405,10 +405,11 @@ class DatasetGroup(object):
             #print("Cache not hit")
 
             from utility.tools import plink_command
-            PLINK_PATH,PLINK_COMMAND = plink_command()
+            PLINK_RUN = plink_command()
 
             geno_file_path = webqtlConfig.GENODIR+self.name+".geno"
             plink_file_path = PLINK_PATH+"/"+self.name+".fam"
+            # @FIXME PJOTR/ZACH: .fam files should go into FLATFILES
 
             if os.path.isfile(plink_file_path):
                 self.samplelist = get_group_samplelists.get_samplelist("plink", plink_file_path)
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 0db195df..c3c9b292 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -9,22 +9,22 @@ import os
 import sys
 from wqflask import app
 
-def get_setting(id,default,guess,find_path):
+def get_setting(command_id,guess=None):
     """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.
+    path points to an expected directory and returns the full path to
+    the binary command
 
       guess = os.environ.get('HOME')+'/pylmm'
-      get_setting('PYLMM_PATH',default,guess,get_valid_path)
+      get_setting('PYLMM_PATH',guess)
 
     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+.
+    app setting for the same +id+ 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.
+    setting, then the guess. A valid path to the binary command 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
@@ -33,46 +33,36 @@ def get_setting(id,default,guess,find_path):
     different settings.py file (or setting the environment).
 
     """
-    # ---- Check whether environment exists
-    path = find_path(os.environ.get(id))
-    # ---- Check whether setting exists
-    setting = app.config.get(id)
-    if not path:
-        path = find_path(setting)
-    # ---- Check whether default exists
-    if not path:
-        path = find_path(default)
-    # ---- Guess directory
-    if not path:
-        guess = os.environ.get('HOME')+guess
-        if not setting:
-            setting = guess
-        path = find_path(guess)
-    if not path:
-        raise Exception(id+' '+setting+' path unknown or faulty (update settings.py?). '+id+' should point to the path')
-    return path
-
-def find_command(command,id1,default,guess):
-    def find_path(path):
-        """Test for a valid repository"""
-        if path:
-            sys.stderr.write("Trying "+id1+" in "+path+"\n")
-        binary = str.split(command)[0]
-        if path and os.path.isfile(path+'/'+binary):
-            return path
+    def valid(command):
+        if command:
+            sys.stderr.write("Found value "+command+"\n")
+            return command
         else:
-            None
+            return None
+    
+    # ---- Check whether environment exists
+    sys.stderr.write("Looking for "+command_id+"\n")
+    command = valid(os.environ.get(command_id))
+    if not command:
+        # ---- Check whether setting exists in app
+        command = valid(app.config.get(command_id))
+        if not command:
+            command = valid(guess)
+            if not command:
+                raise Exception(command_id+' path unknown or faulty (update settings.py?). '+command_id+' should point to the path')
+    return command
 
-    path = get_setting(id1,default,guess,find_path)
-    binary = path+'/'+command
-    sys.stderr.write("Found "+binary+"\n")
-    return path,binary
+def pylmm_command(guess=None):
+    return get_setting("PYLMM_RUN",guess)
 
-def pylmm_command(default=None):
-    return find_command('pylmm_gn2/lmm.py',"PYLMM_PATH",default,'/pylmm2')
+def gemma_command(guess=None):
+    return get_setting("GEMMA_RUN",guess)
 
-def gemma_command(default=None):
-    return find_command('gemma',"GEMMA_PATH",default,'/gemma')
+def plink_command(guess=None):
+    return get_setting("PLINK_RUN",guess)
 
-def plink_command(default=None):
-    return find_command('plink2',"PLINK_PATH",default,'/plink')
+def flat_files(subdir=None):
+    base = get_setting("GENENETWORK_FILES")
+    if subdir:
+        return base+"/"+subdir
+    return base
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py
index 159c5d6c..2f544d44 100755
--- a/wqflask/wqflask/database.py
+++ b/wqflask/wqflask/database.py
@@ -24,8 +24,9 @@ def init_db():
     # you will have to import them first before calling init_db()
     #import yourapplication.models
     import wqflask.model
-    print("Creating all..")
+    print("database.py: Creating all model metadata..")
     Base.metadata.create_all(bind=engine)
-    print("Done creating all...")
+    print("database.py: Done creating all model metadata...")
+    print("Point your browser at http://localhost:5003/")
     
 init_db()
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py
index a657510d..b0f5ed69 100644
--- a/wqflask/wqflask/marker_regression/marker_regression.py
+++ b/wqflask/wqflask/marker_regression/marker_regression.py
@@ -46,9 +46,9 @@ from wqflask.marker_regression import gemma_mapping
 # 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_RUN = gemma_command()
+PYLMM_RUN = pylmm_command()
+PLINK_RUN = plink_command()
 # RQTL_PATH,RQTL_COMMAND   = rqtl_command()
 
 
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index 2d4c952a..458e48da 100755
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -16,7 +16,8 @@ from base import webqtlConfig
 from base import webqtlCaseData
 from wqflask.show_trait.SampleList import SampleList
 from utility import webqtlUtil, Plot, Bunch, helper_functions
-from utility.tools import pylmm_command, plink_command
+# from utility.tools import plink_command
+from utility.tools import flat_files
 from base.trait import GeneralTrait
 from base import data_set
 from dbFunction import webqtlDatabaseFunction
@@ -24,8 +25,7 @@ from basicStatistics import BasicStatisticsFunctions
 
 from pprint import pformat as pf
 
-PYLMM_PATH,PYLMM_COMMAND = pylmm_command()
-PLINK_PATH,PLINK_COMMAND = plink_command()
+MAPPING_FILES = flat_files("mapping")
 
 ###############################################
 #
@@ -162,8 +162,8 @@ class ShowTrait(object):
     def get_mapping_methods(self):
         '''Only display mapping methods when the dataset group's genotype file exists'''
         def check_plink_gemma():
-            if (os.path.isfile(PLINK_PATH+"/"+self.dataset.group.name+".bed") and
-                os.path.isfile(PLINK_PATH+"/"+self.dataset.group.name+".map")):
+            if (os.path.isfile(MAPPYING_FILES+"/"+self.dataset.group.name+".bed") and
+                os.path.isfile(MAPPING_FILES+"/"+self.dataset.group.name+".map")):
                 return True
             else:
                 return False