diff options
author | Zachary Sloan | 2013-03-07 00:34:51 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-03-07 00:34:51 +0000 |
commit | 855a586f82fd1774358d8cfde28ce067f1c6c2ae (patch) | |
tree | d51c2771ab266e2660327fad89850f45d508016c /wqflask | |
parent | 4bce386b619c55e66d6cdd81b11b54baadc5ae87 (diff) | |
download | genenetwork2-855a586f82fd1774358d8cfde28ce067f1c6c2ae.tar.gz |
Created file temp_data to store data related to progress
of the marker regression calculations
Storing progress of kinship matrix calculation in variable as
portion of 45 (the rough percent of total marker regression calculation
time
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/utility/helper_functions.py | 1 | ||||
-rw-r--r-- | wqflask/utility/temp_data.py | 27 | ||||
-rwxr-xr-x | wqflask/wqflask/marker_regression/marker_regression.py | 11 | ||||
-rw-r--r-- | wqflask/wqflask/my_pylmm/pyLMM/lmm.py | 8 | ||||
-rwxr-xr-x | wqflask/wqflask/show_trait/show_trait.py | 4 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee | 10 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js | 43 | ||||
-rw-r--r-- | wqflask/wqflask/templates/show_trait.html | 4 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 11 |
9 files changed, 65 insertions, 54 deletions
diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py index d2567b63..56b409e6 100644 --- a/wqflask/utility/helper_functions.py +++ b/wqflask/utility/helper_functions.py @@ -4,6 +4,7 @@ from base.trait import GeneralTrait from base import data_set from base.species import TheSpecies + def get_species_dataset_trait(self, start_vars): #assert type(read_genotype) == type(bool()), "Expecting boolean value for read_genotype" self.dataset = data_set.create_dataset(start_vars['dataset']) diff --git a/wqflask/utility/temp_data.py b/wqflask/utility/temp_data.py new file mode 100644 index 00000000..192dcc44 --- /dev/null +++ b/wqflask/utility/temp_data.py @@ -0,0 +1,27 @@ +from __future__ import print_function, division, absolute_import +from redis import Redis + +import simplejson as json + +class TempData(object): + + def __init__(self, temp_uuid): + self.temp_uuid = temp_uuid + self.redis = Redis() + self.key = "tempdata:{}".format(self.temp_uuid) + + def store(self, field, value): + print("Storing...") + self.redis.hset(self.key, field, value) + self.redis.expire(self.key, 60*15) # Expire in 15 minutes + + def get_all(self): + return self.redis.hgetall(self.key) + + + +if __name__ == "__main__": + redis = Redis() + for key in redis.keys(): + for field in redis.hkeys(key): + print("{}.{}={}".format(key, field, redis.hget(key, field))) diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 40ebc546..412d9e35 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -34,6 +34,7 @@ from dbFunction import webqtlDatabaseFunction from base.GeneralObject import GeneralObject from wqflask.my_pylmm.data import prep_data from wqflask.my_pylmm.pyLMM import lmm +from utility import temp_data import reaper import cPickle @@ -65,7 +66,13 @@ class MarkerRegression(object): helper_functions.get_species_dataset_trait(self, start_vars) + print("start_vars is:", start_vars) + + self.num_perm = int(start_vars['num_perm']) + #self.temp_uuid = start_vars['temp_uuid'] + self.temp_data = temp_data.TempData(start_vars['temp_uuid']) + # Passed in by the form (user might have edited) #samples = start_vars['allsamples'].split() @@ -465,7 +472,7 @@ class MarkerRegression(object): def gen_data(self): """Todo: Fill this in here""" - print("Session UUID: ", self.start_vars[session_uuid]) + #print("Temp UUID: ", self.temp_uuid) genotype_data = [marker['genotypes'] for marker in self.dataset.group.markers.markers] @@ -476,7 +483,7 @@ class MarkerRegression(object): genotype_matrix = np.array(trimmed_genotype_data).T with Bench("Calculate Kinship"): - kinship_matrix = lmm.calculate_kinship(genotype_matrix) + kinship_matrix = lmm.calculate_kinship(genotype_matrix, self.temp_data) with Bench("Create LMM object"): lmm_ob = lmm.LMM(pheno_vector, kinship_matrix) diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py index 374452f0..cc2e32a7 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py @@ -54,7 +54,7 @@ def matrixMult(A,B): return linalg.fblas.dgemm(alpha=1.,a=AA,b=BB,trans_a=transA,trans_b=transB) -def calculate_kinship(genotype_matrix): +def calculate_kinship(genotype_matrix, temp_data): """ genotype_matrix is an n x m matrix encoding SNP minor alleles. @@ -87,8 +87,10 @@ def calculate_kinship(genotype_matrix): keep.append(counter) genotype_matrix[:,counter] = (genotype_matrix[:,counter] - values_mean) / np.sqrt(vr) - stage = round((counter/m)*45) - print("Percent complete: ", stage) + percent_complete = int(round((counter/m)*45)) + print("Percent complete: ", percent_complete) + temp_data.store("percent_complete", percent_complete) + genotype_matrix = genotype_matrix[:,keep] kinship_matrix = np.dot(genotype_matrix,genotype_matrix.T) * 1.0/float(m) return kinship_matrix diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 7b2d022c..16aec827 100755 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -122,7 +122,7 @@ class ShowTrait(object): # We'll need access to this_trait and hddn in the Jinja2 Template, so we put it inside self self.hddn = hddn - self.session_uuid = uuid.uuid4() + self.temp_uuid = uuid.uuid4() self.sample_group_types = OrderedDict() self.sample_group_types['samples_primary'] = self.dataset.group.name + " Only" @@ -133,7 +133,7 @@ class ShowTrait(object): js_data = dict(sample_group_types = self.sample_group_types, sample_lists = sample_lists, attribute_names = self.sample_groups[0].attributes, - session_uuid = self.session_uuid) + temp_uuid = self.temp_uuid) #print("js_data:", pf(js_data)) self.js_data = js_data diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee index 83cdce4d..50b97171 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee @@ -11,13 +11,21 @@ $ -> $("#trait_data_form").attr("action", url); $("#trait_data_form").submit() + get_progress () => + console.log("temp_uuid:", $("#temp_uuid").val()) + $("#marker_regression").click(() => $("#progress_bar_container").modal() + + get_progress() + url = "/marker_regression" + form_data = $('#trait_data_form').serialize() + console.log("form_data is:", form_data) $.ajax( type: "POST" url: url - data: $("#trait_data_form").serialize() + data: form_data success: (data) => $('#progress_bar_container').modal('hide') $("body").html(data) diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js index 9e40a129..c8b0aa7b 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js @@ -1,47 +1,6 @@ // Generated by CoffeeScript 1.4.0 (function() { - $(function() { - var composite_mapping_fields, submit_special, toggle_enable_disable, - _this = this; - submit_special = function() { - var url; - console.log("In submit_special"); - console.log("this is:", this); - console.log("$(this) is:", $(this)); - url = $(this).data("url"); - console.log("url is:", url); - $("#trait_data_form").attr("action", url); - return $("#trait_data_form").submit(); - }; - $("#marker_regression").click(function() { - var url; - $("#progress_bar_container").modal(); - url = "/marker_regression"; - $.ajax({ - type: "POST", - url: url, - data: $("#trait_data_form").serialize(), - success: function(data) { - $('#progress_bar_container').modal('hide'); - return $("body").html(data); - } - }); - return false; - }); - composite_mapping_fields = function() { - return $(".composite_fields").toggle(); - }; - $("#use_composite_choice").change(composite_mapping_fields); - toggle_enable_disable = function(elem) { - return $(elem).prop("disabled", !$(elem).prop("disabled")); - }; - $("#choose_closet_control").change(function() { - return toggle_enable_disable("#control_locus"); - }); - return $("#display_all_lrs").change(function() { - return toggle_enable_disable("#suggestive_lrs"); - }); - }); + }).call(this); diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html index bb87b4bb..2d569b20 100644 --- a/wqflask/wqflask/templates/show_trait.html +++ b/wqflask/wqflask/templates/show_trait.html @@ -21,8 +21,8 @@ {% for key in hddn %} <input type="hidden" name="{{ key }}" value="{{ hddn[key] }}"> {% endfor %} - - <input type="hidden" name="session_uuid" value="{{ session_uuid }}"> + + <input type="hidden" name="temp_uuid" value="{{ temp_uuid }}"> <div class="container"> <div class="page-header"> diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 9a250434..473dfdff 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -13,13 +13,14 @@ import sqlalchemy from wqflask import app -from flask import render_template, request, make_response, Response, Flask, g, config +from flask import render_template, request, make_response, Response, Flask, g, config, jsonify from wqflask import search_results from wqflask.show_trait import show_trait from wqflask.show_trait import export_trait_data from wqflask.marker_regression import marker_regression from wqflask.correlation import show_corr_results +from utility import temp_data from wqflask.dataSharing import SharingInfo, SharingInfoPage @@ -178,6 +179,12 @@ def sharing_info_page(): return template_vars +@app.route("/get_temp_data") +def get_temp_data(): + temp_uuid = request.args['key'] + return flask.jsonify(temp_data.TempData(temp_uuid).get_all()) + + def json_default_handler(obj): '''Based on http://stackoverflow.com/a/2680060/1175849''' # Handle datestamps @@ -194,4 +201,4 @@ def json_default_handler(obj): # return None else: raise TypeError, 'Object of type %s with value of %s is not JSON serializable' % ( - type(obj), repr(obj)) + type(obj), repr(obj))
\ No newline at end of file |