aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2017-11-22 22:41:46 +0000
committerzsloan2017-11-22 22:41:46 +0000
commit2e0302677db8abc50fea79d164e5f6933342d8c6 (patch)
treee8f4237e9ff3a93aa9db65823a98720289dce2ad
parentf27d2609fa8514d01a91500bf010894f746abeac (diff)
downloadgenenetwork2-2e0302677db8abc50fea79d164e5f6933342d8c6.tar.gz
Added option to export csv of full mapping results
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression.py36
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression_gn1.py1
-rw-r--r--wqflask/wqflask/templates/marker_regression_gn1.html9
-rw-r--r--wqflask/wqflask/views.py13
4 files changed, 59 insertions, 0 deletions
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py
index 9f2f06f3..9e01be3e 100644
--- a/wqflask/wqflask/marker_regression/marker_regression.py
+++ b/wqflask/wqflask/marker_regression/marker_regression.py
@@ -7,6 +7,7 @@ from pprint import pformat as pf
import string
import math
+import random
import sys
import datetime
import os
@@ -30,6 +31,7 @@ from flask import Flask, g
from base.trait import GeneralTrait
from base import data_set
from base import species
+from base import webqtlConfig
from utility import webqtlUtil
from utility import helper_functions
from utility import Plot, Bunch
@@ -78,6 +80,12 @@ class MarkerRegression(object):
self.vals.append(value)
self.mapping_method = start_vars['method']
+ if "results_path" in start_vars:
+ self.mapping_results_path = start_vars['results_path']
+ else:
+ mapping_results_filename = self.dataset.group.name + "_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
+ self.mapping_results_path = "{}{}.csv".format(webqtlConfig.GENERATED_IMAGE_DIR, mapping_results_filename)
+
if start_vars['manhattan_plot'] == "True":
self.manhattan_plot = True
else:
@@ -269,6 +277,8 @@ class MarkerRegression(object):
if ('lod_score' in marker.keys()) or ('lrs_value' in marker.keys()):
self.qtl_results.append(marker)
+ export_mapping_results(self.qtl_results, self.mapping_results_path, self.mapping_scale, self.score_type)
+
self.trimmed_markers = trim_markers_for_table(results)
if self.mapping_method != "gemma":
@@ -598,6 +608,32 @@ def create_snp_iterator_file(group):
with gzip.open(snp_file_base, "wb") as fh:
pickle.dump(data, fh, pickle.HIGHEST_PROTOCOL)
+def export_mapping_results(markers, results_path, mapping_scale, score_type):
+ with open(results_path, "w+") as output_file:
+ output_file.write("Name\tChr\t")
+ if mapping_scale == "physic":
+ output_file.write("Mb\t" + score_type)
+ else:
+ output_file.write("Cm\t" + score_type)
+ if "additive" in markers[0].keys():
+ output_file.write("\tAdditive")
+ if "dominance" in markers[0].keys():
+ output_file.write("\tDominance")
+ output_file.write("\n")
+ for i, marker in enumerate(markers):
+ logger.debug("THE MARKER:", marker)
+ output_file.write(marker['name'] + "\t" + str(marker['chr']) + "\t" + str(marker['Mb']) + "\t")
+ if "lod_score" in marker.keys():
+ output_file.write(str(marker['lod_score']))
+ else:
+ output_file.write(str(marker['lrs_value']))
+ if "additive" in marker.keys():
+ output_file.write("\t" + str(marker['additive']))
+ if "dominance" in marker.keys():
+ output_file.write("\t" + str(marker['dominance']))
+ if i < (len(markers) - 1):
+ output_file.write("\n")
+
def trim_markers_for_table(markers):
num_markers = len(markers)
diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py
index a26d1426..ff1fb492 100644
--- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py
+++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py
@@ -178,6 +178,7 @@ class MarkerRegression(object):
self.samples = start_vars['samples']
self.vals = start_vars['vals']
self.mapping_method = start_vars['mapping_method']
+ self.mapping_results_path = start_vars['mapping_results_path']
if self.mapping_method == "rqtl_geno":
self.mapmethod_rqtl_geno = start_vars['method']
self.mapmodel_rqtl_geno = start_vars['model']
diff --git a/wqflask/wqflask/templates/marker_regression_gn1.html b/wqflask/wqflask/templates/marker_regression_gn1.html
index 5c457275..d13c68cd 100644
--- a/wqflask/wqflask/templates/marker_regression_gn1.html
+++ b/wqflask/wqflask/templates/marker_regression_gn1.html
@@ -15,6 +15,7 @@
<input type="hidden" name="trait_id" value="{{ this_trait.name }}">
<input type="hidden" name="dataset" value="{{ dataset.name }}">
<input type="hidden" name="genofile" value="{{ genofile_string }}">
+ <input type="hidden" name="results_path" value="{{ mapping_results_path }}">
<input type="hidden" name="method" value="{{ mapping_method }}">
{% for sample in samples %}
<input type="hidden" name="value:{{ sample }}" value="{{ vals[loop.index - 1] }}">
@@ -46,6 +47,9 @@
{% if genofile_string is defined %}
<b>Genotypes:</b> {{ genofile_string.split(":")[1] }}
{% endif %}
+ <br>
+ <br>
+ <a href="javascript:export_mapping_results();" target="_blank" >Download Full Results</a>
</div>
<div id="gn1_map_options" class="col-xs-5" style="outline: 3px double #AAAAAA; padding: 10px; margin: 10px;">
<div class="col-xs-8" style="padding: 0px;">
@@ -407,6 +411,11 @@
}
{% endif %}
+ export_mapping_results = function() {
+ $('#marker_regression_form').attr('action', '/export_mapping_results');
+ return $('#marker_regression_form').submit();
+ }
+
</script>
{% endblock %}
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 174bf1e4..40806450 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -557,6 +557,7 @@ def marker_regression_page():
'trait_id',
'dataset',
'method',
+ 'mapping_results_path',
'trimmed_markers',
'selected_chr',
'chromosomes',
@@ -672,6 +673,18 @@ def marker_regression_page():
return rendered_template
+@app.route("/export_mapping_results", methods = ('POST',))
+def export_mapping_results():
+ logger.info("request.form:", request.form)
+ logger.error(request.url)
+ file_path = request.form.get("results_path")
+ results_csv = open(file_path, "r").read()
+ response = Response(results_csv,
+ mimetype='text/csv',
+ headers={"Content-Disposition":"attachment;filename=mapping_results.csv"})
+
+ return response
+
@app.route("/export", methods = ('POST',))
def export():