From 837ce8b9c779b1da6e4390220ccd353b289c1fca Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 20 Dec 2017 09:11:31 -0600 Subject: Bring in some earlier work - mostly documentation and startup handling --- wqflask/utility/logger.py | 2 +- wqflask/utility/tools.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index bacb0aa4..128706df 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -72,7 +72,7 @@ LOG_LEVEL_DEBUG (NYI). def warning(self,*args): """Call logging.warning for multiple args""" self.collect(self.logger.warning,*args) - self.logger.warning(self.collect(*args)) + # self.logger.warning(self.collect(*args)) def error(self,*args): """Call logging.error for multiple args""" diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index c5685cdd..63b7149c 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -147,9 +147,14 @@ def assert_writable_dir(dir): fh.close() os.remove(fn) except IOError: - raise Exception('Unable to write test.txt to directory ' + dir ) + raise Exception('Unable to write test.txt to directory ' + dir) return dir +def assert_file(fn): + if not valid_file(fn): + raise Exception('Unable to find file '+fn) + return fn + def mk_dir(dir): if not valid_path(dir): os.makedirs(dir) @@ -174,6 +179,9 @@ def locate(name, subdir=None): if subdir: sys.stderr.write(subdir) raise Exception("Can not locate "+name+" in "+base) +def locate_phewas(name, subdir=None): + return locate(name,'/phewas/'+subdir) + def locate_ignore_error(name, subdir=None): """ Locate a static flat file in the GENENETWORK_FILES environment. @@ -243,11 +251,11 @@ JS_GUIX_PATH = get_setting('JS_GUIX_PATH') JS_GN_PATH = get_setting('JS_GN_PATH') # assert_dir(JS_GN_PATH) -PYLMM_COMMAND = pylmm_command() -GEMMA_COMMAND = gemma_command() -GEMMA_WRAPPER_COMMAND = gemma_wrapper_command() -PLINK_COMMAND = plink_command() -TEMPDIR = tempdir() # defaults to UNIX TMPDIR +PYLMM_COMMAND = app_set("PYLMM_COMMAND",pylmm_command()) +GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command()) +PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command()) +TEMPDIR = tempdir() # defaults to UNIX TMPDIR +assert_dir(TEMPDIR) # ---- Handle specific JS modules JS_TWITTER_POST_FETCHER_PATH = get_setting("JS_TWITTER_POST_FETCHER_PATH",js_path("Twitter-Post-Fetcher")) @@ -267,3 +275,10 @@ if os.environ.get('WQFLASK_OVERRIDES'): else: OVERRIDES[k] = cmd logger.debug(OVERRIDES) + +assert_file(PHEWAS_FILES+"/auwerx/PheWAS_pval_EMMA_norm.RData") +assert_dir(get_setting("JS_BIODALLIANCE")) +assert_file(get_setting("JS_BIODALLIANCE")+"/build/dalliance-all.js") +assert_file(get_setting("JS_BIODALLIANCE")+"/build/worker-all.js") +assert_dir(get_setting("JS_TWITTER_POST_FETCHER")) +assert_file(get_setting("JS_TWITTER_POST_FETCHER")+"/js/twitterFetcher_min.js") -- cgit v1.2.3 From 8ae775f831c278a3ad97372ad90cba5845e8e6ca Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 20 Dec 2017 10:02:43 -0600 Subject: tools: find path for JS and gemma_wrapper --- wqflask/utility/tools.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 63b7149c..57f97a81 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -105,7 +105,7 @@ def js_path(module=None): try_guix = get_setting("JS_GUIX_PATH")+"/"+module if valid_path(try_guix): return try_guix - raise "No JS path found for "+module+" (check JS_GN_PATH)" + raise "No JS path found for "+module+" (if not in Guix check JS_GN_PATH)" def pylmm_command(guess=None): return assert_bin(get_setting("PYLMM_COMMAND",guess)) @@ -247,13 +247,14 @@ USE_GN_SERVER = get_setting_bool('USE_GN_SERVER') GENENETWORK_FILES = get_setting('GENENETWORK_FILES') JS_GUIX_PATH = get_setting('JS_GUIX_PATH') -# assert_dir(JS_GUIX_PATH) - don't enforce right now +assert_dir(JS_GUIX_PATH) JS_GN_PATH = get_setting('JS_GN_PATH') # assert_dir(JS_GN_PATH) PYLMM_COMMAND = app_set("PYLMM_COMMAND",pylmm_command()) GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command()) PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command()) +GEMMA_WRAPPER_COMMAND = gemma_wrapper_command() TEMPDIR = tempdir() # defaults to UNIX TMPDIR assert_dir(TEMPDIR) @@ -276,9 +277,9 @@ if os.environ.get('WQFLASK_OVERRIDES'): OVERRIDES[k] = cmd logger.debug(OVERRIDES) -assert_file(PHEWAS_FILES+"/auwerx/PheWAS_pval_EMMA_norm.RData") -assert_dir(get_setting("JS_BIODALLIANCE")) -assert_file(get_setting("JS_BIODALLIANCE")+"/build/dalliance-all.js") -assert_file(get_setting("JS_BIODALLIANCE")+"/build/worker-all.js") -assert_dir(get_setting("JS_TWITTER_POST_FETCHER")) -assert_file(get_setting("JS_TWITTER_POST_FETCHER")+"/js/twitterFetcher_min.js") +# assert_file(PHEWAS_FILES+"/auwerx/PheWAS_pval_EMMA_norm.RData") +# assert_dir(get_setting("JS_BIODALLIANCE")) +# assert_file(get_setting("JS_BIODALLIANCE")+"/build/dalliance-all.js") +# assert_file(get_setting("JS_BIODALLIANCE")+"/build/worker-all.js") +# assert_dir(get_setting("JS_TWITTER_POST_FETCHER")) +assert_file(JS_TWITTER_POST_FETCHER_PATH+"/js/twitterFetcher_min.js") -- cgit v1.2.3 From 97ccc478543a7bb08fe0cf178e320dd5811d8bfa Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 10 Feb 2018 07:53:53 +0000 Subject: Check for bimbam path and bail out if it is missing --- bin/genenetwork2 | 1 + wqflask/base/webqtlConfig.py | 1 + wqflask/utility/tools.py | 4 ---- 3 files changed, 2 insertions(+), 4 deletions(-) (limited to 'wqflask/utility') diff --git a/bin/genenetwork2 b/bin/genenetwork2 index f64576d5..7148c022 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -45,6 +45,7 @@ SCRIPT=$(realpath "$0") echo SCRIPT=$SCRIPT +echo GN2_PROFILE=$GN2_PROFILE GN2_BASE_DIR=$(dirname $(dirname "$SCRIPT")) GN2_ID=$(cat /etc/hostname):$(basename $GN2_BASE_DIR) diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py index 1ef2bc26..1e66e957 100644 --- a/wqflask/base/webqtlConfig.py +++ b/wqflask/base/webqtlConfig.py @@ -82,6 +82,7 @@ assert_writable_dir(GENERATED_TEXT_DIR) # Flat file directories GENODIR = flat_files('genotype')+'/' assert_dir(GENODIR) +assert_dir(GENODIR+'bimbam') # for gemma # JSON genotypes are OBSOLETE JSON_GENODIR = flat_files('genotype/json')+'/' diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 57f97a81..e3fcd7c7 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -278,8 +278,4 @@ if os.environ.get('WQFLASK_OVERRIDES'): logger.debug(OVERRIDES) # assert_file(PHEWAS_FILES+"/auwerx/PheWAS_pval_EMMA_norm.RData") -# assert_dir(get_setting("JS_BIODALLIANCE")) -# assert_file(get_setting("JS_BIODALLIANCE")+"/build/dalliance-all.js") -# assert_file(get_setting("JS_BIODALLIANCE")+"/build/worker-all.js") -# assert_dir(get_setting("JS_TWITTER_POST_FETCHER")) assert_file(JS_TWITTER_POST_FETCHER_PATH+"/js/twitterFetcher_min.js") -- cgit v1.2.3 From b3d9c748008d401ca5b5fa5d60a6a1eff505ee3e Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 10 Feb 2018 08:22:41 +0000 Subject: Fixed finding PATHs - one return statement! --- wqflask/utility/tools.py | 9 +++++---- wqflask/wqflask/marker_regression/gemma_mapping.py | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index e3fcd7c7..d3113302 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -16,7 +16,7 @@ OVERRIDES = {} def app_set(command_id, value): """Set application wide value""" app.config.setdefault(command_id,value) - value + return value def get_setting(command_id,guess=None): """Resolve a setting from the environment or the global settings in @@ -51,7 +51,7 @@ def get_setting(command_id,guess=None): return None # ---- Check whether environment exists - logger.debug("Looking for "+command_id+"\n") + # print("Looking for "+command_id+"\n") command = value(os.environ.get(command_id)) if command is None or command == "": command = OVERRIDES.get(command_id) @@ -63,7 +63,7 @@ def get_setting(command_id,guess=None): if command is None or command == "": # print command raise Exception(command_id+' setting unknown or faulty (update default_settings.py?).') - logger.debug("Set "+command_id+"="+str(command)) + # print("Set "+command_id+"="+str(command)) return command def get_setting_bool(id): @@ -253,6 +253,7 @@ JS_GN_PATH = get_setting('JS_GN_PATH') PYLMM_COMMAND = app_set("PYLMM_COMMAND",pylmm_command()) GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command()) +assert(GEMMA_COMMAND is not None) PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command()) GEMMA_WRAPPER_COMMAND = gemma_wrapper_command() TEMPDIR = tempdir() # defaults to UNIX TMPDIR @@ -266,7 +267,7 @@ from six import string_types if os.environ.get('WQFLASK_OVERRIDES'): jsonfn = get_setting('WQFLASK_OVERRIDES') - logger.error("WQFLASK_OVERRIDES: %s" % jsonfn) + logger.info("WQFLASK_OVERRIDES: %s" % jsonfn) with open(jsonfn) as data_file: overrides = json.load(data_file) for k in overrides: diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py index a24e43d4..c004983e 100644 --- a/wqflask/wqflask/marker_regression/gemma_mapping.py +++ b/wqflask/wqflask/marker_regression/gemma_mapping.py @@ -3,7 +3,7 @@ import os, math, string, random, json from base import webqtlConfig from base.trait import GeneralTrait from base.data_set import create_dataset -from utility.tools import flat_files, GEMMA_COMMAND, GEMMA_WRAPPER_COMMAND, TEMPDIR +from utility.tools import flat_files, GEMMA_COMMAND, GEMMA_WRAPPER_COMMAND, TEMPDIR, assert_bin import utility.logger logger = utility.logger.getLogger(__name__ ) @@ -11,6 +11,7 @@ logger = utility.logger.getLogger(__name__ ) def run_gemma(this_dataset, samples, vals, covariates, method, use_loco): """Generates p-values for each marker using GEMMA""" + assert_bin(GEMMA_COMMAND); if this_dataset.group.genofile != None: genofile_name = this_dataset.group.genofile[:-5] else: @@ -27,7 +28,7 @@ def run_gemma(this_dataset, samples, vals, covariates, method, use_loco): if i < (len(this_chromosomes) - 1): chr_list_string += this_chromosomes[i+1].name + "," else: - chr_list_string += this_chromosomes[i+1].name + chr_list_string += this_chromosomes[i+1].name if covariates != "": gen_covariates_file(this_dataset, covariates) @@ -247,4 +248,4 @@ def parse_loco_output(this_dataset, gwa_output_filename): included_markers.append(line.split("\t")[1]) p_values.append(float(line.split("\t")[10])) - return marker_obs \ No newline at end of file + return marker_obs -- cgit v1.2.3