From 52bf76b7238a4b3395e667c0dc8bff5cc409cc58 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 7 Aug 2019 11:49:20 -0500 Subject: Changed rn3 to rn6 for a couple external links on the trait page Made some text bold on trait page details --- .../marker_regression/display_mapping_results.py | 6 +- .../wqflask/marker_regression/qtlreaper_mapping.py | 3 +- wqflask/wqflask/marker_regression/run_mapping.py | 87 ++++++++++++---------- wqflask/wqflask/search_results.py | 79 ++++++++++++++------ wqflask/wqflask/show_trait/show_trait.py | 4 +- .../wqflask/static/new/javascript/show_trait.js | 3 +- wqflask/wqflask/templates/mapping_results.html | 56 ++++++++------ wqflask/wqflask/templates/search_result_page.html | 7 ++ wqflask/wqflask/templates/show_trait_details.html | 24 +++--- wqflask/wqflask/views.py | 18 ++++- 10 files changed, 181 insertions(+), 106 deletions(-) diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index ddf6dd50..ea1ca5ed 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -146,7 +146,7 @@ class DisplayMappingResults(object): self.dataset = start_vars['dataset'] self.this_trait = start_vars['this_trait'] - self.n_samples = len(start_vars['vals']) + self.n_samples = start_vars['num_vals'] self.species = start_vars['species'] self.genofile_string = "" if 'genofile_string' in start_vars: @@ -168,8 +168,8 @@ class DisplayMappingResults(object): self.mapmodel_rqtl_geno = start_vars['model'] self.pair_scan = start_vars['pair_scan'] - if self.mapping_method != "gemma" and self.mapping_method != "plink": - self.js_data = start_vars['js_data'] + #if self.mapping_method != "gemma" and self.mapping_method != "plink": + self.js_data = start_vars['js_data'] self.trimmed_markers = start_vars['trimmed_markers'] #Top markers to display in table if self.dataset.group.species == "rat": diff --git a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py index b74a1c4d..809d0ce4 100644 --- a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py +++ b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py @@ -95,7 +95,8 @@ def parse_reaper_output(gwa_filename, permu_filename, bootstrap_filename): marker['chr'] = line.split("\t")[2] marker['cM'] = float(line.split("\t")[3]) marker['Mb'] = float(line.split("\t")[4]) - marker['p_value'] = float(line.split("\t")[7]) + if float(line.split("\t")[7]) != 1: + marker['p_value'] = float(line.split("\t")[7]) marker['lrs_value'] = float(line.split("\t")[5]) marker['lod_score'] = marker['lrs_value'] / 4.61 marker['additive'] = float(line.split("\t")[6]) diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py index 676df391..7f6bb0a5 100644 --- a/wqflask/wqflask/marker_regression/run_mapping.py +++ b/wqflask/wqflask/marker_regression/run_mapping.py @@ -85,6 +85,8 @@ class RunMapping(object): self.samples.append(sample) self.vals.append(value) + self.num_vals = start_vars['num_vals'] + #ZS: Check if genotypes exist in the DB in order to create links for markers if "geno_db_exists" in start_vars: self.geno_db_exists = start_vars['geno_db_exists'] @@ -311,14 +313,32 @@ class RunMapping(object): else: self.qtl_results = [] + self.qtl_results_for_browser = [] highest_chr = 1 #This is needed in order to convert the highest chr to X/Y for marker in results: + browser_marker = dict( + chr = str(marker['chr']), + rs = marker['name'], + ps = marker['Mb']*1000000 + ) + if 'p_value' in marker: + browser_marker['p_wald'] = marker['p_value'] + else: + if 'lrs_value' in marker and marker['lrs_value'] > 0: + browser_marker['p_wald'] = -math.log10(marker['lrs_value']/4.16) + elif 'lod_score' in marker and marker['lod_score'] > 0: + browser_marker['p_wald'] = -math.log10(marker['lod_score']) + else: + browser_marker['p_wald'] = 0 + self.qtl_results_for_browser.append(browser_marker) if marker['chr'] > 0 or marker['chr'] == "X" or marker['chr'] == "X/Y": if marker['chr'] > highest_chr or marker['chr'] == "X" or marker['chr'] == "X/Y": highest_chr = marker['chr'] if ('lod_score' in marker.keys()) or ('lrs_value' in marker.keys()): self.qtl_results.append(marker) + browser_files = write_input_for_browser(self.dataset, self.qtl_results_for_browser) + with Bench("Exporting Results"): export_mapping_results(self.dataset, self.this_trait, self.qtl_results, self.mapping_results_path, self.mapping_scale, self.score_type) @@ -330,50 +350,23 @@ class RunMapping(object): self.trimmed_markers = trim_markers_for_table(results) if self.mapping_method != "gemma": - self.json_data['chr'] = [] - self.json_data['pos'] = [] - self.json_data['lod.hk'] = [] - self.json_data['markernames'] = [] - - self.json_data['suggestive'] = self.suggestive - self.json_data['significant'] = self.significant - - #Need to convert the QTL objects that qtl reaper returns into a json serializable dictionary - for index, qtl in enumerate(self.qtl_results): - #if index<40: - # logger.debug("lod score is:", qtl['lod_score']) - if qtl['chr'] == highest_chr and highest_chr != "X" and highest_chr != "X/Y": - #logger.debug("changing to X") - self.json_data['chr'].append("X") - else: - self.json_data['chr'].append(str(qtl['chr'])) - self.json_data['pos'].append(qtl['Mb']) - if 'lrs_value' in qtl.keys(): - self.json_data['lod.hk'].append(str(qtl['lrs_value'])) - else: - self.json_data['lod.hk'].append(str(qtl['lod_score'])) - self.json_data['markernames'].append(qtl['name']) - - #Get chromosome lengths for drawing the interval map plot - chromosome_mb_lengths = {} - self.json_data['chrnames'] = [] - for key in self.species.chromosomes.chromosomes.keys(): - self.json_data['chrnames'].append([self.species.chromosomes.chromosomes[key].name, self.species.chromosomes.chromosomes[key].mb_length]) - chromosome_mb_lengths[key] = self.species.chromosomes.chromosomes[key].mb_length - self.js_data = dict( - result_score_type = self.score_type, - json_data = self.json_data, - this_trait = self.this_trait.name, - data_set = self.dataset.name, - maf = self.maf, - manhattan_plot = self.manhattan_plot, - mapping_scale = self.mapping_scale, - chromosomes = chromosome_mb_lengths, - qtl_results = self.qtl_results, + #result_score_type = self.score_type, + #this_trait = self.this_trait.name, + #data_set = self.dataset.name, + #maf = self.maf, + #manhattan_plot = self.manhattan_plot, + #mapping_scale = self.mapping_scale, + #chromosomes = chromosome_mb_lengths, + #qtl_results = self.qtl_results, num_perm = self.num_perm, perm_results = self.perm_output, + browser_files = browser_files ) + else: + self.js_data = dict( + browser_files = browser_files + ) def run_rqtl_plink(self): # os.chdir("") never do this inside a webserver!! @@ -497,3 +490,17 @@ def trim_markers_for_table(markers): return trimmed_sorted_markers else: return sorted_markers + +def write_input_for_browser(this_dataset, markers): + file_base = this_dataset.group.name + "_" + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) + gwas_filename = file_base + "_GWAS" + annot_filename = file_base + "_ANNOT" + gwas_path = "{}/gn2/".format(TEMPDIR) + gwas_filename + annot_path = "{}/gn2/".format(TEMPDIR) + annot_filename + + with open(gwas_path + ".json", "w") as gwas_file, open(annot_path + ".json", "w") as annot_file: + gwas_file.write(json.dumps(markers)) + annot_file.write(json.dumps([])) + + return [gwas_filename, annot_filename] + #return [gwas_filename, annot_filename] \ No newline at end of file diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index 444e1f40..e74fef80 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -25,7 +25,7 @@ from db import webqtlDatabaseFunction from wqflask import user_manager -from flask import render_template +from flask import render_template, Flask, g from utility import formatting from utility.type_checking import is_float, is_int, is_str, get_float, get_int, get_string @@ -47,6 +47,7 @@ views.py). ########################################### self.uc_id = uuid.uuid4() + self.go_term = None logger.debug("uc_id:", self.uc_id) # contains a unique id logger.debug("kw is:", kw) # dict containing search terms @@ -157,25 +158,31 @@ views.py). combined_where_clause = "" previous_from_clauses = [] #The same table can't be referenced twice in the from clause for i, a_search in enumerate(self.search_terms): - the_search = self.get_search_ob(a_search) - if the_search != None: - get_from_clause = getattr(the_search, "get_from_clause", None) - if callable(get_from_clause): - from_clause = the_search.get_from_clause() - if from_clause in previous_from_clauses: - pass - else: - previous_from_clauses.append(from_clause) - combined_from_clause += from_clause - where_clause = the_search.get_where_clause() - combined_where_clause += "(" + where_clause + ")" - if (i+1) < len(self.search_terms): - if self.and_or == "and": - combined_where_clause += "AND" - else: - combined_where_clause += "OR" + if a_search['key'] == "GO": + self.go_term = a_search['search_term'][0] + gene_list = get_GO_symbols(a_search) + self.search_terms += gene_list + continue else: - self.search_term_exists = False + the_search = self.get_search_ob(a_search) + if the_search != None: + get_from_clause = getattr(the_search, "get_from_clause", None) + if callable(get_from_clause): + from_clause = the_search.get_from_clause() + if from_clause in previous_from_clauses: + pass + else: + previous_from_clauses.append(from_clause) + combined_from_clause += from_clause + where_clause = the_search.get_where_clause() + combined_where_clause += "(" + where_clause + ")" + if (i+1) < len(self.search_terms): + if self.and_or == "and": + combined_where_clause += "AND" + else: + combined_where_clause += "OR" + else: + self.search_term_exists = False if self.search_term_exists: combined_where_clause = "(" + combined_where_clause + ")" final_query = the_search.compile_final_query(combined_from_clause, combined_where_clause) @@ -186,11 +193,19 @@ views.py). self.search_term_exists = False else: for a_search in self.search_terms: - the_search = self.get_search_ob(a_search) - if the_search != None: - self.results.extend(the_search.run()) + logger.debug("TERMS:", self.search_terms) + if a_search['key'] == "GO": + self.go_term = a_search['search_term'][0] + gene_list = get_GO_symbols(a_search) + self.search_terms += gene_list + self.search_terms.pop(0) + continue else: - self.search_term_exists = False + the_search = self.get_search_ob(a_search) + if the_search != None: + self.results.extend(the_search.run()) + else: + self.search_term_exists = False if self.search_term_exists: if the_search != None: @@ -218,9 +233,27 @@ views.py). else: return None +def get_GO_symbols(a_search): + query = """SELECT genes + FROM GORef + WHERE goterm='{0}:{1}'""".format(a_search['key'], a_search['search_term'][0]) + + gene_list = g.db.execute(query).fetchone()[0].strip().split() + + new_terms = [] + for gene in gene_list: + this_term = dict(key=None, + separator=None, + search_term=[gene]) + + new_terms.append(this_term) + + return new_terms + def insert_newlines(string, every=64): """ This is because it is seemingly impossible to change the width of the description column, so I'm just manually adding line breaks """ lines = [] for i in xrange(0, len(string), every): lines.append(string[i:i+every]) return '\n'.join(lines) + diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index f1f5840f..b0a46b32 100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -107,7 +107,7 @@ class ShowTrait(object): blatsequence += '%3EProbe_' + string.strip(seqt[1]) + '%0A' + string.strip(seqt[0]) + '%0A' if self.dataset.group.species == "rat": - self.UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', blatsequence) + self.UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn6', blatsequence) self.UTHSC_BLAT_URL = "" elif self.dataset.group.species == "mouse": self.UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm10', blatsequence) @@ -314,7 +314,7 @@ class ShowTrait(object): if chr and transcript_start and transcript_end and kgId: transcript_start = int(transcript_start*1000000) # Convert to bases from megabases transcript_end = int(transcript_end*1000000) - self.ucsc_blat_link = webqtlConfig.UCSC_REFSEQ % ('rn3', kgId, chr, transcript_start, transcript_end) + self.ucsc_blat_link = webqtlConfig.UCSC_REFSEQ % ('rn6', kgId, chr, transcript_start, transcript_end) if self.this_trait.geneid and (self.dataset.group.species == "mouse" or self.dataset.group.species == "rat" or self.dataset.group.species == "human"): self.biogps_link = webqtlConfig.BIOGPS_URL % (self.dataset.group.species, self.this_trait.geneid) diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 48b6da5e..53158885 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -940,6 +940,7 @@ if (js_data.num_values < 256) { root.bar_layout = { title: js_data.trait_id, xaxis: { + type: 'category', titlefont: { size: 16 }, @@ -947,7 +948,7 @@ if (js_data.num_values < 256) { ticklen: 4, tickfont: { size: 16 - } + }, }, yaxis: { title: js_data.unit_type, diff --git a/wqflask/wqflask/templates/mapping_results.html b/wqflask/wqflask/templates/mapping_results.html index 98931166..b8b64761 100644 --- a/wqflask/wqflask/templates/mapping_results.html +++ b/wqflask/wqflask/templates/mapping_results.html @@ -3,9 +3,11 @@ {% block css %} + + - + {% endblock %} {% from "base_macro.html" import header %} {% block content %} @@ -29,6 +31,7 @@ {% for sample in samples %} {% endfor %} + @@ -153,11 +156,9 @@
  • GN1 Map
  • - {% if mapping_method != "gemma" and mapping_method != "plink" %} -
  • - Vector Map +
  • + Genome Browser
  • - {% endif %}
    @@ -177,19 +178,31 @@ {% endif %}
    - {% if mapping_method != "gemma" and mapping_method != "plink" %} -
    -
    -
    -
    +
    +
    +
    + + + + + +
    +
    - {% endif %}
    {% if selectedChr == -1 %} -
    +

    Mapping Statistics


    @@ -307,20 +320,14 @@ + - {% if mapping_method != "gemma" and mapping_method != "plink" %} - {% endif %} - {% if mapping_method != "gemma" and mapping_method != "plink" %} - - - - - {% endif %} + {% endblock %} diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 2dded69f..8dfa37a8 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -15,6 +15,9 @@

    Search Results: We searched {{ dataset.fullname }} to find all records + {% if go_term is not none %} + with Gene Ontology ID GO:{{ go_term }}. + {% else %} {% for word in search_terms %} {% if word.key|lower == "rif" %} with GeneRIF containing {{ word.search_term[0] }}{% if loop.last %}.{% else %} and {% endif %} @@ -40,9 +43,13 @@ {% if word.search_term[0] == "*" %} in the dataset.{% else %}{% if loop.first %}that match:
    {% endif %}"{{ word.search_term[0] }}"{% if loop.last %}{% else %} and {% endif %}{% endif %} {% endif %} {% endfor %} + {% endif %}
    {{ results|count }} records are shown below.

    + {% if go_term is not none %} +

    The associated genes include:

    {% for word in search_terms %}{{ word.search_term[0] }}{% endfor %}

    + {% endif %} diff --git a/wqflask/wqflask/templates/show_trait_details.html b/wqflask/wqflask/templates/show_trait_details.html index 7714a1ab..bb0b62fe 100644 --- a/wqflask/wqflask/templates/show_trait_details.html +++ b/wqflask/wqflask/templates/show_trait_details.html @@ -1,40 +1,40 @@ - + {% if this_trait.dataset.type == 'Publish' %} - + - + - + - + {% else %} - + {% endif %} {% if this_trait.dataset.type == 'ProbeSet' %} {% if this_trait.symbol != None %} - + {% endif %} - + {% if this_trait.alias_fmt != "Not Available" %} @@ -46,12 +46,12 @@ {% endif %} {% if this_trait.dataset.type != 'Publish' %} - + {% endif %} - + {% if this_trait.probe_set_specificity %} - + - +
    Species and GroupSpecies and Group {{ this_trait.dataset.group.species }}, {{ this_trait.dataset.group.name }}
    PhenotypePhenotype
    {{ this_trait.description_fmt }}
    AuthorsAuthors
    {{ this_trait.authors }}
    TitleTitle
    {{ this_trait.title }}
    JournalJournal {{ this_trait.journal }} ({% if this_trait.pubmed_id %}{{ this_trait.year }}{% else %}{{ this_trait.year }}{% endif %})
    TissueTissue {{ this_trait.dataset.tissue }}
    Gene SymbolGene Symbol {{ this_trait.symbol }}
    AliasesAliases Wikidata: {{ this_trait.wikidata_alias_fmt|replace(",",";") }}
    LocationLocation {{ this_trait.location_fmt }}
    DatabaseDatabase {{ dataset.fullname }} @@ -60,7 +60,7 @@
    Target ScoreTarget Score BLAT Specificity @@ -75,7 +75,7 @@ {% endif %} {% if this_trait.pubmed_id or this_trait.geneid or this_trait.omim or this_trait.symbol %}
    Resource LinksResource Links {% if pubmed_link %} diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 7b585b03..aa64a910 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -639,7 +639,8 @@ def mapping_results_page(): 'mapmethod_rqtl_geno', 'mapmodel_rqtl_geno', 'temp_trait', - 'reaper_version' + 'reaper_version', + 'num_vals' ) start_vars = {} for key, value in initial_start_vars.iteritems(): @@ -670,8 +671,8 @@ def mapping_results_page(): if template_vars.no_results: rendered_template = render_template("mapping_error.html") else: - if template_vars.mapping_method != "gemma" and template_vars.mapping_method != "plink": - template_vars.js_data = json.dumps(template_vars.js_data, + #if template_vars.mapping_method != "gemma" and template_vars.mapping_method != "plink": + template_vars.js_data = json.dumps(template_vars.js_data, default=json_default_handler, indent=" ") @@ -808,6 +809,17 @@ def get_temp_data(): temp_uuid = request.args['key'] return flask.jsonify(temp_data.TempData(temp_uuid).get_all()) +@app.route("/browser_input", methods=('GET',)) +def browser_inputs(): + """ Returns JSON from tmp directory for the purescript genome browser""" + + filename = request.args['filename'] + + with open("{}/gn2/".format(TEMPDIR) + filename + ".json", "r") as the_file: + file_contents = json.load(the_file) + + return flask.jsonify(file_contents) + ########################################################################## def json_default_handler(obj): -- cgit v1.2.3