aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/correlation/show_corr_results.py74
-rw-r--r--wqflask/wqflask/marker_regression/gemma_mapping.py18
-rw-r--r--wqflask/wqflask/static/dbdoc/TODO.md1
-rw-r--r--wqflask/wqflask/templates/correlation_page.html86
-rw-r--r--wqflask/wqflask/templates/empty_collection.html15
-rw-r--r--wqflask/wqflask/views.py2
6 files changed, 169 insertions, 27 deletions
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py
index 3d1c0d17..9b048346 100644
--- a/wqflask/wqflask/correlation/show_corr_results.py
+++ b/wqflask/wqflask/correlation/show_corr_results.py
@@ -32,6 +32,7 @@ import pp
import math
import collections
import resource
+import json
import scipy
@@ -51,6 +52,7 @@ import utility.webqtlUtil #this is for parallel computing only.
from wqflask.correlation import correlation_functions
from utility.benchmark import Bench
import utility.webqtlUtil
+from wqflask import user_manager
from MySQLdb import escape_string as escape
@@ -248,7 +250,7 @@ class CorrelationResults(object):
else:
self.this_trait_vals.append("None")
num_overlap = len(self.this_trait_vals)
-
+ logger.debug("DOING PARALLEL")
self.do_parallel_correlation(db_filename, num_overlap)
else:
for trait, values in self.target_dataset.trait_data.iteritems():
@@ -335,6 +337,7 @@ class CorrelationResults(object):
#print("self.correlation_results: ", pf(self.correlation_results))
+ self.json_results = generate_corr_json(self.correlation_results, self.this_trait, self.dataset, self.target_dataset)
#XZ, 09/18/2008: get all information about the user selected database.
#target_db_name = fd.corr_dataset
@@ -1195,6 +1198,17 @@ class CorrelationResults(object):
import math
import reaper
+ def cmpOrder2(A,B):
+ try:
+ if A[-1] < B[-1]:
+ return -1
+ elif A[-1] == B[-1]:
+ return 0
+ else:
+ return 1
+ except:
+ return 0
+
def calCorrelation(dbdata,userdata,N):
X = []
Y = []
@@ -1420,3 +1434,61 @@ class CorrelationResults(object):
# for one_result in results:
# for one_traitinfo in one_result:
# allcorrelations.append( one_traitinfo )
+
+def generate_corr_json(corr_results, this_trait, dataset, target_dataset):
+ results_list = []
+ for i, trait in enumerate(corr_results):
+ results_dict = {}
+ results_dict['checkbox'] = "<INPUT TYPE='checkbox' NAME='searchResult' class='checkbox trait_checkbox' style='padding-right: 0px;' VALUE='" + user_manager.data_hmac('{}:{}'.format(trait.name, trait.dataset.name)) + "'>"
+ results_dict['index'] = i + 1
+ results_dict['trait_id'] = "<a href='/show_trait?trait_id="+str(trait.name)+"&dataset="+str(dataset.name)+"'>"+str(trait.name)+"</a>"
+ if target_dataset.type == "ProbeSet":
+ results_dict['symbol'] = trait.symbol
+ results_dict['description'] = trait.description_display
+ results_dict['location'] = trait.location_repr
+ results_dict['mean'] = float(trait.mean)
+ if trait.LRS_score_repr != "N/A":
+ results_dict['lrs_score'] = "%.1f" % float(trait.LRS_score_repr)
+ else:
+ results_dict['lrs_score'] = "N/A"
+ results_dict['lrs_location'] = trait.LRS_location_repr
+ if trait.additive != "":
+ results_dict['additive'] = "%0.3f" % float(trait.additive)
+ else:
+ results_dict['additive'] = "N/A"
+ results_dict['sample_r'] = "<a target='_blank' href='corr_scatter_plot?dataset_1=" + str(dataset.name) + "&dataset_2=" + str(trait.dataset.name) + "&trait_1=" + str(this_trait.name) + "&trait_2=" + str(trait.name) + "'>" + "%0.3f" % float(trait.sample_r) + "</a>"
+ results_dict['num_overlap'] = trait.num_overlap
+ results_dict['sample_p'] = "%0.3e" % float(trait.sample_p)
+ if trait.lit_corr == "" or trait.lit_corr == 0:
+ results_dict['lit_corr'] = "--"
+ else:
+ results_dict['lit_corr'] = "%0.3f" % float(trait.lit_corr)
+ if trait.tissue_corr == "" or trait.tissue_corr == 0:
+ results_dict['tissue_corr'] = "--"
+ else:
+ results_dict['tissue_corr'] = "%0.3f" % float(trait.tissue_corr)
+ elif target_dataset.type == "Publish":
+ results_dict['description'] = trait.description_display
+ results_dict['authors'] = trait.authors
+ if trait.pubmed_id:
+ results_dict['pubmed'] = "<a href='" + trait.pubmed_link + "'> " + trait.pubmed_text + "</a>"
+ else:
+ results_dict['pubmed'] = "N/A"
+ results_dict['lrs_score'] = trait.LRS_score_repr
+ results_dict['lrs_location'] = trait.LRS_location_repr
+ if trait.additive != "":
+ results_dict['additive'] = "%0.3f" % float(trait.additive)
+ else:
+ results_dict['additive'] = "N/A"
+ results_dict['sample_r'] = "<a target='_blank' href='corr_scatter_plot?dataset_1=" + str(dataset.name) + "&dataset_2=" + str(trait.dataset.name) + "&trait_1=" + str(this_trait.name) + "&trait_2=" + str(trait.name) + "'>" + "%0.3f" % trait.sample_r + "</a>"
+ results_dict['num_overlap'] = trait.num_overlap
+ results_dict['sample_p'] = "%0.3e" % float(trait.sample_p)
+ else:
+ results_dict['lrs_location'] = trait.LRS_location_repr
+ results_dict['sample_r'] = "<a target='_blank' href='corr_scatter_plot?dataset_1=" + str(dataset.name) + "&dataset_2=" + str(trait.dataset.name) + "&trait_1=" + str(this_trait.name) + "&trait_2=" + str(trait.name) + "'>" + "%0.3f" % float(trait.sample_r) + "</a>"
+ results_dict['num_overlap'] = trait.num_overlap
+ results_dict['sample_p'] = "%0.3e" % float(trait.sample_p)
+
+ results_list.append(results_dict)
+
+ return json.dumps(results_list)
diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py
index 68920130..233a5c76 100644
--- a/wqflask/wqflask/marker_regression/gemma_mapping.py
+++ b/wqflask/wqflask/marker_regression/gemma_mapping.py
@@ -3,7 +3,7 @@ import os, math, string, random, json
from base import webqtlConfig
from base.trait import GeneralTrait
from base.data_set import create_dataset
-from utility.tools import flat_files, GEMMA_COMMAND, GEMMA_WRAPPER_COMMAND, TEMPDIR, assert_bin, assert_file
+from utility.tools import flat_files, GEMMA_COMMAND, GEMMA_WRAPPER_COMMAND, TEMPDIR
import utility.logger
logger = utility.logger.getLogger(__name__ )
@@ -11,7 +11,6 @@ logger = utility.logger.getLogger(__name__ )
def run_gemma(this_dataset, samples, vals, covariates, method, use_loco):
"""Generates p-values for each marker using GEMMA"""
- assert_bin(GEMMA_COMMAND);
if this_dataset.group.genofile != None:
genofile_name = this_dataset.group.genofile[:-5]
else:
@@ -193,7 +192,7 @@ def parse_gemma_output(genofile_name):
# if marker['chr'] != previous_chr:
# previous_chr = marker['chr']
marker['Mb'] = float(line.split("\t")[2]) / 1000000
- marker['p_value'] = float(line.split("\t")[10])
+ marker['p_value'] = float(line.split("\t")[11])
if math.isnan(marker['p_value']) or (marker['p_value'] <= 0):
marker['lod_score'] = 0
#marker['lrs_value'] = 0
@@ -203,20 +202,15 @@ def parse_gemma_output(genofile_name):
marker_obs.append(marker)
included_markers.append(line.split("\t")[1])
- p_values.append(float(line.split("\t")[10]))
+ p_values.append(float(line.split("\t")[11]))
return marker_obs
def parse_loco_output(this_dataset, gwa_output_filename):
output_filelist = []
- jsonfn = "{}/gn2/".format(TEMPDIR) + gwa_output_filename + ".json"
- assert_file(jsonfn)
- try:
- with open(jsonfn) as data_file:
- data = json.load(data_file)
- except:
- logger.error("Can not parse "+jsonfn)
+ with open("{}/gn2/".format(TEMPDIR) + gwa_output_filename + ".json") as data_file:
+ data = json.load(data_file)
files = data['files']
for file in files:
@@ -253,4 +247,4 @@ def parse_loco_output(this_dataset, gwa_output_filename):
included_markers.append(line.split("\t")[1])
p_values.append(float(line.split("\t")[10]))
- return marker_obs
+ return marker_obs \ No newline at end of file
diff --git a/wqflask/wqflask/static/dbdoc/TODO.md b/wqflask/wqflask/static/dbdoc/TODO.md
new file mode 100644
index 00000000..c0a8bab7
--- /dev/null
+++ b/wqflask/wqflask/static/dbdoc/TODO.md
@@ -0,0 +1 @@
+TODO: Add all database documentation into this folder
diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html
index fa9e3585..1254ea6a 100644
--- a/wqflask/wqflask/templates/correlation_page.html
+++ b/wqflask/wqflask/templates/correlation_page.html
@@ -1,9 +1,10 @@
{% extends "base.html" %}
{% block css %}
+ <link rel="stylesheet" type="text/css" href="/static/new/packages/tabulator/css/tabulator.css" />
+ <!--
<link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" />
- <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" />
- <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" />
<link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" />
+ -->
{% endblock %}
{% block content %}
@@ -63,15 +64,16 @@
</div>
<div style="width: {% if target_dataset.type == "ProbeSet" %}1600px{% elif target_dataset.type == "Publish" %}1400px{% else %}800px{% endif %};">
- <table id="trait_table" class="display dataTable nowrap" style="float: left;">
+ <table id="trait_table" class="display dataTable nowrap" style="font-size: 12px; float: left;">
+<!--
<thead>
<tr>
- <th style="width: 30px;"></th>
+ <th></th>
{% for header in target_dataset.header_fields %}
{% if header == 'Year' %}
<th>{{header}}</th>
{% elif header == 'Max LRS' %}
- <th>Max LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th>
+ <th>Max LRS</th>
{% elif header == 'Max LRS Location' %}
<th>{{header}}</th>
{% elif header == 'Location' %}
@@ -79,7 +81,7 @@
{% elif header == 'Mean' %}
<th>{{header}}</th>
{% elif header == 'Additive Effect' %}
- <th>Additive Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th>
+ <th>Additive Effect</th>
{% elif header == 'Index' %}
<th>{{header}}</th>
{% elif header == 'N' %}
@@ -91,7 +93,7 @@
{% if target_dataset.type == "ProbeSet" %}
{% if corr_method == 'pearson' %}
<th>Sample r</th>
- <th>&nbsp;&nbsp;N</th>
+ <th>N</th>
<th>Sample p(r)</th>
<th>Lit r</th>
<th>Tissue r</th>
@@ -129,8 +131,8 @@
<tbody>
{% for trait in correlation_results %}
<tr>
- <td style="padding-left: 8px; padding-right: 0px; padding-top: 4px; align: center;"><INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" style="padding-right: 0px;" VALUE="{{ data_hmac('{}:{}'.format(trait.name, trait.dataset.name)) }}"></td>
- <td align="right">{{ loop.index }}</td>
+ <td><INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" style="padding-right: 0px;" VALUE="{{ data_hmac('{}:{}'.format(trait.name, trait.dataset.name)) }}"></td>
+ <td style="padding-left: 8px; padding-right: 0px; padding-top: 4px; align: center; display: inline;">{{ loop.index }}</td>
<td>
<a href="{{ url_for('show_trait_page',
trait_id = trait.name,
@@ -183,6 +185,7 @@
</tr>
{% endfor %}
</tbody>
+-->
</table>
</div>
</div>
@@ -191,13 +194,17 @@
{% block js %}
<script type="text/javascript" src="/static/new/javascript/search_results.js"></script>
+ <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script>
+ <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script>
+ <script language="javascript" type="text/javascript" src="/static/new/packages/tabulator/js/tabulator.js"></script>
+ <!--
<script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.js"></script>
<script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script>
<script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script>
<script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script>
- <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script>
<script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script>
- <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script>
+ -->
+
<script type="text/javascript" charset="utf-8">
function getValue(x) {
if (x.indexOf('input') >= 0) {
@@ -213,7 +220,8 @@
}
return parseFloat(x);
}
-
+
+/*
jQuery.fn.dataTableExt.oSort['numeric-html-asc'] = function(a,b) {
a = Math.abs(parseFloat($(a).text()));
b = Math.abs(parseFloat($(b).text()));
@@ -259,10 +267,60 @@
var y = parseFloat(b);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
-
+*/
$(document).ready( function () {
+ var table_json = {{ json_results | safe }}
+
+
+ {% if target_dataset.type == "ProbeSet" %}
+ var json_array = new Array();
+
+ for (i=0; i < table_json.length; i++){
+ json_array.push({
+ checkbox: table_json[i]["checkbox"],
+ index: table_json[i]["index"],
+ trait_id: table_json[i]["trait_id"],
+ symbol: table_json[i]["symbol"],
+ description: table_json[i]["description"],
+ location: table_json[i]["location"],
+ mean: table_json[i]["mean"],
+ lrs_score: table_json[i]["lrs_score"],
+ lrs_location: table_json[i]["lrs_location"],
+ additive: table_json[i]["additive"],
+ sample_r: table_json[i]["sample_r"],
+ num_overlap: table_json[i]["num_overlap"],
+ sample_p: table_json[i]["sample_p"],
+ lit_corr: table_json[i]["lit_corr"],
+ tissue_corr: table_json[i]["tissue_corr"]
+ });
+ console.log("JSON_DATA:", json_array);
+ }
+ //console.log("JSON_DATA:", json_array)
+
+ $("#trait_table").tabulator({
+ data: json_array,
+ columns:[
+ {title:"", field:"checkbox", formatter:"html"},
+ {title:"Index", field:"index", formatter:"plaintext"},
+ {title:"Record", field:"trait_id", formatter:"html"},
+ {title:"Symbol", field:"symbol", formatter:"plaintext"},
+ {title:"Description", field:"description", formatter:"textarea", width:"25%"},
+ {title:"Location", field:"location", formatter:"plaintext"},
+ {title:"Mean", field:"mean", formatter:"plaintext"},
+ {title:"Max LRS", field:"lrs_score", formatter:"plaintext"},
+ {title:"Max LRS Location", field:"lrs_location", formatter:"plaintext"},
+ {title:"Additive Effect", field:"additive", formatter:"plaintext"},
+ {title:"Sample r", field:"sample_r", formatter:"html"},
+ {title:"N", field:"num_overlap", formatter:"plaintext"},
+ {title:"Sample p(r)", field:"sample_p", formatter:"plaintext"},
+ {title:"Lit r", field:"lit_corr", formatter:"plaintext"},
+ {title:"Tissue r", field:"tissue_corr", formatter:"plaintext"}
+ ]
+ });
+ {% endif %}
+
$('#trait_table tr').click(function(event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
@@ -296,6 +354,7 @@
}
}
+ /*
console.time("Creating table");
{% if target_dataset.type == "ProbeSet" %}
@@ -447,6 +506,7 @@
} );
{% endif %}
console.timeEnd("Creating table");
+ */
submit_special = function(url) {
$("#correlation_form").attr("action", url);
diff --git a/wqflask/wqflask/templates/empty_collection.html b/wqflask/wqflask/templates/empty_collection.html
new file mode 100644
index 00000000..d1b779ef
--- /dev/null
+++ b/wqflask/wqflask/templates/empty_collection.html
@@ -0,0 +1,15 @@
+{% extends "base.html" %}
+{% block title %}{{ tool }}{% endblock %}
+{% block content %}
+<!-- Start of body -->
+ {{ header("Error") }}
+
+ <div class="container">
+ <input type="hidden" name="uc_id" id="uc_id" value="{{ uc_id }}">
+ <p>You must select at least two traits to use the {{ tool }}.</p>
+ </div>
+
+
+<!-- End of body -->
+
+{% endblock %}
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 4e81c29c..187b60dc 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -743,7 +743,7 @@ def corr_matrix_page():
start_vars = request.form
traits = [trait.strip() for trait in start_vars['trait_list'].split(',')]
- if traits[0] != "":
+ if len(traits) > 1:
template_vars = show_corr_matrix.CorrelationMatrix(start_vars)
template_vars.js_data = json.dumps(template_vars.js_data,
default=json_default_handler,