aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2016-04-28 18:42:20 +0000
committerzsloan2016-04-28 18:42:20 +0000
commit6e6482db14c3840328d786c551feea6e34a3ef06 (patch)
treecbdb2a39ac63fa097c9b806eb5c31e5694152741 /wqflask
parente2bdde9488c02603caee5b19644135cac23e9daf (diff)
downloadgenenetwork2-6e6482db14c3840328d786c551feea6e34a3ef06.tar.gz
Added option to export permutation results for mapping page
Added data_scale to dataset objects and basic stats table will now check data scale when calculating range Made interval analyst results table work with datatables Changed the appearance of the basic stats table some by giving it a border
Diffstat (limited to 'wqflask')
-rw-r--r--[-rwxr-xr-x]wqflask/base/data_set.py74
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression.py12
-rwxr-xr-xwqflask/wqflask/show_trait/show_trait.py1
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js4
-rw-r--r--wqflask/wqflask/templates/marker_regression_gn1.html31
-rwxr-xr-xwqflask/wqflask/templates/show_trait.html1
-rwxr-xr-xwqflask/wqflask/templates/show_trait_statistics.html2
-rw-r--r--wqflask/wqflask/views.py23
8 files changed, 68 insertions, 80 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index e37a838f..379e5906 100755..100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -509,6 +509,7 @@ class DataSet(object):
self.shortname = None
self.fullname = None
self.type = None
+ self.data_scale = None #ZS: For example log2
self.setup()
@@ -569,8 +570,8 @@ class DataSet(object):
self.name,
self.name))
- self.id, self.name, self.fullname, self.shortname, self.tissue = g.db.execute("""
- SELECT ProbeSetFreeze.Id, ProbeSetFreeze.Name, ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, Tissue.Name
+ self.id, self.name, self.fullname, self.shortname, self.data_scale, self.tissue = g.db.execute("""
+ SELECT ProbeSetFreeze.Id, ProbeSetFreeze.Name, ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, ProbeSetFreeze.DataScale, Tissue.Name
FROM ProbeSetFreeze, ProbeFreeze, Tissue
WHERE ProbeSetFreeze.public > %s AND
ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id AND
@@ -1035,75 +1036,6 @@ class MrnaAssayDataSet(DataSet):
#print("After retrieve_sample_data")
return trait_data
- #def get_trait_data(self):
- # self.samplelist = self.group.samplelist + self.group.parlist + self.group.f1list
- # query = """
- # SELECT Strain.Name, Strain.Id FROM Strain, Species
- # WHERE Strain.Name IN {}
- # and Strain.SpeciesId=Species.Id
- # and Species.name = '{}'
- # """.format(create_in_clause(self.samplelist), *mescape(self.group.species))
- # results = dict(g.db.execute(query).fetchall())
- # sample_ids = [results[item] for item in self.samplelist]
- #
- # # MySQL limits the number of tables that can be used in a join to 61,
- # # so we break the sample ids into smaller chunks
- # # Postgres doesn't have that limit, so we can get rid of this after we transition
- # chunk_size = 50
- # number_chunks = int(math.ceil(len(sample_ids) / chunk_size))
- # trait_sample_data = []
- # for sample_ids_step in chunks.divide_into_chunks(sample_ids, number_chunks):
- #
- # #XZ, 09/24/2008: build one temporary table that only contains the records associated with the input GeneId
- # #tempTable = None
- # #if GeneId and db.type == "ProbeSet":
- # # if method == "3":
- # # tempTable = self.getTempLiteratureTable(species=species,
- # # input_species_geneid=GeneId,
- # # returnNumber=returnNumber)
- # #
- # # if method == "4" or method == "5":
- # # tempTable = self.getTempTissueCorrTable(primaryTraitSymbol=GeneSymbol,
- # # TissueProbeSetFreezeId=tissueProbeSetFreezeId,
- # # method=method,
- # # returnNumber=returnNumber)
- #
- # temp = ['T%s.value' % item for item in sample_ids_step]
- # query = "SELECT {}.Name,".format(escape(self.type))
- # data_start_pos = 1
- # query += string.join(temp, ', ')
- # query += ' FROM ({}, {}XRef, {}Freeze) '.format(*mescape(self.type,
- # self.type,
- # self.type))
- #
- # for item in sample_ids_step:
- # query += """
- # left join {}Data as T{} on T{}.Id = {}XRef.DataId
- # and T{}.StrainId={}\n
- # """.format(*mescape(self.type, item, item, self.type, item, item))
- #
- # query += """
- # WHERE {}XRef.{}FreezeId = {}Freeze.Id
- # and {}Freeze.Name = '{}'
- # and {}.Id = {}XRef.{}Id
- # order by {}.Id
- # """.format(*mescape(self.type, self.type, self.type, self.type,
- # self.name, self.type, self.type, self.type, self.type))
- # results = g.db.execute(query).fetchall()
- # trait_sample_data.append(results)
- #
- # trait_count = len(trait_sample_data[0])
- # self.trait_data = collections.defaultdict(list)
- #
- # # put all of the separate data together into a dictionary where the keys are
- # # trait names and values are lists of sample values
- # for trait_counter in range(trait_count):
- # trait_name = trait_sample_data[0][trait_counter][0]
- # for chunk_counter in range(int(number_chunks)):
- # self.trait_data[trait_name] += (
- # trait_sample_data[chunk_counter][trait_counter][data_start_pos:])
-
-
def get_trait_info(self, trait_list=None, species=''):
# Note: setting trait_list to [] is probably not a great idea.
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py
index fa439b55..c0bfd70b 100644
--- a/wqflask/wqflask/marker_regression/marker_regression.py
+++ b/wqflask/wqflask/marker_regression/marker_regression.py
@@ -79,6 +79,8 @@ class MarkerRegression(object):
self.pair_scan = False # Initializing this since it is checked in views to determine which template to use
self.score_type = "LRS" #ZS: LRS or LOD
self.mapping_scale = "physic"
+ self.num_perm = 0
+ self.perm_output = []
self.bootstrap_results = []
#ZS: This is passed to GN1 code for single chr mapping
@@ -125,13 +127,14 @@ class MarkerRegression(object):
try:
if int(start_vars['num_perm']) > 0:
self.num_perm = int(start_vars['num_perm'])
- else:
- self.num_perm = 0
except:
self.num_perm = 0
self.LRSCheck = self.score_type
- self.permCheck = "ON"
+ if self.num_perm > 0:
+ self.permCheck = "ON"
+ else:
+ self.permCheck = False
self.showSNP = "ON"
self.showGenes = "ON"
self.viewLegend = "ON"
@@ -278,6 +281,8 @@ class MarkerRegression(object):
mapping_scale = self.mapping_scale,
chromosomes = chromosome_mb_lengths,
qtl_results = self.qtl_results,
+ num_perm = self.num_perm,
+ perm_results = self.perm_output,
)
@@ -683,6 +688,7 @@ class MarkerRegression(object):
self.perm_output = genotype.permutation(strains = trimmed_samples, trait = trimmed_values, nperm=self.num_perm)
self.suggestive = self.perm_output[int(self.num_perm*0.37-1)]
self.significant = self.perm_output[int(self.num_perm*0.95-1)]
+ self.highly_significant = self.perm_output[int(self.num_perm*0.99-1)]
self.json_data['suggestive'] = self.suggestive
self.json_data['significant'] = self.significant
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index 2d4c952a..156510bb 100755
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -153,6 +153,7 @@ class ShowTrait(object):
self.trait_table_width = get_trait_table_width(self.sample_groups)
js_data = dict(dataset_type = self.dataset.type,
+ data_scale = self.dataset.data_scale,
sample_group_types = self.sample_group_types,
sample_lists = sample_lists,
attribute_names = self.sample_groups[0].attributes,
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 9d418e9b..9e249c28 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -190,9 +190,9 @@
}
row_line = "<tr>";
if (row.url != null) {
- row_line += "<td id=\"" + row.vn + "\" style=\"border-right: 1px solid #000000;\"><a href=\"" + row.url + "\">" + row.pretty + "</a></td>";
+ row_line += "<td id=\"" + row.vn + "\"><a href=\"" + row.url + "\">" + row.pretty + "</a></td>";
} else {
- row_line += "<td id=\"" + row.vn + "\" style=\"border-right: 1px solid #000000;\">" + row.pretty + "</td>";
+ row_line += "<td id=\"" + row.vn + "\">" + row.pretty + "</td>";
}
_ref1 = js_data.sample_group_types;
for (key in _ref1) {
diff --git a/wqflask/wqflask/templates/marker_regression_gn1.html b/wqflask/wqflask/templates/marker_regression_gn1.html
index 7f269048..d86d981e 100644
--- a/wqflask/wqflask/templates/marker_regression_gn1.html
+++ b/wqflask/wqflask/templates/marker_regression_gn1.html
@@ -22,6 +22,7 @@
<input type="hidden" name="selected_chr" value="{{ selectedChr }}">
<input type="hidden" name="manhattan_plot" value="{{ manhattan_plot }}">
<input type="hidden" name="num_perm" value="{{ nperm }}">
+ <input type="hidden" name="perm_results" value="">
<input type="hidden" name="num_bootstrap" value="{{ nboot }}">
<input type="hidden" name="do_control" value="{{ doControl }}">
<input type="hidden" name="control_marker" value="{{ controlLocus }}">
@@ -148,9 +149,12 @@
<br>
<span style="white-space: nowrap;">A positive additive coefficient (green line) indicates that {{ dataset.group.parlist[1] }} alleles increase trait values. In contrast, a negative additive coefficient (orange line) indicates that {{ dataset.group.parlist[0] }} alleles increase trait values.</span>
{% endif %}
- {% if nperm > 0 %}
+ {% if nperm > 0 and permChecked == "ON" %}
<br><br>
<img src="/static/output/{{ perm_filename }}.gif">
+ <br><br>
+ Total of {{ nperm }} permutations&nbsp;&nbsp;<a href="javascript:export_perm_data();" target="_blank" >Download Permutation Results</a>
+ <br>
{% endif %}
</div>
</div>
@@ -292,7 +296,20 @@
"scrollCollapse": true,
"paging": false
} );
- console.timeEnd("Creating table");
+
+ $('#interval_analyst').dataTable( {
+ "columnDefs": [ {
+ "targets": 0,
+ "sortable": false
+ }],
+ "order": [[3, "asc"]],
+ "sDom": "RZtir",
+ "iDisplayLength": -1,
+ "autoWidth": true,
+ "bDeferRender": true,
+ "bSortClasses": false,
+ "paging": false
+ } );
$('#vector_map_tab').click(function(){
$('div#gn1_map_options').hide();
@@ -325,6 +342,16 @@
return $('#marker_regression_form').submit();
};
+ export_perm_data = function() {
+ var num_perm, perm_data;
+ num_perm = js_data.num_perm
+ perm_data = js_data.perm_results
+ json_perm_data = JSON.stringify(perm_data);
+ $('input[name=perm_results]').val(json_perm_data);
+ $('#marker_regression_form').attr('action', '/export_perm_data');
+ return $('#marker_regression_form').submit();
+ };
+
</script>
{% endblock %}
diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html
index 7429cd5f..64638fc7 100755
--- a/wqflask/wqflask/templates/show_trait.html
+++ b/wqflask/wqflask/templates/show_trait.html
@@ -254,7 +254,6 @@
} );
{% endif %}
- console.log("SAMPLE GROUP TYPES:", js_data.sample_group_types)
if (Object.keys(js_data.sample_group_types).length > 1) {
$('#stats_table').DataTable( {
"columnDefs": [
diff --git a/wqflask/wqflask/templates/show_trait_statistics.html b/wqflask/wqflask/templates/show_trait_statistics.html
index 9a57b285..242f1c26 100755
--- a/wqflask/wqflask/templates/show_trait_statistics.html
+++ b/wqflask/wqflask/templates/show_trait_statistics.html
@@ -26,7 +26,7 @@
<div class="tab-content">
<div class="tab-pane active" id="stats_tab">
<div style="padding: 20px" class="form-horizontal">
- <table id="stats_table" style="width: 300px; float: left;" class="table table-hover table-striped cell-border"></table>
+ <table border="1" id="stats_table" style="width: 300px; float: left;" class="table table-hover table-striped cell-border"></table>
</div>
</div>
<div class="tab-pane" id="histogram_tab">
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 3bf64a18..3cdb9339 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -265,6 +265,29 @@ def export_trait_csv():
return Response(csv_data,
mimetype='text/csv',
headers={"Content-Disposition":"attachment;filename=sample_data.csv"})
+
+@app.route('/export_perm_data', methods=('POST',))
+def export_perm_data():
+ """CSV file consisting of the permutation data for the mapping results"""
+ num_perm = float(request.form['num_perm'])
+ perm_data = json.loads(request.form['perm_results'])
+
+ buff = StringIO.StringIO()
+ writer = csv.writer(buff)
+ writer.writerow(["Suggestive LRS (p=0.63) = " + str(perm_data[int(num_perm*0.37-1)])])
+ writer.writerow(["Significant LRS (p=0.05) = " + str(perm_data[int(num_perm*0.95-1)])])
+ writer.writerow(["Highly Significant LRS (p=0.01) = " + str(perm_data[int(num_perm*0.99-1)])])
+ writer.writerow("")
+ writer.writerow([str(num_perm) + " Permutations"])
+ writer.writerow("")
+ for item in perm_data:
+ writer.writerow([item])
+ csv_data = buff.getvalue()
+ buff.close()
+
+ return Response(csv_data,
+ mimetype='text/csv',
+ headers={"Content-Disposition":"attachment;filename=perm_data.csv"})
@app.route("/show_trait")
def show_trait_page():