aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2015-03-18 11:18:58 +0300
committerPjotr Prins2015-03-18 11:18:58 +0300
commit876e80148984274dfd3b8281677c7541504feb59 (patch)
treec180b2463d5987dfe95f43632333360645ec45d6
parent178cdbbd1a52cfcab975ab27b36e148009cc3577 (diff)
downloadgenenetwork2-876e80148984274dfd3b8281677c7541504feb59.tar.gz
Added uses as syntax sugar for callbacks
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/kinship.py5
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/lmm.py6
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/lmm2.py8
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/standalone.py9
4 files changed, 18 insertions, 10 deletions
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/kinship.py b/wqflask/wqflask/my_pylmm/pyLMM/kinship.py
index 43e7fe36..d3792570 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/kinship.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/kinship.py
@@ -155,13 +155,12 @@ def kinship(G,computeSize=1000,numThreads=None,useBLAS=False,verbose=True):
# np.savetxt(outFile+".kve",Kve)
return K
-def kvakve(K, callbacks):
+def kvakve(K, uses):
"""
Obtain eigendecomposition for K and return Kva,Kve where Kva is cleaned
of small values < 1e-6 (notably smaller than zero)
"""
- info = callbacks()['info']
- mprint = callbacks()['mprint']
+ info,mprint = uses('info','mprint')
info("Obtaining eigendecomposition for %dx%d matrix" % (K.shape[0],K.shape[1]) )
Kva,Kve = linalg.eigh(K)
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
index 5ad644e2..2076bc84 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
@@ -57,11 +57,11 @@ import gwas
# ---- A trick to decide on the environment:
try:
from wqflask.my_pylmm.pyLMM import chunks
- from gn2 import callbacks
+ from gn2 import uses
except ImportError:
print("WARNING: Standalone version missing the Genenetwork2 environment\n")
has_gn2=False
- from standalone import callbacks
+ from standalone import uses
pass
#np.seterr('raise')
@@ -597,7 +597,7 @@ class LMM:
# if self.verbose: sys.stderr.write("Obtaining eigendecomposition for %dx%d matrix\n" % (K.shape[0],K.shape[1]) )
begin = time.time()
# Kva,Kve = linalg.eigh(K)
- Kva,Kve = kvakve(K,callbacks)
+ Kva,Kve = kvakve(K,uses)
end = time.time()
if self.verbose: sys.stderr.write("Total time: %0.3f\n" % (end - begin))
print("sum(Kva),sum(Kve)=",sum(Kva),sum(Kve))
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py
index 6aefb9d3..5b93ae0d 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm2.py
@@ -24,14 +24,14 @@ from scipy import optimize
from optmatrix import matrixMult
import kinship
-# A trick to decide on the environment:
+# ---- A trick to decide on the environment:
try:
from wqflask.my_pylmm.pyLMM import chunks
- from gn2 import callbacks
+ from gn2 import uses
except ImportError:
print("WARNING: Standalone version missing the Genenetwork2 environment\n")
has_gn2=False
- from standalone import callbacks
+ from standalone import uses
pass
def calculateKinship(W,center=False):
@@ -194,7 +194,7 @@ class LMM2:
# if self.verbose: sys.stderr.write("Obtaining eigendecomposition for %dx%d matrix\n" % (K.shape[0],K.shape[1]) )
begin = time.time()
# Kva,Kve = linalg.eigh(K)
- Kva,Kve = kinship.kvakve(K,callbacks)
+ Kva,Kve = kinship.kvakve(K,uses)
end = time.time()
if self.verbose: sys.stderr.write("Total time: %0.3f\n" % (end - begin))
print("sum(Kva),sum(Kve)=",sum(Kva),sum(Kve))
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/standalone.py b/wqflask/wqflask/my_pylmm/pyLMM/standalone.py
index bbee3cd7..705da21f 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/standalone.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/standalone.py
@@ -44,6 +44,12 @@ def callbacks():
progress = progress,
mprint = mprint
)
+
+def uses(*funcs):
+ """
+ Some sugar
+ """
+ return [callbacks()[func] for func in funcs]
# ----- Minor test cases:
@@ -69,3 +75,6 @@ if __name__ == '__main__':
[5,0.5,0.6096595 , -0.31559815, -0.52793285, 1.16573418e-15],
[6,0.5,0.6096595 , -0.31559815, -0.52793285, 1.16573418e-15]]
mprint("matrix",matrix)
+ ix,dx = uses("info","debug")
+ ix("ix")
+ dx("dx")