diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/do_search.py | 6 | ||||
-rw-r--r-- | wqflask/wqflask/parser.py | 40 | ||||
-rwxr-xr-x | wqflask/wqflask/show_trait/show_trait.py | 16 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/show_trait.coffee | 57 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/show_trait.js | 46 | ||||
-rw-r--r-- | wqflask/wqflask/templates/show_trait_edit_data.html | 130 |
6 files changed, 167 insertions, 128 deletions
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index 61bfbaba..fd03f359 100644 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -5,8 +5,12 @@ from __future__ import print_function, division from pprint import pformat as pf +import sys +sys.path.append("..") + from dbFunction import webqtlDatabaseFunction + class DoSearch(object): """Parent class containing parameters/functions used for all searches""" @@ -423,8 +427,6 @@ if __name__ == "__main__": import MySQLdb import sys - sys.path.append("/home/zas1024/gene/wqflask") - print("Path is:", sys.path) from base import webqtlConfig diff --git a/wqflask/wqflask/parser.py b/wqflask/wqflask/parser.py index 74343b8a..dc33fc52 100644 --- a/wqflask/wqflask/parser.py +++ b/wqflask/wqflask/parser.py @@ -1,12 +1,33 @@ +""" +Parses search terms input by user + +Searches take two primary forms: +- search term by itself (ex. "shh" or "brain") +- key / separator / value(s) (ex. "LRS=(9 99 Chr4 122 155)" or "GO:342533") + +In the example of "LRS=(9 99 Chr4 122 155)", the key is "LRS", the separator is "=" and the value +is everything within the parentheses. + +Both "=" and ":" can be used as separators; in the future, it would also be good to allow no +separator at all (ex. "cisLRS(9 999 10)") + +Both square brackets and parentheses can be used interchangeably. Both can also be used to +encapsulate a single value; "cisLRS=[9 999 10)" would +be acceptable.] + +""" + from __future__ import print_function, division import re from pprint import pformat as pf - def parse(pstring): - pstring = re.split(r"""(?:(\w+\s*=\s*\([^)]*\))|(\w+\s*[=:]\w+)|(\w+))""", pstring) + pstring = re.split(r"""(?:(\w+\s*=\s*[\(\[][^)]*[\)\]]) | # LRS=(1 2 3), cisLRS=[4 5 6], etc + (\w+\s*[=:]\w+) | # wiki=bar, GO:foobar, etc + (\w+)) # shh, brain, etc """, pstring, + flags=re.VERBOSE) pstring = [item.strip() for item in pstring if item and item.strip()] print(pstring) @@ -21,19 +42,12 @@ def parse(pstring): seperator = None if seperator: - if '(' in value: - assert value.startswith("("), "Invalid token" - assert value.endswith(")"), "Invalid token" + if '(' in value or '[' in value: + assert value.startswith(("(", "[")), "Invalid token" + assert value.endswith((")", "]")), "Invalid token" value = value[1:-1] # Get rid of the parenthesis values = re.split(r"""\s+|,""", value) value = [value.strip() for value in values if value.strip()] - # Brackets can also be used to encapsulate values - elif '[' in value: - assert value.startswith("["), "Invalid token" - assert value.endswith("]"), "Invalid token" - value = value[1:-1] # Get rid of the brackets - values = re.split(r"""\s+|,""", value) - value = [value.strip() for value in values if value.strip()] term = dict(key=key, seperator=seperator, search_term=value) @@ -47,6 +61,8 @@ def parse(pstring): return(items) if __name__ == '__main__': + parse("foo=[3 2 1]") + parse("foo=[3 2 1)") parse("foo=(3 2 1)") parse("shh") parse("shh grep") diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 86a0a992..19e67c43 100755 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -159,9 +159,9 @@ class ShowTrait(templatePage): self.hddn = hddn self.sample_group_types = OrderedDict() - self.sample_group_types['primary_only'] = fd.RISet + " Only" - self.sample_group_types['other_only'] = "Non-" + fd.RISet - self.sample_group_types['all_cases'] = "All Cases" + self.sample_group_types['samples_primary'] = fd.RISet + " Only" + self.sample_group_types['samples_other'] = "Non-" + fd.RISet + self.sample_group_types['samples_all'] = "All Cases" sample_lists = [group.sample_list for group in self.sample_groups] print("sample_lists is:", pf(sample_lists)) js_data = dict(sample_group_types = self.sample_group_types, @@ -176,16 +176,16 @@ class ShowTrait(templatePage): #if traitInfos: # database, ProbeSetID, CellID = traitInfos #else: - database = self.fd['database'] - probe_set_id = self.fd['ProbeSetID'] + dataset = self.fd['dataset'] + trait_id = self.fd['trait_id'] cell_id = self.fd.get('CellID') - this_trait = webqtlTrait(db=database, name=probe_set_id, cellid=cell_id, cursor=self.cursor) + this_trait = webqtlTrait(db=dataset, name=trait_id, cellid=cell_id, cursor=self.cursor) ##identification, etc. - self.fd.identification = '%s : %s' % (this_trait.db.shortname, probe_set_id) + self.fd.identification = '%s : %s' % (this_trait.db.shortname, trait_id) this_trait.returnURL = webqtlConfig.CGIDIR + webqtlConfig.SCRIPTFILE + '?FormID=showDatabase&database=%s\ - &ProbeSetID=%s&RISet=%s&parentsf1=on' %(database, probe_set_id, self.fd['RISet']) + &ProbeSetID=%s&RISet=%s&parentsf1=on' %(dataset, trait_id, self.fd['RISet']) if cell_id: self.fd.identification = '%s/%s'%(self.fd.identification, cell_id) diff --git a/wqflask/wqflask/static/new/javascript/show_trait.coffee b/wqflask/wqflask/static/new/javascript/show_trait.coffee index 10671e78..6e22119f 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.coffee +++ b/wqflask/wqflask/static/new/javascript/show_trait.coffee @@ -26,45 +26,62 @@ $ -> current_value = parseFloat($(in_box)).toFixed(decimal_places) + console.log("urgh:", category, value_type) the_value = sample_sets[category][value_type]() + console.log("After running sample_sets, the_value is:", the_value) if decimal_places > 0 the_value = the_value.toFixed(decimal_places) + console.log("*-* the_value:", the_value) + console.log("*-* current_value:", current_value) if the_value != current_value $(id).html(the_value).effect("highlight") update_stat_values = (sample_sets)-> - for category in ['primary_only', 'other_only', 'all_cases'] + for category in ['samples_primary', 'samples_other', 'samples_all'] change_stats_value(sample_sets, category, "n_of_samples", 0) for stat in ["mean", "median", "std_dev", "std_error"] + console.log("Calling change_stats_value") change_stats_value(sample_sets, category, stat, 2) edit_data_change = -> sample_sets = - primary_only: new Stats([]) - other_only: new Stats([]) - all_cases: new Stats([]) + samples_primary: new Stats([]) + samples_other: new Stats([]) + samples_all: new Stats([]) console.log("at beginning:", sample_sets) - values = $('#value_table').find(".edit_sample_value") - for value in values - real_value = $(value).val() - row = $(value).closest("tr") - category = row[0].id - checkbox = $(row).find(".edit_sample_checkbox") - checked = $(checkbox).attr('checked') - - if checked and is_number(real_value) and real_value != "" - real_value = parseFloat(real_value) - if _(category).startsWith("Primary") - sample_sets.primary_only.add_value(real_value) - else if _(category).startsWith("Other") - sample_sets.other_only.add_value(real_value) - sample_sets.all_cases.add_value(real_value) + # ########## + # Bug here #value_table doesn't exist and why is it a class? + # ########## + + #values = $('.value_table').find(".edit_sample_value") + + + tables = ['samples_primary', 'samples_other'] + for table in tables + rows = $("#" + table).find('tr') + console.log("[fuji3] rows:", rows) + for row in rows + real_value = $(row).find('.edit_sample_value').val() + #row = $(value).closest("tr") + #category = row[0].id + console.log("real_value:", real_value) + checkbox = $(row).find(".edit_sample_checkbox") + checked = $(checkbox).attr('checked') + + if checked and is_number(real_value) and real_value != "" + console.log("in the iffy if") + real_value = parseFloat(real_value) + #if _(category).startsWith("Primary") + sample_sets[table].add_value(real_value) + #else if _(category).startsWith("Other") + # sample_sets.other_only.add_value(real_value) + sample_sets['samples_all'].add_value(real_value) console.log("towards end:", sample_sets) update_stat_values(sample_sets) - + make_table = -> header = "<thead><tr><th> </th>" diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index db40b547..919bc766 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -32,17 +32,21 @@ console.log("the_id:", id); in_box = $(id).html; current_value = parseFloat($(in_box)).toFixed(decimal_places); + console.log("urgh:", category, value_type); the_value = sample_sets[category][value_type](); + console.log("After running sample_sets, the_value is:", the_value); if (decimal_places > 0) { the_value = the_value.toFixed(decimal_places); } + console.log("*-* the_value:", the_value); + console.log("*-* current_value:", current_value); if (the_value !== current_value) { return $(id).html(the_value).effect("highlight"); } }; update_stat_values = function(sample_sets) { var category, stat, _i, _len, _ref, _results; - _ref = ['primary_only', 'other_only', 'all_cases']; + _ref = ['samples_primary', 'samples_other', 'samples_all']; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { category = _ref[_i]; @@ -53,6 +57,7 @@ _results1 = []; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { stat = _ref1[_j]; + console.log("Calling change_stats_value"); _results1.push(change_stats_value(sample_sets, category, stat, 2)); } return _results1; @@ -61,29 +66,30 @@ return _results; }; edit_data_change = function() { - var category, checkbox, checked, real_value, row, sample_sets, value, values, _i, _len; + var checkbox, checked, real_value, row, rows, sample_sets, table, tables, _i, _j, _len, _len1; sample_sets = { - primary_only: new Stats([]), - other_only: new Stats([]), - all_cases: new Stats([]) + samples_primary: new Stats([]), + samples_other: new Stats([]), + samples_all: new Stats([]) }; console.log("at beginning:", sample_sets); - values = $('#value_table').find(".edit_sample_value"); - for (_i = 0, _len = values.length; _i < _len; _i++) { - value = values[_i]; - real_value = $(value).val(); - row = $(value).closest("tr"); - category = row[0].id; - checkbox = $(row).find(".edit_sample_checkbox"); - checked = $(checkbox).attr('checked'); - if (checked && is_number(real_value) && real_value !== "") { - real_value = parseFloat(real_value); - if (_(category).startsWith("Primary")) { - sample_sets.primary_only.add_value(real_value); - } else if (_(category).startsWith("Other")) { - sample_sets.other_only.add_value(real_value); + tables = ['samples_primary', 'samples_other']; + for (_i = 0, _len = tables.length; _i < _len; _i++) { + table = tables[_i]; + rows = $("#" + table).find('tr'); + console.log("[fuji3] rows:", rows); + for (_j = 0, _len1 = rows.length; _j < _len1; _j++) { + row = rows[_j]; + real_value = $(row).find('.edit_sample_value').val(); + console.log("real_value:", real_value); + checkbox = $(row).find(".edit_sample_checkbox"); + checked = $(checkbox).attr('checked'); + if (checked && is_number(real_value) && real_value !== "") { + console.log("in the iffy if"); + real_value = parseFloat(real_value); + sample_sets[table].add_value(real_value); + sample_sets['samples_all'].add_value(real_value); } - sample_sets.all_cases.add_value(real_value); } } console.log("towards end:", sample_sets); diff --git a/wqflask/wqflask/templates/show_trait_edit_data.html b/wqflask/wqflask/templates/show_trait_edit_data.html index ce1642d3..6c9b1073 100644 --- a/wqflask/wqflask/templates/show_trait_edit_data.html +++ b/wqflask/wqflask/templates/show_trait_edit_data.html @@ -82,78 +82,76 @@ <div> <h3>{{ sample_type.header }}</h3> - <div id="{{ sample_type.sample_group_type }}"> - <table class="table table-hover table-striped" {# Todo: Turn tablesorter back on #} - id="{{ 'sortable%i' % (loop.index) }}"> - <tr> - <th>Index</th> - - <th>Sample</th> - - <th>Value</th> - {% if sample_type.se_exists() %} - <th> </th> - - <th>SE</th> - {% endif %} - - {% for attribute in sample_type.attributes|sort() %} - <th> - {{ sample_type.attributes[attribute].name }} - </th> - {% endfor %} - </tr> - - {% for sample in sample_type.sample_list %} - <tr class="{{ sample.class_outlier }} value_se" id="{{ sample.this_id }}"> - <td class="column_name-Index"> - {{ loop.index }} - <input type="checkbox" name="selectCheck" - class="checkbox edit_sample_checkbox" - value="{{ sample.name }}" checked="checked"> - </td> - - <td class="column_name-Sample"> - <span class="edit_sample_sample_name"> - {{ sample.name }} - </span> - </td> - - {# Todo: Add IDs #} - <td class="column_name-Value"> - <input type="text" data-value="{{ sample.display_value }}" name="{{ sample.name }}" - class="trait_value_input edit_sample_value" - value="{{ sample.display_value }}" - size=8 maxlength=8 - > - </td> + <table class="table table-hover table-striped" {# Todo: Enable sorting on table #} + id="samples_{{ sample_type.sample_group_type }}"> + <tr> + <th>Index</th> + <th>Sample</th> + + <th>Value</th> {% if sample_type.se_exists() %} - <td> - ± - </td> - - {# Todo: Add IDs #} - <td class="column_name-SE"> - <input type="text" data-value="{{ sample.display_variance }}" name=""{{ 'V' + sample.name}}" - class="trait_value_input edit_sample_se" - value="{{ sample.display_variance }}" - size=8 maxlength=8 - > - </td> + <th> </th> + + <th>SE</th> {% endif %} - {# Loop through each attribute type and input value #} {% for attribute in sample_type.attributes|sort() %} - <td class="std_cell column_name-{{ sample_type.attributes[attribute].name.replace(' ', '_') }}"> - {{ sample.extra_attributes[sample_type.attributes[attribute].name] }} - </td> + <th> + {{ sample_type.attributes[attribute].name }} + </th> {% endfor %} - </tr> - {% endfor %} - - </table> - </div> + </tr> + + {% for sample in sample_type.sample_list %} + <tr class="{{ sample.class_outlier }} value_se" id="{{ sample.this_id }}"> + <td class="column_name-Index"> + {{ loop.index }} + <input type="checkbox" name="selectCheck" + class="checkbox edit_sample_checkbox" + value="{{ sample.name }}" checked="checked"> + </td> + + <td class="column_name-Sample"> + <span class="edit_sample_sample_name"> + {{ sample.name }} + </span> + </td> + + {# Todo: Add IDs #} + <td class="column_name-Value"> + <input type="text" data-value="{{ sample.display_value }}" name="{{ sample.name }}" + class="trait_value_input edit_sample_value" + value="{{ sample.display_value }}" + size=8 maxlength=8 + > + </td> + + {% if sample_type.se_exists() %} + <td> + ± + </td> + + {# Todo: Add IDs #} + <td class="column_name-SE"> + <input type="text" data-value="{{ sample.display_variance }}" name=""{{ 'V' + sample.name}}" + class="trait_value_input edit_sample_se" + value="{{ sample.display_variance }}" + size=8 maxlength=8 + > + </td> + {% endif %} + + {# Loop through each attribute type and input value #} + {% for attribute in sample_type.attributes|sort() %} + <td class="std_cell column_name-{{ sample_type.attributes[attribute].name.replace(' ', '_') }}"> + {{ sample.extra_attributes[sample_type.attributes[attribute].name] }} + </td> + {% endfor %} + </tr> + {% endfor %} + + </table> </div> {% endfor %} </div> |