about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins2015-03-10 12:47:27 +0300
committerPjotr Prins2015-03-10 12:47:27 +0300
commit4902e2a8f4a4c9e08272dbd752eeb61f0e6b60f2 (patch)
tree79dba166a26c83232d43ced2a62b2211d7dae2b4
parent926225cf75991142e82d95b2505c59446fa1a8c4 (diff)
downloadgenenetwork2-4902e2a8f4a4c9e08272dbd752eeb61f0e6b60f2.tar.gz
Populationg Redis from TSV data
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/lmm.py49
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/runlmm.py11
2 files changed, 42 insertions, 18 deletions
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
index 3cbab149..8c6e30e8 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
@@ -719,23 +719,11 @@ class LMM:
        pl.ylabel("Probability of data")
        pl.title(title)
 
-# This is the main function used by Genenetwork2 (with environment)
-def gn2_main():
-    parser = argparse.ArgumentParser(description='Run pyLMM')
-    parser.add_argument('-k', '--key')
-    parser.add_argument('-s', '--species')
-    
-    opts = parser.parse_args()
-    
-    key = opts.key
-    species = opts.species
-    
+
+def gn2_redis(key,species):
     json_params = Redis.get(key)
     
     params = json.loads(json_params)
-    #print("params:", params)
-    
-    #print("kinship_matrix:", params['kinship_matrix'])
     
     tempdata = temp_data.TempData(params['temp_uuid'])
     if species == "human" :
@@ -760,7 +748,38 @@ def gn2_main():
     #Pushing json_results into a list where it is the only item because blpop needs a list
     Redis.rpush(results_key, json_results)
     Redis.expire(results_key, 60*60)
-        
+
+# This is the main function used by Genenetwork2 (with environment)
+def gn2_main():
+    parser = argparse.ArgumentParser(description='Run pyLMM')
+    parser.add_argument('-k', '--key')
+    parser.add_argument('-s', '--species')
+    
+    opts = parser.parse_args()
+    
+    key = opts.key
+    species = opts.species
+
+    gn2_redis(key,species)
+
+def gn2_load_redis(key,species,kinship,pheno,geno):
+    print("Loading Redis from parsed data")
+    params = dict(pheno_vector = pheno.tolist(),
+                  genotype_matrix = geno.tolist(),
+                  restricted_max_likelihood = True,
+                  refit = False,
+                  temp_uuid = "testrun_temp_uuid",
+                        
+                  # meta data
+                  timestamp = datetime.datetime.now().isoformat(),
+    )
+            
+    json_params = json.dumps(params)
+    Redis.set(key, json_params)
+    Redis.expire(key, 60*60)
+
+    gn2_redis(key,species)
+    
 if __name__ == '__main__':
     print("WARNING: Calling pylmm from lmm.py will become OBSOLETE, use runlmm.py instead!")
     if has_gn2:
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/runlmm.py b/wqflask/wqflask/my_pylmm/pyLMM/runlmm.py
index bed2e39e..525c43fc 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/runlmm.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/runlmm.py
@@ -19,6 +19,7 @@
 
 from optparse import OptionParser
 import tsvreader
+from lmm import gn2_load_redis
 
 usage = """
 python runlmm.py [options] command
@@ -29,6 +30,7 @@ python runlmm.py [options] command
   Current commands are:
 
     parse        : only parse input files
+    redis        : use Redis to call into GN2
 
   try --help for more information
 """
@@ -58,12 +60,15 @@ print "Command: ",cmd
 
 if options.kinship:
     k = tsvreader.kinship(options.kinship)
-    print len(k)
+    print k.shape
 
 if options.pheno:
     y = tsvreader.pheno(options.pheno)
-    print len(y)
+    print y.shape
 
 if options.geno:
     g = tsvreader.geno(options.geno)
-    print len(g)
+    print g.shape
+
+if cmd == 'redis':
+    gn2_load_redis('testrun','other',k,y,g.T)