From 9a5fe211a846184aea7027aa90fde3fba93697e4 Mon Sep 17 00:00:00 2001 From: DannyArends Date: Mon, 23 Mar 2015 14:59:18 +0000 Subject: Updates to make GN2 work on my version of penguin (ports, and paths) --- wqflask/runserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wqflask/runserver.py') diff --git a/wqflask/runserver.py b/wqflask/runserver.py index 8ab88580..9d5686a9 100755 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -20,7 +20,7 @@ from wqflask import app import logging #from themodule import TheHandlerYouWant -file_handler = logging.FileHandler("/tmp/flask_gn_log") +file_handler = logging.FileHandler("/tmp/flask_gn_log_danny_unsecure") file_handler.setLevel(logging.DEBUG) app.logger.addHandler(file_handler) @@ -28,7 +28,7 @@ import logging_tree logging_tree.printout() app.run(host='0.0.0.0', - port=5002, + port=5003, use_debugger=False, threaded=True, use_reloader=True) -- cgit v1.2.3 From a1d8f68d5428a4ceec9a2d9a771b000ecabec5e6 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 18 Apr 2015 09:36:00 +0000 Subject: pylmm: fix integration problems --- wqflask/runserver.py | 6 ++--- .../wqflask/marker_regression/marker_regression.py | 14 +++++----- wqflask/wqflask/my_pylmm/pyLMM/gn2.py | 30 +++++++++++++++------- wqflask/wqflask/my_pylmm/pyLMM/lmm.py | 19 ++++++++------ wqflask/wqflask/my_pylmm/pyLMM/lmm2.py | 18 ++++++++++--- 5 files changed, 56 insertions(+), 31 deletions(-) (limited to 'wqflask/runserver.py') diff --git a/wqflask/runserver.py b/wqflask/runserver.py index 9d5686a9..fadae6bf 100755 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -20,9 +20,9 @@ from wqflask import app import logging #from themodule import TheHandlerYouWant -file_handler = logging.FileHandler("/tmp/flask_gn_log_danny_unsecure") -file_handler.setLevel(logging.DEBUG) -app.logger.addHandler(file_handler) +# file_handler = logging.FileHandler("/tmp/flask_gn_log_danny_unsecure") +# file_handler.setLevel(logging.DEBUG) +# app.logger.addHandler(file_handler) import logging_tree logging_tree.printout() diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 7708356b..ae3e062f 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -40,6 +40,7 @@ from utility import temp_data from utility.benchmark import Bench +PYLMM_COMMAND= 'python /home/pjotr/izip/git/opensource/python/gn2/wqflask/wqflask/my_pylmm/pyLMM/lmm.py' class MarkerRegression(object): @@ -272,7 +273,7 @@ class MarkerRegression(object): """) def run_rqtl_geno(self): - print("Calling R/qtl from python") + print("Calling R/qtl") self.geno_to_rqtl_function() @@ -655,8 +656,7 @@ class MarkerRegression(object): Redis.set(key, json_params) Redis.expire(key, 60*60) - command = 'python /home/zas1024/gene/wqflask/wqflask/my_pylmm/pyLMM/lmm.py --key {} --species {}'.format(key, - "other") + command = PYLMM_COMMAND+' --key {} --species {}'.format(key,"other") os.system(command) @@ -713,8 +713,8 @@ class MarkerRegression(object): # "refit": False, # "temp_data": tempdata} - print("genotype_matrix:", str(genotype_matrix.tolist())) - print("pheno_vector:", str(pheno_vector.tolist())) + # print("genotype_matrix:", str(genotype_matrix.tolist())) + # print("pheno_vector:", str(pheno_vector.tolist())) params = dict(pheno_vector = pheno_vector.tolist(), genotype_matrix = genotype_matrix.tolist(), @@ -732,7 +732,7 @@ class MarkerRegression(object): Redis.expire(key, 60*60) print("before printing command") - command = 'python /home/zas1024/gene/wqflask/wqflask/my_pylmm/pyLMM/lmm.py --key {} --species {}'.format(key, + command = PYLMM_COMMAND + ' --key {} --species {}'.format(key, "other") print("command is:", command) print("after printing command") @@ -806,7 +806,7 @@ class MarkerRegression(object): print("Before creating the command") - command = 'python /home/zas1024/gene/wqflask/wqflask/my_pylmm/pyLMM/lmm.py --key {} --species {}'.format(key, + command = PYLMM_COMMAND+' --key {} --species {}'.format(key, "human") print("command is:", command) diff --git a/wqflask/wqflask/my_pylmm/pyLMM/gn2.py b/wqflask/wqflask/my_pylmm/pyLMM/gn2.py index 7bceb089..b128bfab 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/gn2.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/gn2.py @@ -1,7 +1,10 @@ -# Genenetwork2 specific methods and callback handler +# Standalone specific methods and callback handler # # Copyright (C) 2015 Pjotr Prins (pjotr.prins@thebird.nl) # +# Set the log level with +# +# logging.basicConfig(level=logging.DEBUG) from __future__ import absolute_import, print_function, division @@ -9,10 +12,12 @@ import numpy as np import sys import logging -# logging.basicConfig(level=logging.DEBUG) -# np.set_printoptions() +# logger = logging.getLogger(__name__) +logger = logging.getLogger('lmm2') +logging.basicConfig(level=logging.DEBUG) +np.set_printoptions(precision=3,suppress=True) -progress_location = None +progress_location = None progress_current = None progress_prev_perc = None @@ -20,30 +25,37 @@ def progress_default_func(location,count,total): global progress_current value = round(count*100.0/total) progress_current = value - + progress_func = progress_default_func def progress_set_func(func): global progress_func progress_func = func - + def progress(location, count, total): global progress_location global progress_prev_perc - + perc = round(count*100.0/total) if perc != progress_prev_perc and (location != progress_location or perc > 98 or perc > progress_prev_perc + 5): progress_func(location, count, total) logger.info("Progress: %s %d%%" % (location,perc)) progress_location = location progress_prev_perc = perc - + def mprint(msg,data): """ Array/matrix print function """ m = np.array(data) - print(msg,m.shape,"=\n",m) + if m.ndim == 1: + print(msg,m.shape,"=\n",m[0:3]," ... ",m[-3:]) + if m.ndim == 2: + print(msg,m.shape,"=\n[", + m[0][0:3]," ... ",m[0][-3:],"\n ", + m[1][0:3]," ... ",m[1][-3:],"\n ...\n ", + m[-2][0:3]," ... ",m[-2][-3:],"\n ", + m[-1][0:3]," ... ",m[-1][-3:],"]") def fatal(msg): logger.critical(msg) diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py index b2067b27..6fff5f1d 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py @@ -42,25 +42,27 @@ from redis import Redis Redis = Redis() import sys -sys.path.append("/home/zas1024/gene/wqflask/") - -has_gn2=True from utility.benchmark import Bench from utility import temp_data -sys.path.append("/home/zas1024/gene/wqflask/wqflask/my_pylmm/pyLMM/") - from kinship import kinship, kinship_full, kvakve import genotype import phenotype import gwas +has_gn2=True +sys.stderr.write("INFO: pylmm system path is "+":".join(sys.path)+"\n") +sys.stderr.write("INFO: pylmm file is "+__file__+"\n") + # ---- A trick to decide on the environment: try: - from wqflask.my_pylmm.pyLMM import chunks + sys.stderr.write("INFO: trying loading module\n") + import utility.formatting # this is never used, just to check the environment + sys.stderr.write("INFO: This is a genenetwork2 environment\n") from gn2 import uses, progress_set_func except ImportError: + # Failed to load gn2 has_gn2=False import standalone as handlers from standalone import uses, progress_set_func @@ -856,7 +858,8 @@ def gwas_with_redis(key,species,new_code=True): print(key) v = params[key] if v is not None: - v = np.array(v) + v = np.array(v).astype(np.float) + print(v) return v def narrayT(key): @@ -969,6 +972,6 @@ if __name__ == '__main__': if has_gn2: gn2_main() else: - print("Run from runlmm.py instead") + fatal("Run from runlmm.py instead") diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py index 358bf27e..c65843ec 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py @@ -24,14 +24,24 @@ from scipy import optimize from optmatrix import matrixMult import kinship +sys.stderr.write("INFO: pylmm (lmm2) system path is "+":".join(sys.path)+"\n") +sys.stderr.write("INFO: pylmm (lmm2) file is "+__file__+"\n") + # ---- A trick to decide on the environment: try: - from wqflask.my_pylmm.pyLMM import chunks - from gn2 import uses + sys.stderr.write("INFO: trying loading module\n") + import utility.formatting # this is never used, just to check the environment + sys.stderr.write("INFO: This is a genenetwork2 environment (lmm2)\n") + from gn2 import uses, progress_set_func except ImportError: - sys.stderr.write("WARNING: LMM2 standalone version missing the Genenetwork2 environment\n") + # Failed to load gn2 has_gn2=False - from standalone import uses + import standalone as handlers + from standalone import uses, progress_set_func + sys.stderr.write("WARNING: LMM2 standalone version missing the Genenetwork2 environment\n") + +progress,mprint,debug,info,fatal = uses('progress','mprint','debug','info','fatal') + def calculateKinship(W,center=False): """ -- cgit v1.2.3 From 5dad3ceb4acd652dd28d183f784005479089aa8a Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 19 Apr 2015 10:55:42 +0200 Subject: Restore logger in runserver --- wqflask/runserver.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'wqflask/runserver.py') diff --git a/wqflask/runserver.py b/wqflask/runserver.py index fadae6bf..20d79218 100755 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -19,10 +19,9 @@ from wqflask import app #_log.addHandler(_ch) import logging -#from themodule import TheHandlerYouWant -# file_handler = logging.FileHandler("/tmp/flask_gn_log_danny_unsecure") -# file_handler.setLevel(logging.DEBUG) -# app.logger.addHandler(file_handler) +file_handler = logging.FileHandler(app.config['LOGFILE']) +file_handler.setLevel(logging.DEBUG) +app.logger.addHandler(file_handler) import logging_tree logging_tree.printout() -- cgit v1.2.3 From 93f663a2e865484cb6f476fb7a0fa2415410e4fd Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 19 Apr 2015 11:01:56 +0200 Subject: runserver: set port --- wqflask/runserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wqflask/runserver.py') diff --git a/wqflask/runserver.py b/wqflask/runserver.py index 20d79218..4ae91e64 100755 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -27,7 +27,7 @@ import logging_tree logging_tree.printout() app.run(host='0.0.0.0', - port=5003, + port=app.config['SERVER_PORT'], use_debugger=False, threaded=True, use_reloader=True) -- cgit v1.2.3 From 240c2db33b70b7d10a6bdd18e043fc0aa6766715 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 19 Apr 2015 11:04:31 +0200 Subject: Output configi --- wqflask/runserver.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'wqflask/runserver.py') diff --git a/wqflask/runserver.py b/wqflask/runserver.py index 4ae91e64..5a76d1e2 100755 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -18,6 +18,8 @@ from wqflask import app #_ch = logging.StreamHandler() #_log.addHandler(_ch) +print app.config + import logging file_handler = logging.FileHandler(app.config['LOGFILE']) file_handler.setLevel(logging.DEBUG) -- cgit v1.2.3