From b59be258dc6e61a9d170d95049d1ae5002ff754d Mon Sep 17 00:00:00 2001 From: zsloan Date: Mon, 26 Aug 2019 13:49:01 -0500 Subject: Output filenames are now passed around when when zooming with the new qtlreaper, so zooming into chromosomes and ranges should be faster Updated genome browser and fixed an issue where it created multiple copies when the tab was clicked repeatedly Added option to filter correlation page results by R and mean expression --- .../marker_regression/display_mapping_results.py | 4 +- wqflask/wqflask/marker_regression/gemma_mapping.py | 4 +- .../wqflask/marker_regression/qtlreaper_mapping.py | 77 +- wqflask/wqflask/marker_regression/run_mapping.py | 21 +- .../static/new/javascript/init_genome_browser.js | 4 +- .../css/purescript-genetics-browser.css | 1 - .../js/purescript-genetics-browser.js | 63425 +------------------ wqflask/wqflask/templates/correlation_page.html | 113 +- wqflask/wqflask/templates/mapping_results.html | 6 +- wqflask/wqflask/views.py | 2 +- 10 files changed, 696 insertions(+), 62961 deletions(-) delete mode 100644 wqflask/wqflask/static/packages/purescript_genome_browser/css/purescript-genetics-browser.css diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index b1e9dad4..1d5843d4 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -232,10 +232,12 @@ class DisplayMappingResults(object): if 'use_loco' in start_vars.keys() and self.mapping_method == "gemma": self.use_loco = start_vars['use_loco'] if self.use_loco == "True": - self.gwa_filename = start_vars['gwa_filename'] + self.output_files = start_vars['output_files'] if 'reaper_version' in start_vars.keys() and self.mapping_method == "reaper": self.reaper_version = start_vars['reaper_version'] + if 'output_files' in start_vars: + self.output_files = ",".join(start_vars['output_files']) self.selectedChr = int(start_vars['selected_chr']) diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py index 1d9bbb43..8d59a392 100644 --- a/wqflask/wqflask/marker_regression/gemma_mapping.py +++ b/wqflask/wqflask/marker_regression/gemma_mapping.py @@ -12,7 +12,7 @@ GEMMAOPTS = "-debug" if WEBSERVER_MODE == 'PROD': GEMMAOPTS = "-no-check" -def run_gemma(this_trait, this_dataset, samples, vals, covariates, use_loco, maf=0.01, first_run=True, gwa_output_filename=None): +def run_gemma(this_trait, this_dataset, samples, vals, covariates, use_loco, maf=0.01, first_run=True, output_files=None): """Generates p-values for each marker using GEMMA""" if this_dataset.group.genofile != None: @@ -101,6 +101,8 @@ def run_gemma(this_trait, this_dataset, samples, vals, covariates, use_loco, maf logger.debug("gemma_command:" + gemma_command) os.system(gemma_command) + else: + gwa_output_filename = output_files if use_loco == "True": marker_obs = parse_loco_output(this_dataset, gwa_output_filename) diff --git a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py index 809d0ce4..bbc8b513 100644 --- a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py +++ b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py @@ -8,45 +8,48 @@ from utility.tools import flat_files, REAPER_COMMAND, TEMPDIR import utility.logger logger = utility.logger.getLogger(__name__ ) -def run_reaper(this_trait, this_dataset, samples, vals, json_data, num_perm, boot_check, num_bootstrap, do_control, control_marker, manhattan_plot): +def run_reaper(this_trait, this_dataset, samples, vals, json_data, num_perm, boot_check, num_bootstrap, do_control, control_marker, manhattan_plot, first_run=True, output_files=None): """Generates p-values for each marker using qtlreaper""" - if this_dataset.group.genofile != None: - genofile_name = this_dataset.group.genofile[:-5] + if first_run: + if this_dataset.group.genofile != None: + genofile_name = this_dataset.group.genofile[:-5] + else: + genofile_name = this_dataset.group.name + + trait_filename = str(this_trait.name) + "_" + str(this_dataset.name) + "_pheno" + gen_pheno_txt_file(this_dataset, genofile_name, samples, vals, trait_filename) + + output_filename = this_dataset.group.name + "_GWA_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + bootstrap_filename = None + permu_filename = None + + opt_list = [] + if boot_check and num_bootstrap > 0: + bootstrap_filename = this_dataset.group.name + "_BOOTSTRAP_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + + opt_list.append("-b") + opt_list.append("--n_bootstrap " + str(num_bootstrap)) + opt_list.append("--bootstrap_output " + webqtlConfig.GENERATED_IMAGE_DIR + bootstrap_filename + ".txt") + if num_perm > 0: + permu_filename = this_dataset.group.name + "_PERM_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + opt_list.append("-n " + str(num_perm)) + opt_list.append("--permu_output " + webqtlConfig.GENERATED_IMAGE_DIR + permu_filename + ".txt") + if control_marker != "" and do_control == "true": + opt_list.append("-c " + control_marker) + + reaper_command = REAPER_COMMAND + ' --geno {0}/{1}.geno --traits {2}/gn2/{3}.txt {4} -o {5}{6}.txt'.format(flat_files('genotype'), + genofile_name, + TEMPDIR, + trait_filename, + " ".join(opt_list), + webqtlConfig.GENERATED_IMAGE_DIR, + output_filename) + + logger.debug("reaper_command:" + reaper_command) + os.system(reaper_command) else: - genofile_name = this_dataset.group.name - - trait_filename = str(this_trait.name) + "_" + str(this_dataset.name) + "_pheno" - gen_pheno_txt_file(this_dataset, genofile_name, samples, vals, trait_filename) - - output_filename = this_dataset.group.name + "_GWA_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) - bootstrap_filename = None - permu_filename = None - - opt_list = [] - if boot_check and num_bootstrap > 0: - bootstrap_filename = this_dataset.group.name + "_BOOTSTRAP_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) - - opt_list.append("-b") - opt_list.append("--n_bootstrap " + str(num_bootstrap)) - opt_list.append("--bootstrap_output " + webqtlConfig.GENERATED_IMAGE_DIR + bootstrap_filename + ".txt") - if num_perm > 0: - permu_filename = this_dataset.group.name + "_PERM_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) - opt_list.append("-n " + str(num_perm)) - opt_list.append("--permu_output " + webqtlConfig.GENERATED_IMAGE_DIR + permu_filename + ".txt") - if control_marker != "" and do_control == "true": - opt_list.append("-c " + control_marker) - - reaper_command = REAPER_COMMAND + ' --geno {0}/{1}.geno --traits {2}/gn2/{3}.txt {4} -o {5}{6}.txt'.format(flat_files('genotype'), - genofile_name, - TEMPDIR, - trait_filename, - " ".join(opt_list), - webqtlConfig.GENERATED_IMAGE_DIR, - output_filename) - - logger.debug("reaper_command:" + reaper_command) - os.system(reaper_command) + output_filename, permu_filename, bootstrap_filename = output_files marker_obs, permu_vals, bootstrap_vals = parse_reaper_output(output_filename, permu_filename, bootstrap_filename) @@ -56,7 +59,7 @@ def run_reaper(this_trait, this_dataset, samples, vals, json_data, num_perm, boo suggestive = permu_vals[int(num_perm*0.37-1)] significant = permu_vals[int(num_perm*0.95-1)] - return marker_obs, permu_vals, suggestive, significant, bootstrap_vals + return marker_obs, permu_vals, suggestive, significant, bootstrap_vals, [output_filename, permu_filename, bootstrap_filename] def gen_pheno_txt_file(this_dataset, genofile_name, samples, vals, trait_filename): """Generates phenotype file for GEMMA""" diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py index 1c08d653..bf90c979 100644 --- a/wqflask/wqflask/marker_regression/run_mapping.py +++ b/wqflask/wqflask/marker_regression/run_mapping.py @@ -181,16 +181,16 @@ class RunMapping(object): self.dataset.group.get_markers() if self.mapping_method == "gemma": self.first_run = True - self.gwa_filename = None + self.output_files= None if 'first_run' in start_vars: #ZS: check if first run so existing result files can be used if it isn't (for example zooming on a chromosome, etc) self.first_run = False - if 'gwa_filename' in start_vars: - self.gwa_filename = start_vars['gwa_filename'] + if 'output_files' in start_vars: + self.output_files = start_vars['output_files'] self.score_type = "-log(p)" self.manhattan_plot = True with Bench("Running GEMMA"): if self.use_loco == "True": - marker_obs, self.gwa_filename = gemma_mapping.run_gemma(self.this_trait, self.dataset, self.samples, self.vals, self.covariates, self.use_loco, self.maf, self.first_run, self.gwa_filename) + marker_obs, self.output_files = gemma_mapping.run_gemma(self.this_trait, self.dataset, self.samples, self.vals, self.covariates, self.use_loco, self.maf, self.first_run, self.output_files) else: marker_obs = gemma_mapping.run_gemma(self.this_trait, self.dataset, self.samples, self.vals, self.covariates, self.use_loco, self.maf, self.first_run) results = marker_obs @@ -244,7 +244,14 @@ class RunMapping(object): logger.info("Running qtlreaper") if self.reaper_version == "new": - results, self.perm_output, self.suggestive, self.significant, self.bootstrap_results = qtlreaper_mapping.run_reaper(self.this_trait, + self.first_run = True + self.output_files = None + if 'first_run' in start_vars: #ZS: check if first run so existing result files can be used if it isn't (for example zooming on a chromosome, etc) + self.first_run = False + if 'output_files' in start_vars: + self.output_files = start_vars['output_files'].split(",") + + results, self.perm_output, self.suggestive, self.significant, self.bootstrap_results, self.output_files = qtlreaper_mapping.run_reaper(self.this_trait, self.dataset, self.samples, self.vals, @@ -254,7 +261,9 @@ class RunMapping(object): self.num_bootstrap, self.do_control, self.control_marker, - self.manhattan_plot) + self.manhattan_plot, + self.first_run, + self.output_files) else: results, self.json_data, self.perm_output, self.suggestive, self.significant, self.bootstrap_results = qtlreaper_mapping.run_original_reaper(self.this_trait, self.dataset, diff --git a/wqflask/wqflask/static/new/javascript/init_genome_browser.js b/wqflask/wqflask/static/new/javascript/init_genome_browser.js index 07bdaaeb..eba1a69f 100644 --- a/wqflask/wqflask/static/new/javascript/init_genome_browser.js +++ b/wqflask/wqflask/static/new/javascript/init_genome_browser.js @@ -72,7 +72,9 @@ var config = }; $('#browser_tab').click(function() { - GenomeBrowser.main(config)(); + if ($('#gwas').length == 0){ + GenomeBrowser.main(config)(); + } }); document.getElementById("controls").style.visibility = "visible"; \ No newline at end of file diff --git a/wqflask/wqflask/static/packages/purescript_genome_browser/css/purescript-genetics-browser.css b/wqflask/wqflask/static/packages/purescript_genome_browser/css/purescript-genetics-browser.css deleted file mode 100644 index 135292ac..00000000 --- a/wqflask/wqflask/static/packages/purescript_genome_browser/css/purescript-genetics-browser.css +++ /dev/null @@ -1 +0,0 @@ -body,html{max-width:100%;overflow-x:hidden}#browser{position:absolute;margin:0}#info-line{border:1px solid #aaa;padding:2px;position:absolute;right:0;top:1px;min-width:14%;font-size:9pt}#controls{visibility:hidden;position:absolute;top:4px;left:100px;z-index:1000}#controls>button{border:1px solid #aaa;border-radius:2px;padding-left:6px;padding-right:6px;height:23px;min-width:20px}button#scrollRight,button#zoomIn{margin-left:-2px;margin-right:4px}#infoBox{position:absolute;display:inline-block;z-index:10000;visibility:hidden;padding:5px;border:2px solid grey;border-radius:5%;background-color:#fff;min-height:100px;min-width:10px;max-width:80%;margin-top:9.7em;font-family:sans-serif}#infoBox>div{float:left;margin:1em 1.2em}#infoBox>div>p{margin:.1em} \ No newline at end of file diff --git a/wqflask/wqflask/static/packages/purescript_genome_browser/js/purescript-genetics-browser.js b/wqflask/wqflask/static/packages/purescript_genome_browser/js/purescript-genetics-browser.js index 27bb4b2f..26fd2d99 100644 --- a/wqflask/wqflask/static/packages/purescript_genome_browser/js/purescript-genetics-browser.js +++ b/wqflask/wqflask/static/packages/purescript_genome_browser/js/purescript-genetics-browser.js @@ -1,63016 +1,659 @@ -// modules are defined as an array -// [ module function, map of requires ] -// -// map of requires is short require name -> numeric require -// -// anything defined in a previous bundle is accessed via the -// orig method which is the require for previous bundles -parcelRequire = (function (modules, cache, entry, globalName) { - // Save the require from previous bundle to this closure if any - var previousRequire = typeof parcelRequire === 'function' && parcelRequire; - var nodeRequire = typeof require === 'function' && require; - - function newRequire(name, jumped) { - if (!cache[name]) { - if (!modules[name]) { - // if we cannot find the module within our internal map or - // cache jump to the current global require ie. the last bundle - // that was added to the page. - var currentRequire = typeof parcelRequire === 'function' && parcelRequire; - if (!jumped && currentRequire) { - return currentRequire(name, true); - } - - // If there are other bundles on this page the require from the - // previous one is saved to 'previousRequire'. Repeat this as - // many times as there are bundles until the module is found or - // we exhaust the require chain. - if (previousRequire) { - return previousRequire(name, true); - } - - // Try the node require function if it exists. - if (nodeRequire && typeof name === 'string') { - return nodeRequire(name); - } - - var err = new Error('Cannot find module \'' + name + '\''); - err.code = 'MODULE_NOT_FOUND'; - throw err; - } - - localRequire.resolve = resolve; - localRequire.cache = {}; - - var module = cache[name] = new newRequire.Module(name); - - modules[name][0].call(module.exports, localRequire, module, module.exports, this); - } - - return cache[name].exports; - - function localRequire(x){ - return newRequire(localRequire.resolve(x)); - } - - function resolve(x){ - return modules[name][1][x] || x; - } - } - - function Module(moduleName) { - this.id = moduleName; - this.bundle = newRequire; - this.exports = {}; - } - - newRequire.isParcelRequire = true; - newRequire.Module = Module; - newRequire.modules = modules; - newRequire.cache = cache; - newRequire.parent = previousRequire; - newRequire.register = function (id, exports) { - modules[id] = [function (require, module) { - module.exports = exports; - }, {}]; - }; - - var error; - for (var i = 0; i < entry.length; i++) { - try { - newRequire(entry[i]); - } catch (e) { - // Save first error but execute all entries - if (!error) { - error = e; - } - } - } - - if (entry.length) { - // Expose entry point to Node, AMD or browser globals - // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js - var mainExports = newRequire(entry[entry.length - 1]); - - // CommonJS - if (typeof exports === "object" && typeof module !== "undefined") { - module.exports = mainExports; - - // RequireJS - } else if (typeof define === "function" && define.amd) { - define(function () { - return mainExports; - }); - - // {% endblock %} diff --git a/wqflask/wqflask/templates/mapping_results.html b/wqflask/wqflask/templates/mapping_results.html index becb139a..189f8abc 100644 --- a/wqflask/wqflask/templates/mapping_results.html +++ b/wqflask/wqflask/templates/mapping_results.html @@ -19,8 +19,8 @@ - {% if gwa_filename is defined %} - + {% if output_files is defined %} + {% endif %} {% if reaper_version is defined %} @@ -171,7 +171,7 @@ {% endif %} -
+