Skip to content

Commit

Permalink
Merge pull request #39 from pjotrp/master
Browse files Browse the repository at this point in the history
Refactoring finding tools such as pylmm
  • Loading branch information
zsloan committed May 13, 2015
2 parents 8e8e14b + 6d14bf7 commit 8fa3154
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Next update the setting.py file to point at the tree

GN2 can locate PYLMM through PYLMM_PATH in setting.py (or in ENV)

PYLMM_PATH = '/home/test/opensource/python/pylmm_gn2/pylmm_gn2'
PYLMM_PATH = '/home/test/opensource/python/pylmm_gn2'

## Other information

Check also the ./misc/ directory for settings
Check also the ./misc/ directory for settings
51 changes: 51 additions & 0 deletions wqflask/utility/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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
15 changes: 2 additions & 13 deletions wqflask/wqflask/marker_regression/marker_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Redis = Redis()

from flask import Flask, g
from wqflask import app

from base.trait import GeneralTrait
from base import data_set
Expand All @@ -36,23 +35,13 @@
#from wqflask.marker_regression import plink_mapping
from wqflask.marker_regression import gemma_mapping
#from wqflask.marker_regression import rqtl_mapping
from wqflask.my_pylmm.data import prep_data
# from wqflask.my_pylmm.pyLMM import lmm
# from wqflask.my_pylmm.pyLMM import input
from utility import helper_functions
from utility import Plot, Bunch
from utility import temp_data

from utility.benchmark import Bench
from utility.tools import pylmm_command

import os
if os.environ.get('PYLMM_PATH') is None:
PYLMM_PATH=app.config.get('PYLMM_PATH')
if PYLMM_PATH is None:
PYLMM_PATH=os.environ['HOME']+'/gene/wqflask/wqflask/my_pylmm/pyLMM'
if not os.path.isfile(PYLMM_PATH+'/lmm.py'):
raise Exception('PYLMM_PATH '+PYLMM_PATH+' unknown or faulty')
PYLMM_COMMAND= 'python '+PYLMM_PATH+'/lmm.py'
PYLMM_PATH,PYLMM_COMMAND = pylmm_command()

class MarkerRegression(object):

Expand Down

0 comments on commit 8fa3154

Please sign in to comment.