aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Sloan2012-10-17 17:05:51 -0500
committerZachary Sloan2012-10-17 17:05:51 -0500
commit79105a574b68c837ca3ab0343250da3da600a544 (patch)
tree4c8002bf899df9a70b0fc13d935867d6b43de8f5
parentdc191dfac1c198610e3991c66516643a158a5d31 (diff)
downloadgenenetwork2-79105a574b68c837ca3ab0343250da3da600a544.tar.gz
Fixed bug in an SQL query, changed search field id from "ORkeyword" to "search_terms"
-rw-r--r--wqflask/wqflask/parser.py15
-rw-r--r--wqflask/wqflask/search_results.py33
-rw-r--r--wqflask/wqflask/show_trait/export_trait_data.py12
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.coffee24
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js9
-rw-r--r--wqflask/wqflask/templates/index_page.html2
-rw-r--r--wqflask/wqflask/templates/new_index_page.html2
-rw-r--r--wqflask/wqflask/templates/show_trait.html25
-rw-r--r--wqflask/wqflask/views.py31
9 files changed, 87 insertions, 66 deletions
diff --git a/wqflask/wqflask/parser.py b/wqflask/wqflask/parser.py
index 67325b56..e34992a0 100644
--- a/wqflask/wqflask/parser.py
+++ b/wqflask/wqflask/parser.py
@@ -36,10 +36,11 @@ def parse(pstring):
print(pf(items))
return(items)
-parse("foo=(3 2 1)")
-parse("shh")
-parse("shh grep")
-parse("LRS=(9 99 Chr4 122 155) cisLRS=(9 999 10)")
-parse("sal1 LRS=(9 99 Chr4 122 155) sal2 cisLRS=(9 999 10)")
-parse("sal1 sal3 LRS=(9 99 Chr4 122 155) wiki=bar sal2 go:foobar cisLRS=(9 999 10)")
-parse("sal1 LRS=(9 99 Chr4 122 155) wiki=bar sal2 go:foobar cisLRS=(9, 999, 10)") \ No newline at end of file
+if __name__ == '__main__':
+ parse("foo=(3 2 1)")
+ parse("shh")
+ parse("shh grep")
+ parse("LRS=(9 99 Chr4 122 155) cisLRS=(9 999 10)")
+ parse("sal1 LRS=(9 99 Chr4 122 155) sal2 cisLRS=(9 999 10)")
+ parse("sal1 sal3 LRS=(9 99 Chr4 122 155) wiki=bar sal2 go:foobar cisLRS=(9 999 10)")
+ parse("sal1 LRS=(9 99 Chr4 122 155) wiki=bar sal2 go:foobar cisLRS=(9, 999, 10)") \ No newline at end of file
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index 4cca6492..585deb8f 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -60,6 +60,7 @@ class SearchResultPage(templatePage):
nkeywords = 0
def __init__(self, fd):
+ self.fd = fd
if not self.openMysql():
return
@@ -98,9 +99,15 @@ class SearchResultPage(templatePage):
#userExist = None
for individualDB in self.database:
- self.cursor.execute('''SELECT Id, Name, FullName, confidentiality,
- AuthorisedUsers FROM %sFreeze WHERE Name = %s''', (
- self.database[0].type, individualDB))
+ # Can't use paramater substitution for table names apparently
+ db_type = self.database[0].type + "Freeze"
+ print("db_type [%s]: %s" % (type(db_type), db_type))
+
+ query = '''SELECT Id, Name, FullName, confidentiality,
+ AuthorisedUsers FROM %s WHERE Name = %%s''' % (db_type)
+
+ self.cursor.execute(query, (individualDB,))
+
(indId,
indName,
indFullName,
@@ -175,6 +182,8 @@ class SearchResultPage(templatePage):
'RefSeq_TranscriptId']
elif self.dbType == "Geno":
self.searchField = ['Name','Chr']
+
+ self.do_search()
###########################################
# Search Options
@@ -545,7 +554,6 @@ class SearchResultPage(templatePage):
_log.info("Done executing queries")
-
#searchCountQuery retrieve all the results, for counting use only
if searchCountQuery != searchQuery:
for item in searchQuery:
@@ -558,7 +566,6 @@ class SearchResultPage(templatePage):
return nresults
-
def assembleQuery(self):
self.query = []
if self.ANDQuery or self.ORQuery:
@@ -635,13 +642,15 @@ class SearchResultPage(templatePage):
return 0
+ def do_search(self):
+ print("fd.search_terms:", self.fd['search_terms'])
+ self.search_terms = parser.parse(self.fd['search_terms'])
+ print("After parsing:", self.search_terms)
+ #print("ORkeyword is:", pf(self.ORkeyword))
+ #self.ANDkeyword2 = parser.parse(self.ANDkeyword)
+ #self.ORkeyword2 = parser.parse(self.ORkeyword)
+ #print("ORkeyword2 is:", pf(parser.parse(self.ORkeyword)))
- def normalSearch(self):
- print("ORkeyword is:", pf(self.ORkeyword))
- self.ANDkeyword2 = parser.parse(self.ANDkeyword)
- self.ORkeyword2 = parser.parse(self.ORkeyword)
- print("ORkeyword2 is:", pf(parser.parse(self.ORkeyword)))
-
#self.ANDkeyword2 = re.sub(self._1mPattern, '', self.ANDkeyword)
#self.ANDkeyword2 = re.sub(self._2mPattern, '', self.ANDkeyword2)
#self.ANDkeyword2 = re.sub(self._3mPattern, '', self.ANDkeyword2)
@@ -649,7 +658,7 @@ class SearchResultPage(templatePage):
###remove remain parethesis, could be input with syntax error
#self.ANDkeyword2 = re.sub(re.compile('\s*\([\s\S]*\)'), '', self.ANDkeyword2)
#self.ANDkeyword2 = self.encregexp(self.ANDkeyword2)
- #
+
#self.ORkeyword2 = re.sub(self._1mPattern, '', self.ORkeyword)
#self.ORkeyword2 = re.sub(self._2mPattern, '', self.ORkeyword2)
#self.ORkeyword2 = re.sub(self._3mPattern, '', self.ORkeyword2)
diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py
index e5f2035d..f7f2d6d4 100644
--- a/wqflask/wqflask/show_trait/export_trait_data.py
+++ b/wqflask/wqflask/show_trait/export_trait_data.py
@@ -4,21 +4,13 @@ import operator
import simplejson as json
-#import xlwt
from pprint import pformat as pf
def export_sample_table(targs):
- #print("* keys0 args is:", targs[0].keys())
-
-
- #test_export_file = open("/home/zas1024/gene/wqflask/wqflask/show_trait/export_test.txt", "w")
- #
- #for key, item in targs.iteritems():
- # print("[arrow] key is:", key)
-
+
sample_data = json.loads(targs['export_data'])
final_sample_data = []
-
+
for sample_group in ['primary_samples', 'other_samples']:
for row in sample_data[sample_group]:
sorted_row = dict_to_sorted_list(row)
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.coffee b/wqflask/wqflask/static/new/javascript/show_trait.coffee
index c7dc7c88..b1cca461 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.coffee
+++ b/wqflask/wqflask/static/new/javascript/show_trait.coffee
@@ -295,6 +295,10 @@ $ ->
samples.other_samples = other_samples
return samples
+ ##End Get Sample Data from Table Code
+
+ ##Export Sample Table Data Code
+
export_sample_table_data = ->
sample_data = get_sample_table_data()
console.log("sample_data is:", sample_data)
@@ -302,27 +306,19 @@ $ ->
console.log("json_sample_data is:", json_sample_data)
$('input[name=export_data]').val(json_sample_data)
-
console.log("export_data is", $('input[name=export_data]').val())
- $('#trait_data_form').attr('action', '/export_trait_csv')
+ format = $('#export_format').val()
+ if format == "excel"
+ $('#trait_data_form').attr('action', '/export_trait_excel')
+ else
+ $('#trait_data_form').attr('action', '/export_trait_csv')
console.log("action is:", $('#trait_data_form').attr('action'))
+
$('#trait_data_form').submit()
-
- #$.ajax(
- # url: '/export_trait_csv'
- # type: 'POST'
- # data: "json_data=" + json_sample_data
- #)
$('#export').click(export_sample_table_data)
-
-
- ##End Get Sample Data from Table Code
-
- ##Export Sample Table Data Code
-
##End Export Sample Table Data Code
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 5729eb22..5aadedef 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -334,14 +334,19 @@
return samples;
};
export_sample_table_data = function() {
- var json_sample_data, sample_data;
+ var format, json_sample_data, sample_data;
sample_data = get_sample_table_data();
console.log("sample_data is:", sample_data);
json_sample_data = JSON.stringify(sample_data);
console.log("json_sample_data is:", json_sample_data);
$('input[name=export_data]').val(json_sample_data);
console.log("export_data is", $('input[name=export_data]').val());
- $('#trait_data_form').attr('action', '/export_trait_csv');
+ format = $('#export_format').val();
+ if (format === "excel") {
+ $('#trait_data_form').attr('action', '/export_trait_excel');
+ } else {
+ $('#trait_data_form').attr('action', '/export_trait_csv');
+ }
console.log("action is:", $('#trait_data_form').attr('action'));
return $('#trait_data_form').submit();
};
diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html
index a209f302..db0b2d9e 100644
--- a/wqflask/wqflask/templates/index_page.html
+++ b/wqflask/wqflask/templates/index_page.html
@@ -96,7 +96,7 @@
<td width="3%"></td>
<td nowrap width="85%" align="left"><input class="input-medium search-query"
- id="tfor" name="ORkeyword" style=
+ id="tfor" name="search_terms" style=
"width:420px; background-color:white; font-family:verdana; font-size:14px"
type="text" maxlength="500"></td>
</tr><!-- GET ANY HELP -->
diff --git a/wqflask/wqflask/templates/new_index_page.html b/wqflask/wqflask/templates/new_index_page.html
index 3d6d3f3f..f2178f3c 100644
--- a/wqflask/wqflask/templates/new_index_page.html
+++ b/wqflask/wqflask/templates/new_index_page.html
@@ -125,7 +125,7 @@
<label for="tfor">Search:</label>
<input class="search-query"
- id="tfor" name="ORkeyword"
+ id="tfor" name="search_terms"
type="text" maxlength="500">
<!-- GET ANY HELP -->
diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html
index 1e1d8b8f..d48f9487 100644
--- a/wqflask/wqflask/templates/show_trait.html
+++ b/wqflask/wqflask/templates/show_trait.html
@@ -1253,10 +1253,18 @@
</div>
{% endif %}
<br>
- <input type="button" id="hide_no_value" class="btn" value="Hide No Value">
- <input type="button" id="block_outliers" class="btn" value="Block Outliers">
- <input type="button" id="reset" class="btn btn-inverse" value="Reset">
- <input type="button" id="export" class="btn" value="Export">
+ <div>
+ <input type="button" id="hide_no_value" class="btn" value="Hide No Value">
+ <input type="button" id="block_outliers" class="btn" value="Block Outliers">
+ <input type="button" id="reset" class="btn btn-inverse" value="Reset">
+ <span class="input-append">
+ <input type="button" id="export" class="btn" value="Export">
+ <select id="export_format" class="select optional span2">
+ <option value="excel">Excel</option>
+ <option value="csv">CSV</option>
+ </select>
+ </span>
+ </div>
</fieldset>
<br>
<div>
@@ -1272,17 +1280,16 @@
</div>
</div>
<br>
-
-
-
-
+
+
+
<div style="width:80%;margin:0;padding:0;border:none;">
{% for sample_type in sample_groups %}
<div style="float:left;width:50%;">
<h2>{{ sample_type.header }}</h2>
<div id="{{ sample_type.sample_group_type }}">
- <table class="not_tablesorter" {# Todo: Turn tablesorter back on #}
+ <table class="table table-hover not_tablesorter" {# Todo: Turn tablesorter back on #}
id="{{ 'sortable%i' % (loop.index) }}"
cellpadding="0" cellspacing="0">
<tr>
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 693b863a..2933b428 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -90,6 +90,25 @@ def show_trait_page():
print("show_trait template_vars:", pf(template_vars.__dict__))
return render_template("show_trait.html", **template_vars.__dict__)
+@app.route('/export_trait_csv', methods=('POST',))
+def export_trait_excel():
+ """Excel file consisting of the sample data from the trait data and analysis page"""
+ print("In export_trait_excel")
+ print("request.form:", request.form)
+ sample_data = export_trait_data.export_sample_table(request.form)
+
+ print("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data)))
+
+ buff = StringIO.StringIO()
+ writer = csv.writer(buff)
+ for row in sample_data:
+ writer.writerow(row)
+ csv_data = buff.getvalue()
+ buff.close()
+
+ return Response(csv_data,
+ mimetype='text/csv',
+ headers={"Content-Disposition":"attachment;filename=test.csv"})
@app.route('/export_trait_csv', methods=('POST',))
def export_trait_csv():
@@ -97,7 +116,7 @@ def export_trait_csv():
print("In export_trait_csv")
print("request.form:", request.form)
sample_data = export_trait_data.export_sample_table(request.form)
-
+
print("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data)))
buff = StringIO.StringIO()
@@ -106,20 +125,12 @@ def export_trait_csv():
writer.writerow(row)
csv_data = buff.getvalue()
buff.close()
-
+
return Response(csv_data,
mimetype='text/csv',
headers={"Content-Disposition":"attachment;filename=test.csv"})
-#@app.route("/export_trait_data", methods=('POST',))
-#def export_sample_table():
-# """CSV file consisting of the sample data from the trait data and analysis page"""
-# print("In export_sample_table")
-# print("request.form:", request.form)
-# template_vars = export_trait_data.export_sample_table(request.form)
-
-
@app.route("/corr_compute", methods=('POST',))
def corr_compute_page():
#print("In corr_compute, request.args is:", pf(request.form))