diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/base/trait.py | 1 | ||||
-rw-r--r-- | wqflask/utility/helper_functions.py | 16 | ||||
-rw-r--r-- | wqflask/wqflask/collect.py | 41 | ||||
-rw-r--r-- | wqflask/wqflask/model.py | 2 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/add.html | 11 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/view.html | 235 | ||||
-rw-r--r-- | wqflask/wqflask/templates/search_result_page.html | 2 |
7 files changed, 149 insertions, 159 deletions
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 9566c192..f18481a8 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -116,7 +116,6 @@ class GeneralTrait(object): return stringy - def display_name(self): stringy = "" if self.dataset and self.name: diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py index 15f60765..149ee553 100644 --- a/wqflask/utility/helper_functions.py +++ b/wqflask/utility/helper_functions.py @@ -4,6 +4,8 @@ from base.trait import GeneralTrait from base import data_set from base.species import TheSpecies +from wqflask import user_manager + def get_species_dataset_trait(self, start_vars): #assert type(read_genotype) == type(bool()), "Expecting boolean value for read_genotype" @@ -23,13 +25,15 @@ def get_species_dataset_trait(self, start_vars): def get_trait_db_obs(self, trait_db_list): - + if isinstance(trait_db_list, basestring): + trait_db_list = trait_db_list.split(",") + self.trait_list = [] - for i, trait_db in enumerate(trait_db_list): - if i == (len(trait_db_list) - 1): - break - trait_name, dataset_name = trait_db.split(":") - #print("dataset_name:", dataset_name) + for trait in trait_db_list: + data, _separator, hmac = trait.rpartition(':') + data = data.strip() + assert hmac==user_manager.actual_hmac_creation(data), "Data tampering?" + trait_name, dataset_name = data.split(":") dataset_ob = data_set.create_dataset(dataset_name) trait_ob = GeneralTrait(dataset=dataset_ob, name=trait_name, diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index 5484633b..7e7aba89 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -165,12 +165,19 @@ class UserCollection(object): return create_new("Default") else: uc = model.UserCollection.query.get(params['existing_collection']) - members = uc.members_as_set() #set(json.loads(uc.members)) + members = list(uc.members_as_set()) #set(json.loads(uc.members)) len_before = len(members) traits = process_traits(params['traits']) - - members_now = list(members | traits) + + members_now = members + for trait in traits: + if trait in members: + continue + else: + members_now.append(trait) + + #members_now = list(members | traits) len_now = len(members_now) uc.members = json.dumps(members_now) @@ -184,28 +191,6 @@ class UserCollection(object): # Probably have to change that return redirect(url_for('view_collection', uc_id=uc.id)) - def remove_traits(self, params): - - #params = request.form - print("params are:", params) - uc_id = params['uc_id'] - uc = model.UserCollection.query.get(uc_id) - traits_to_remove = params.getlist('traits[]') - print("traits_to_remove are:", traits_to_remove) - traits_to_remove = process_traits(traits_to_remove) - print("\n\n after processing, traits_to_remove:", traits_to_remove) - all_traits = uc.members_as_set() - print(" all_traits:", all_traits) - members_now = all_traits - traits_to_remove - print(" members_now:", members_now) - print("Went from {} to {} members in set.".format(len(all_traits), len(members_now))) - uc.members = json.dumps(list(members_now)) - uc.changed_timestamp = datetime.datetime.utcnow() - db_session.commit() - - # We need to return something so we'll return this...maybe in the future - # we can use it to check the results - return str(len(members_now)) def report_change(len_before, len_now): new_length = len_now - len_before @@ -218,8 +203,6 @@ def report_change(len_before, len_now): print("No new traits were added.") - - @app.route("/collections/add") def collections_add(): traits=request.args['traits'] @@ -329,7 +312,6 @@ def list_collections(): @app.route("/collections/remove", methods=('POST',)) def remove_traits(): - params = request.form print("params are:", params) @@ -337,14 +319,11 @@ def remove_traits(): uc_id = params['uc_id'] uc = model.UserCollection.query.get(uc_id) traits_to_remove = params.getlist('traits[]') - print("traits_to_remove are:", traits_to_remove) traits_to_remove = process_traits(traits_to_remove) print("\n\n after processing, traits_to_remove:", traits_to_remove) all_traits = uc.members_as_set() - print(" all_traits:", all_traits) members_now = all_traits - traits_to_remove print(" members_now:", members_now) - print("Went from {} to {} members in set.".format(len(all_traits), len(members_now))) uc.members = json.dumps(list(members_now)) uc.changed_timestamp = datetime.datetime.utcnow() db_session.commit() diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py index 17343186..5321e420 100644 --- a/wqflask/wqflask/model.py +++ b/wqflask/wqflask/model.py @@ -177,12 +177,10 @@ class UserCollection(Base): except: return 0 - #@property #def display_num_members(self): # return display_collapsible(self.num_members) - def members_as_set(self): return set(json.loads(self.members)) diff --git a/wqflask/wqflask/templates/collections/add.html b/wqflask/wqflask/templates/collections/add.html index c5598e84..47b87d73 100644 --- a/wqflask/wqflask/templates/collections/add.html +++ b/wqflask/wqflask/templates/collections/add.html @@ -6,16 +6,6 @@ </div> <div class="modal-body"> <form action="/collections/new" data-validate="parsley" id="add_form"> -<!-- - <fieldset> - <legend>Use your default collection</legend> - <span class="help-block">Choose this if you're in a hurry or don't plan on using the collection again.</span> - <span class="help-block"><em></em>If you are unsure this is probably the option you want.</em></span> - <button type="submit" name="Default" class="btn">Continue</button> - </fieldset> - <hr /> ---> - <input type="hidden" name="traits" value="{{ traits }}" /> <fieldset> <legend>Create a new named collection</legend> @@ -28,7 +18,6 @@ {% endif %} <button type="submit" name="create_new" class="btn">Create and add traits</button> </fieldset> - <hr /> <fieldset> <legend>Or add to an existing collection</legend> diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index 68d2886f..6a11600c 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -21,64 +21,41 @@ <div class="container"> <div> - <form action="/collections/delete" method="post"> - {% if uc %} - <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> - {% else %} - <input type="hidden" name="collection_name" id="collection_name" value="{{ collection_name }}" /> - {% endif %} - <div class="col-xs-3 controls"> - <input type="submit" class="btn btn-danger" value="Delete this collection" /> - </div> - </form> - <form action="/corr_matrix" method="post"> - {% if uc %} - <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> - {% endif %} - <input type="hidden" name="trait_list" id="trait_list" value= " - {% for this_trait in trait_obs %} - {{ this_trait.name }}:{{ this_trait.dataset.name }}, - {% endfor %}" > - <div class="col-xs-2 controls"> - <input type="submit" class="btn btn-primary" value="Correlation Matrix" /> - </div> - </form> - <form action="/wgcna_setup" method="post"> - {% if uc %} - <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> - {% endif %} - <input type="hidden" name="trait_list" id="trait_list" value= " - {% for this_trait in trait_obs %} - {{ this_trait.name }}:{{ this_trait.dataset.name }}, - {% endfor %}" > - <div class="col-xs-2 controls"> - <input type="submit" class="btn btn-primary" value="WGCNA Analysis" /> - </div> - </form> - <form action="/ctl_setup" method="post"> - {% if uc %} - <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> - {% endif %} - <input type="hidden" name="trait_list" id="trait_list" value= " - {% for this_trait in trait_obs %} - {{ this_trait.name }}:{{ this_trait.dataset.name }}, - {% endfor %}" > - <div class="col-xs-2 controls"> - <input type="submit" class="btn btn-primary" value="CTL Analysis" /> - </div> - </form> - <form action="/heatmap" method="post"> - {% if uc %} - <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> - {% endif %} - <input type="hidden" name="trait_list" id="trait_list" value= " - {% for this_trait in trait_obs %} - {{ this_trait.name }}:{{ this_trait.dataset.name }}, - {% endfor %}" > - <div class="col-xs-2 controls"> - <input type="submit" class="btn btn-primary" value="Heatmap" /> - </div> - </form> + <form id="collection_form" action="/delete" method="post"> + {% if uc %} + <input type="hidden" name="uc_id" id="uc_id" value="{{ uc.id }}" /> + {% endif %} + <input type="hidden" name="collection_name" id="collection_name" value="{{ collection_name }}" /> + <input type="hidden" name="trait_list" id="trait_list" value= " + {% for this_trait in trait_obs %} + {{ this_trait.name }}:{{ this_trait.dataset.name }}, + {% endfor %}" > + <div class="col-xs-3 controls"> + <button id="delete" class="btn btn-danger submit_special" data-url="/collections/delete" title="Delete this collection" > + Delete this collection + </button> + </div> + <div class="col-xs-2 controls"> + <button id="corr_matrix" class="btn btn-primary submit_special" data-url="/corr_matrix" title="Correlation Matrix" > + Correlation Matrix + </button> + </div> + <div class="col-xs-2 controls"> + <button id="wgcna_setup" class="btn btn-primary submit_special" data-url="/wgcna_setup" title="WGCNA Analysis" > + WGCNA Analysis + </button> + </div> + <div class="col-xs-2 controls"> + <button id="ctl_setup" class="btn btn-primary submit_special" data-url="/ctl_setup" title="CTL Analysis" > + CTL Analysis + </button> + </div> + <div class="col-xs-2 controls"> + <button id="heatmap" class="btn btn-primary submit_special" data-url="/heatmap" title="Heatmap" > + Heatmap + </button> + </div> + </form> </div> <div> @@ -92,53 +69,54 @@ <button class="btn" id="remove" disabled="disabled"><i class="icon-minus-sign"></i> Remove Record</button> <br /> <br /> - <div style="background-color: #eeeeee; border: 1px solid black;"> - <table class="table table-hover table-striped" id='trait_table'> - <thead> - <tr> - <th style="background-color: #eeeeee;"></th> - <th style="background-color: #eeeeee;">Index</th> - <th style="background-color: #eeeeee;">Record</th> - <th style="background-color: #eeeeee;">Description</th> - <th style="background-color: #eeeeee;">Location</th> - <th style="background-color: #eeeeee;">Mean</th> - <th style="background-color: #eeeeee;">Max LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - <th style="background-color: #eeeeee;">Max LRS Location</th> - <th style="background-color: #eeeeee;">Additive Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - </tr> - </thead> - - <tbody> - {% for this_trait in trait_obs %} - <TR id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> - <TD> - <INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" - VALUE="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"> - </TD> - <TD>{{ loop.index }}</TD> - <TD> - <a href="{{ url_for('show_trait_page', - trait_id = this_trait.name, - dataset = this_trait.dataset.name - )}}"> - {{ this_trait.name }} - </a> - </TD> - - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.location_repr }}</TD> - <TD>{{ this_trait.mean }}</TD> - <TD>{{ this_trait.LRS_score_repr }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - <TD>{{ this_trait.additive }}</TD> - - </TR> - {% endfor %} - </tbody> - - </table> - </div> - <br /> + <div style="background-color: #eeeeee; border: 1px solid black;"> + <table id="trait_table" class="table table-hover table-striped"> + <thead> + <tr> + <th style="background-color: #eeeeee;"></th> + <th style="background-color: #eeeeee;">Index</th> + <th style="background-color: #eeeeee;">Dataset</th> + <th style="background-color: #eeeeee;">Record</th> + <th style="background-color: #eeeeee;">Description</th> + <th style="background-color: #eeeeee;">Location</th> + <th style="background-color: #eeeeee;">Mean</th> + <th style="background-color: #eeeeee;">Max LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th style="background-color: #eeeeee;">Max LRS Location</th> + <th style="background-color: #eeeeee;">Additive Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + </tr> + </thead> + + <tbody> + {% for this_trait in trait_obs %} + <TR id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> + <TD> + <INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" + VALUE="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"> + </TD> + <TD>{{ loop.index }}</TD> + <TD>{{ this_trait.dataset.name }}</TD> + <TD> + <a href="{{ url_for('show_trait_page', + trait_id = this_trait.name, + dataset = this_trait.dataset.name + )}}"> + {{ this_trait.name }} + </a> + </TD> + <TD>{{ this_trait.description_display }}</TD> + <TD>{{ this_trait.location_repr }}</TD> + <TD>{{ '%0.3f' % this_trait.mean|float }}</TD> + <TD>{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> + <TD>{{ this_trait.LRS_location_repr }}</TD> + <TD>{{ '%0.3f' % this_trait.additive|float }}</TD> + + </TR> + {% endfor %} + </tbody> + + </table> + </div> + <br /> </div> </div> @@ -175,13 +153,14 @@ { "type": "natural" }, { "type": "natural" }, { "type": "natural" }, + { "type": "natural" }, { "type": "natural", "width": "35%" }, { "type": "natural", "width": "15%" }, { "type": "cust-txt" }, { "type": "natural", - "width": "12%" }, + "width": "9%" }, { "type": "natural", "width": "15%" }, { "type": "natural" } @@ -193,7 +172,7 @@ title: 'collection', fieldBoundary: '"', exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8] + columns: [1, 2, 3, 4, 5, 6, 7, 8, 9] } } ], @@ -208,6 +187,48 @@ } ); console.timeEnd("Creating table"); + submit_special = function(url) { + $("#collection_form").attr("action", url); + return $("#collection_form").submit(); + }; + + $("#delete").on("click", function() { + url = $(this).data("url") + return submit_special(url) + }); + + $("#corr_matrix").on("click", function() { + traits = $("#trait_table input:checked").map(function() { + return $(this).val(); + }).get(); + $("#trait_list").val(traits) + url = $(this).data("url") + return submit_special(url) + }); + $("#wgcna_setup").on("click", function() { + traits = $("#trait_table input:checked").map(function() { + return $(this).val(); + }).get(); + $("#trait_list").val(traits) + url = $(this).data("url") + return submit_special(url) + }); + $("#ctl_setup").on("click", function() { + traits = $("#trait_table input:checked").map(function() { + return $(this).val(); + }).get(); + $("#trait_list").val(traits) + url = $(this).data("url") + return submit_special(url) + }); + $("#heatmap").on("click", function() { + traits = $("#trait_table input:checked").map(function() { + return $(this).val(); + }).get(); + $("#trait_list").val(traits) + url = $(this).data("url") + return submit_special(url) + }); }); </script> diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 02c97862..bf1475ff 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -122,7 +122,7 @@ {{ this_trait.pubmed_text }} </a> </TD> - <TD>{{ this_trait.LRS_score_repr }}</TD> + <TD>{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> <TD>{{ this_trait.LRS_location_repr }}</TD> <TD>{{ '%0.3f' % this_trait.additive|float }}</TD> {% elif dataset.type == 'Geno' %} |