diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/base/data_set.py | 6 | ||||
-rw-r--r-- | wqflask/base/trait.py | 12 | ||||
-rwxr-xr-x | wqflask/base/webqtlCaseData.py | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | wqflask/base/webqtlConfig.py | 2 | ||||
-rw-r--r-- | wqflask/wqflask/gsearch.py | 166 | ||||
-rw-r--r-- | wqflask/wqflask/heatmap/heatmap.py | 2 | ||||
-rw-r--r-- | wqflask/wqflask/marker_regression/marker_regression.py | 30 | ||||
-rw-r--r--[-rwxr-xr-x] | wqflask/wqflask/show_trait/show_trait.py | 9 | ||||
-rwxr-xr-x | wqflask/wqflask/templates/gsearch_gene.html | 121 | ||||
-rw-r--r-- | wqflask/wqflask/update_search_results.py | 129 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 12 |
11 files changed, 317 insertions, 175 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 053b45fc..4953e728 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -711,7 +711,7 @@ class PhenotypeDataSet(DataSet): def retrieve_sample_data(self, trait): query = """ SELECT - Strain.Name, PublishData.value, PublishSE.error, NStrain.count + Strain.Name, PublishData.value, PublishSE.error, NStrain.count, Strain.Name2 FROM (PublishData, Strain, PublishXRef, PublishFreeze) left join PublishSE on @@ -803,7 +803,7 @@ class GenotypeDataSet(DataSet): def retrieve_sample_data(self, trait): query = """ SELECT - Strain.Name, GenoData.value, GenoSE.error, GenoData.Id + Strain.Name, GenoData.value, GenoSE.error, GenoData.Id, Sample.Name2 FROM (GenoData, GenoFreeze, Strain, Geno, GenoXRef) left join GenoSE on @@ -1031,7 +1031,7 @@ class MrnaAssayDataSet(DataSet): def retrieve_sample_data(self, trait): query = """ SELECT - Strain.Name, ProbeSetData.value, ProbeSetSE.error, ProbeSetData.Id + Strain.Name, ProbeSetData.value, ProbeSetSE.error, ProbeSetData.Id, Strain.Name2 FROM (ProbeSetData, ProbeSetFreeze, Strain, ProbeSet, ProbeSetXRef) left join ProbeSetSE on diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 6b4fff20..d1c0be83 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -180,13 +180,15 @@ class GeneralTrait(object): samples = [] vals = [] the_vars = [] + sample_aliases = [] for sample_name, sample_data in self.data.items(): if sample_data.value != None: if not include_variance or sample_data.variance != None: samples.append(sample_name) vals.append(sample_data.value) the_vars.append(sample_data.variance) - return samples, vals, the_vars + sample_aliases.append(sample_data.name2) + return samples, vals, the_vars, sample_aliases # @@ -230,7 +232,7 @@ class GeneralTrait(object): if results: for item in results: - name, value, variance, num_cases = item + name, value, variance, num_cases, name2 = item if not samplelist or (samplelist and name in samplelist): self.data[name] = webqtlCaseData(*item) #name, value, variance, num_cases) @@ -313,9 +315,9 @@ class GeneralTrait(object): self.confidential = 0 if self.pre_publication_description and not self.pubmed_id: self.confidential = 1 - - description = self.post_publication_description + description = self.post_publication_description + #If the dataset is confidential and the user has access to confidential #phenotype traits, then display the pre-publication description instead #of the post-publication description @@ -479,7 +481,7 @@ class GeneralTrait(object): else: self.locus = self.lrs = self.additive = "" - if self.locus_chr != "" and self.locus_mb != "": + if (self.dataset.type == 'Publish' or self.dataset.type == "ProbeSet") and self.locus_chr != "" and self.locus_mb != "": #XZ: LRS_location_value is used for sorting try: LRS_location_value = int(self.locus_chr)*1000 + float(self.locus_mb) diff --git a/wqflask/base/webqtlCaseData.py b/wqflask/base/webqtlCaseData.py index 42763aed..99a34866 100755 --- a/wqflask/base/webqtlCaseData.py +++ b/wqflask/base/webqtlCaseData.py @@ -29,8 +29,9 @@ print("Mr. Mojo Risin 2") class webqtlCaseData(object): """one case data in one trait""" - def __init__(self, name, value=None, variance=None, num_cases=None): + def __init__(self, name, value=None, variance=None, num_cases=None, name2=None): self.name = name + self.name2 = name2 # Other name (for traits like BXD65a) self.value = value # Trait Value self.variance = variance # Trait Variance self.num_cases = num_cases # Number of individuals/cases diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py index 0358bcbf..d0016b33 100755..100644 --- a/wqflask/base/webqtlConfig.py +++ b/wqflask/base/webqtlConfig.py @@ -69,7 +69,7 @@ GENERATED_TEXT_DIR = mk_dir(TMPDIR+'/generated_text/') # Flat file directories GENODIR = flat_files('genotype')+'/' -JSON_GENODIR = assert_dir(GENODIR+'json/') +JSON_GENODIR = flat_files('json')+'/' PORTADDR = "http://50.16.251.170" diff --git a/wqflask/wqflask/gsearch.py b/wqflask/wqflask/gsearch.py index 4cd3874c..4f9dc316 100644 --- a/wqflask/wqflask/gsearch.py +++ b/wqflask/wqflask/gsearch.py @@ -1,94 +1,94 @@ from __future__ import absolute_import, print_function, division from flask import Flask, g -from base.data_set import create_dataset -from base.trait import GeneralTrait -from dbFunction import webqtlDatabaseFunction +#from base.data_set import create_dataset +#from base.trait import GeneralTrait +#from dbFunction import webqtlDatabaseFunction -from utility.benchmark import Bench +#from utility.benchmark import Bench class GSearch(object): def __init__(self, kw): self.type = kw['type'] self.terms = kw['terms'] - if self.type == "gene": - sql = """ - SELECT - Species.`Name` AS species_name, - InbredSet.`Name` AS inbredset_name, - Tissue.`Name` AS tissue_name, - ProbeSetFreeze.Name AS probesetfreeze_name, - ProbeSet.Name AS probeset_name, - ProbeSet.Symbol AS probeset_symbol, - ProbeSet.`description` AS probeset_description, - ProbeSet.Chr AS chr, - ProbeSet.Mb AS mb, - ProbeSetXRef.Mean AS mean, - ProbeSetXRef.LRS AS lrs, - ProbeSetXRef.`Locus` AS locus, - ProbeSetXRef.`pValue` AS pvalue, - ProbeSetXRef.`additive` AS additive - FROM Species, InbredSet, ProbeSetXRef, ProbeSet, ProbeFreeze, ProbeSetFreeze, Tissue - WHERE InbredSet.`SpeciesId`=Species.`Id` - AND ProbeFreeze.InbredSetId=InbredSet.`Id` - AND ProbeFreeze.`TissueId`=Tissue.`Id` - AND ProbeSetFreeze.ProbeFreezeId=ProbeFreeze.Id - AND ( MATCH (ProbeSet.Name,ProbeSet.description,ProbeSet.symbol,alias,GenbankId, UniGeneId, Probe_Target_Description) AGAINST ('%s' IN BOOLEAN MODE) ) - AND ProbeSet.Id = ProbeSetXRef.ProbeSetId - AND ProbeSetXRef.ProbeSetFreezeId=ProbeSetFreeze.Id - AND ProbeSetFreeze.public > 0 - ORDER BY species_name, inbredset_name, tissue_name, probesetfreeze_name, probeset_name - LIMIT 6000 - """ % (self.terms) - with Bench("Running query"): - re = g.db.execute(sql).fetchall() - self.trait_list = [] - with Bench("Creating trait objects"): - for line in re: - dataset = create_dataset(line[3], "ProbeSet", get_samplelist=False) - trait_id = line[4] - #with Bench("Building trait object"): - this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) - self.trait_list.append(this_trait) + # if self.type == "gene": + # sql = """ + # SELECT + # Species.`Name` AS species_name, + # InbredSet.`Name` AS inbredset_name, + # Tissue.`Name` AS tissue_name, + # ProbeSetFreeze.Name AS probesetfreeze_name, + # ProbeSet.Name AS probeset_name, + # ProbeSet.Symbol AS probeset_symbol, + # ProbeSet.`description` AS probeset_description, + # ProbeSet.Chr AS chr, + # ProbeSet.Mb AS mb, + # ProbeSetXRef.Mean AS mean, + # ProbeSetXRef.LRS AS lrs, + # ProbeSetXRef.`Locus` AS locus, + # ProbeSetXRef.`pValue` AS pvalue, + # ProbeSetXRef.`additive` AS additive + # FROM Species, InbredSet, ProbeSetXRef, ProbeSet, ProbeFreeze, ProbeSetFreeze, Tissue + # WHERE InbredSet.`SpeciesId`=Species.`Id` + # AND ProbeFreeze.InbredSetId=InbredSet.`Id` + # AND ProbeFreeze.`TissueId`=Tissue.`Id` + # AND ProbeSetFreeze.ProbeFreezeId=ProbeFreeze.Id + # AND ( MATCH (ProbeSet.Name,ProbeSet.description,ProbeSet.symbol,alias,GenbankId, UniGeneId, Probe_Target_Description) AGAINST ('%s' IN BOOLEAN MODE) ) + # AND ProbeSet.Id = ProbeSetXRef.ProbeSetId + # AND ProbeSetXRef.ProbeSetFreezeId=ProbeSetFreeze.Id + # AND ProbeSetFreeze.public > 0 + # ORDER BY species_name, inbredset_name, tissue_name, probesetfreeze_name, probeset_name + # LIMIT 6000 + # """ % (self.terms) + # with Bench("Running query"): + # re = g.db.execute(sql).fetchall() + # self.trait_list = [] + # with Bench("Creating trait objects"): + # for line in re: + # dataset = create_dataset(line[3], "ProbeSet", get_samplelist=False) + # trait_id = line[4] + # with Bench("Building trait object"): + # this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + # self.trait_list.append(this_trait) - elif self.type == "phenotype": - sql = """ - SELECT - Species.`Name`, - InbredSet.`Name`, - PublishFreeze.`Name`, - PublishXRef.`Id`, - Phenotype.`Post_publication_description`, - Publication.`Authors`, - Publication.`Year`, - PublishXRef.`LRS`, - PublishXRef.`Locus`, - PublishXRef.`additive` - FROM Species,InbredSet,PublishFreeze,PublishXRef,Phenotype,Publication - WHERE PublishXRef.`InbredSetId`=InbredSet.`Id` - AND PublishFreeze.`InbredSetId`=InbredSet.`Id` - AND InbredSet.`SpeciesId`=Species.`Id` - AND PublishXRef.`PhenotypeId`=Phenotype.`Id` - AND PublishXRef.`PublicationId`=Publication.`Id` - AND (Phenotype.Post_publication_description REGEXP "[[:<:]]%s[[:>:]]" - OR Phenotype.Pre_publication_description REGEXP "[[:<:]]%s[[:>:]]" - OR Phenotype.Pre_publication_abbreviation REGEXP "[[:<:]]%s[[:>:]]" - OR Phenotype.Post_publication_abbreviation REGEXP "[[:<:]]%s[[:>:]]" - OR Phenotype.Lab_code REGEXP "[[:<:]]%s[[:>:]]" - OR Publication.PubMed_ID REGEXP "[[:<:]]%s[[:>:]]" - OR Publication.Abstract REGEXP "[[:<:]]%s[[:>:]]" - OR Publication.Title REGEXP "[[:<:]]%s[[:>:]]" - OR Publication.Authors REGEXP "[[:<:]]%s[[:>:]]" - OR PublishXRef.Id REGEXP "[[:<:]]%s[[:>:]]") - ORDER BY Species.`Name`, InbredSet.`Name`, PublishXRef.`Id` - LIMIT 6000 - """ % (self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms) - re = g.db.execute(sql).fetchall() - self.trait_list = [] - with Bench("Creating trait objects"): - for line in re: - dataset = create_dataset(line[2], "Publish") - trait_id = line[3] - this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) - self.trait_list.append(this_trait) + # elif self.type == "phenotype": + # sql = """ + # SELECT + # Species.`Name`, + # InbredSet.`Name`, + # PublishFreeze.`Name`, + # PublishXRef.`Id`, + # Phenotype.`Post_publication_description`, + # Publication.`Authors`, + # Publication.`Year`, + # PublishXRef.`LRS`, + # PublishXRef.`Locus`, + # PublishXRef.`additive` + # FROM Species,InbredSet,PublishFreeze,PublishXRef,Phenotype,Publication + # WHERE PublishXRef.`InbredSetId`=InbredSet.`Id` + # AND PublishFreeze.`InbredSetId`=InbredSet.`Id` + # AND InbredSet.`SpeciesId`=Species.`Id` + # AND PublishXRef.`PhenotypeId`=Phenotype.`Id` + # AND PublishXRef.`PublicationId`=Publication.`Id` + # AND (Phenotype.Post_publication_description REGEXP "[[:<:]]%s[[:>:]]" + # OR Phenotype.Pre_publication_description REGEXP "[[:<:]]%s[[:>:]]" + # OR Phenotype.Pre_publication_abbreviation REGEXP "[[:<:]]%s[[:>:]]" + # OR Phenotype.Post_publication_abbreviation REGEXP "[[:<:]]%s[[:>:]]" + # OR Phenotype.Lab_code REGEXP "[[:<:]]%s[[:>:]]" + # OR Publication.PubMed_ID REGEXP "[[:<:]]%s[[:>:]]" + # OR Publication.Abstract REGEXP "[[:<:]]%s[[:>:]]" + # OR Publication.Title REGEXP "[[:<:]]%s[[:>:]]" + # OR Publication.Authors REGEXP "[[:<:]]%s[[:>:]]" + # OR PublishXRef.Id REGEXP "[[:<:]]%s[[:>:]]") + # ORDER BY Species.`Name`, InbredSet.`Name`, PublishXRef.`Id` + # LIMIT 6000 + # """ % (self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms) + # re = g.db.execute(sql).fetchall() + # self.trait_list = [] + # with Bench("Creating trait objects"): + # for line in re: + # dataset = create_dataset(line[2], "Publish") + # trait_id = line[3] + # this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + # self.trait_list.append(this_trait) diff --git a/wqflask/wqflask/heatmap/heatmap.py b/wqflask/wqflask/heatmap/heatmap.py index 2445b37f..19c330eb 100644 --- a/wqflask/wqflask/heatmap/heatmap.py +++ b/wqflask/wqflask/heatmap/heatmap.py @@ -136,7 +136,7 @@ class Heatmap(object): this_trait = trait_db[0] #this_db = trait_db[1] genotype = self.dataset.group.read_genotype_file() - samples, values, variances = this_trait.export_informative() + samples, values, variances, sample_aliases = this_trait.export_informative() trimmed_samples = [] trimmed_values = [] diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 08f422f0..1e0a618e 100644 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -56,11 +56,21 @@ class MarkerRegression(object): self.samples = [] # Want only ones with values self.vals = [] - + + #for sample in self.this_trait.data.keys(): for sample in self.dataset.group.samplelist: - value = start_vars['value:' + sample] - self.samples.append(str(sample)) - self.vals.append(value) + in_trait_data = False + for item in self.this_trait.data: + if self.this_trait.data[item].name2 == sample: + value = start_vars['value:' + self.this_trait.data[item].name] + self.samples.append(self.this_trait.data[item].name) + self.vals.append(value) + in_trait_data = True + break + if not in_trait_data: + value = start_vars['value:' + sample] + self.samples.append(sample) + self.vals.append(value) self.mapping_method = start_vars['method'] if start_vars['manhattan_plot'] == "True": @@ -203,6 +213,8 @@ class MarkerRegression(object): if 'lod_score' in marker.keys(): self.qtl_results.append(marker) + self.trimmed_markers = trim_markers_for_table(results) + for qtl in enumerate(self.qtl_results): self.json_data['chr1'].append(str(qtl['chr1'])) self.json_data['chr2'].append(str(qtl['chr2'])) @@ -641,15 +653,17 @@ class MarkerRegression(object): if self.manhattan_plot != True: genotype = genotype.addinterval() - samples, values, variances = self.this_trait.export_informative() - + samples, values, variances, sample_aliases = self.this_trait.export_informative() + trimmed_samples = [] trimmed_values = [] for i in range(0, len(samples)): - if samples[i] in self.dataset.group.samplelist: - trimmed_samples.append(samples[i]) + if self.this_trait.data[samples[i]].name2 in self.dataset.group.samplelist: + trimmed_samples.append(sample_aliases[i]) trimmed_values.append(values[i]) + #print("THE SAMPLES:", trimmed_samples) + if self.num_perm < 100: self.suggestive = 0 self.significant = 0 diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 074c78bf..76651cbf 100755..100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -1184,17 +1184,16 @@ class ShowTrait(object): all_samples_ordered = self.dataset.group.all_samples_ordered() primary_sample_names = list(all_samples_ordered) - - print("self.dataset.group", pf(self.dataset.group.__dict__)) - print("-*- primary_samplelist is:", pf(primary_sample_names)) - + other_sample_names = [] for sample in this_trait.data.keys(): + if (this_trait.data[sample].name2 in primary_sample_names) and (this_trait.data[sample].name not in primary_sample_names): + primary_sample_names.append(this_trait.data[sample].name) + primary_sample_names.remove(this_trait.data[sample].name2) if sample not in all_samples_ordered: all_samples_ordered.append(sample) other_sample_names.append(sample) - print("species:", self.dataset.group.species) if self.dataset.group.species == "human": primary_sample_names += other_sample_names diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 7cc9a1bd..92b0b411 100755 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -2,10 +2,6 @@ {% block title %}Search Results{% endblock %} {% block 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/dataTables.fixedHeader.css" > - <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/fixedcolumns/3.0.4/css/dataTables.fixedColumns.css"> <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" /> {% endblock %} {% block content %} @@ -13,6 +9,7 @@ <div class="container"> + <p>You searched for {{ terms }}.</p> <p>To study a record, click on its ID below.<br />Check records below and click Add button to add to selection.</p> <div> @@ -26,46 +23,28 @@ <br /> <br /> - <table width="2000px" class="table table-hover table-striped" id="trait_table"> + <div style="width: 2000px;"> + <table width="2000px" id="trait_table" class="table table-hover table-striped" > <thead> - <tr> - <th style="width: 30px;"></th> - <th>Index</th> - <th>Species</th> - <th>Group</th> - <th>Tissue</th> - <th>Dataset</th> - <th>Record</th> - <th>Symbol</th> - <th>Description</th> - <th>Location</th> - <th>Mean</th> - <th style="text-align: right;">Max <br>LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - <th>Max LRS Location</th> - <th style="text-align: right;">Additive<br>Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - </tr> - </thead> - <tbody> - {% for this_trait in trait_list %} - <TR id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> - <TD><INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" style="transform: scale(1.5);" VALUE="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"></TD> - <TD>{{ loop.index }}</TD> - <TD>{{ this_trait.dataset.group.species }}</TD> - <TD>{{ this_trait.dataset.group.name }}</TD> - <TD>{{ this_trait.dataset.tissue }}</TD> - <TD>{{ this_trait.dataset.fullname }}</TD> - <TD><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></TD> - <TD>{{ this_trait.symbol }}</TD> - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.location_repr }}</TD> - <TD align="right">{{ '%0.3f' % this_trait.mean|float }}</TD> - <TD align="right">{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - <TD align="right">{{ '%0.3f' % this_trait.additive|float }}</TD> - </TR> - {% endfor %} - </tbody> - </table> + <tr> + <th></th> + <th>Index</th> + <th>Species</th> + <th>Group</th> + <th>Tissue</th> + <th>Dataset</th> + <th>Record</th> + <th>Symbol</th> + <th>Description</th> + <th>Location</th> + <th>Mean</th> + <th>Max<br>LRS<a href="http://genenetwork.org/glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th>Max LRS Location</th> + <th>Additive<br>Effect<a href="http://genenetwork.org/glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + </tr> + </thead> + </table> + </div> </div> </div> @@ -156,23 +135,18 @@ console.time("Creating table"); $('#trait_table').DataTable( { - "columns": [ - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "cust-txt" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "15%" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "cust-txt" } - ], - "order": [[ 1, "asc" ]], + "processing": true, + "serverSide": true, + "paging": false, + "ajax": { + "url": "/gsearch_updating?terms={{ terms }}&type={{ type }}", + "type": "POST", + "dataType": "json", + "contentType": "application/json; charset=utf-8", + "data": function ( args ) { + return { "args": JSON.stringify( args ) }; + } + }, "buttons": [ { extend: 'csvHtml5', @@ -184,15 +158,26 @@ } } ], - "sDom": "RZBtir", + "columns": [ + { "data": "checkbox", "orderable" : false }, + { "data": "index", "orderable" : true }, + { "data": "species", "orderable" : true }, + { "data": "group", "orderable" : true }, + { "data": "tissue", "orderable" : true }, + { "data": "dataset", "orderable" : true }, + { "data": "record", "orderable" : true }, + { "data": "symbol", "orderable" : true }, + { "data": "description", "orderable" : true }, + { "data": "location", "orderable" : true }, + { "data": "mean", "orderable" : true }, + { "data": "max_lrs", "orderable" : true }, + { "data": "max_lrs_location", "orderable" : true }, + { "data": "additive_effect", "orderable" : true } + ], + "sDom": "Bfrti", "autoWidth": false, - "bLengthChange": true, - "bDeferRender": true, - "scrollCollapse": false, - "colResize": { - "tableWidthFixed": false, - }, - "paging": false + "scrollY": "800px", + "bDeferRender": true } ); console.timeEnd("Creating table"); diff --git a/wqflask/wqflask/update_search_results.py b/wqflask/wqflask/update_search_results.py new file mode 100644 index 00000000..ffd7fd51 --- /dev/null +++ b/wqflask/wqflask/update_search_results.py @@ -0,0 +1,129 @@ +from __future__ import absolute_import, print_function, division + +import json + +from flask import Flask, g +from base.data_set import create_dataset +from base.trait import GeneralTrait +from dbFunction import webqtlDatabaseFunction + +from utility.benchmark import Bench + +class GSearch(object): + + def __init__(self, kw): + self.type = kw['type'] + self.terms = kw['terms'] + #self.row_range = kw['row_range'] + if self.type == "gene": + sql = """ + SELECT + Species.`Name` AS species_name, + InbredSet.`Name` AS inbredset_name, + Tissue.`Name` AS tissue_name, + ProbeSetFreeze.Name AS probesetfreeze_name, + ProbeSet.Name AS probeset_name, + ProbeSet.Symbol AS probeset_symbol, + ProbeSet.`description` AS probeset_description, + ProbeSet.Chr AS chr, + ProbeSet.Mb AS mb, + ProbeSetXRef.Mean AS mean, + ProbeSetXRef.LRS AS lrs, + ProbeSetXRef.`Locus` AS locus, + ProbeSetXRef.`pValue` AS pvalue, + ProbeSetXRef.`additive` AS additive + FROM Species, InbredSet, ProbeSetXRef, ProbeSet, ProbeFreeze, ProbeSetFreeze, Tissue + WHERE InbredSet.`SpeciesId`=Species.`Id` + AND ProbeFreeze.InbredSetId=InbredSet.`Id` + AND ProbeFreeze.`TissueId`=Tissue.`Id` + AND ProbeSetFreeze.ProbeFreezeId=ProbeFreeze.Id + AND ( MATCH (ProbeSet.Name,ProbeSet.description,ProbeSet.symbol,alias,GenbankId, UniGeneId, Probe_Target_Description) AGAINST ('%s' IN BOOLEAN MODE) ) + AND ProbeSet.Id = ProbeSetXRef.ProbeSetId + AND ProbeSetXRef.ProbeSetFreezeId=ProbeSetFreeze.Id + AND ProbeSetFreeze.public > 0 + ORDER BY species_name, inbredset_name, tissue_name, probesetfreeze_name, probeset_name + LIMIT 6000 + """ % (self.terms) + with Bench("Running query"): + re = g.db.execute(sql).fetchall() + self.trait_list = [] + with Bench("Creating trait objects"): + for line in re: + dataset = create_dataset(line[3], "ProbeSet", get_samplelist=False) + trait_id = line[4] + #with Bench("Building trait object"): + this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + self.trait_list.append(this_trait) + + elif self.type == "phenotype": + sql = """ + SELECT + Species.`Name`, + InbredSet.`Name`, + PublishFreeze.`Name`, + PublishXRef.`Id`, + Phenotype.`Post_publication_description`, + Publication.`Authors`, + Publication.`Year`, + PublishXRef.`LRS`, + PublishXRef.`Locus`, + PublishXRef.`additive` + FROM Species,InbredSet,PublishFreeze,PublishXRef,Phenotype,Publication + WHERE PublishXRef.`InbredSetId`=InbredSet.`Id` + AND PublishFreeze.`InbredSetId`=InbredSet.`Id` + AND InbredSet.`SpeciesId`=Species.`Id` + AND PublishXRef.`PhenotypeId`=Phenotype.`Id` + AND PublishXRef.`PublicationId`=Publication.`Id` + AND (Phenotype.Post_publication_description REGEXP "[[:<:]]%s[[:>:]]" + OR Phenotype.Pre_publication_description REGEXP "[[:<:]]%s[[:>:]]" + OR Phenotype.Pre_publication_abbreviation REGEXP "[[:<:]]%s[[:>:]]" + OR Phenotype.Post_publication_abbreviation REGEXP "[[:<:]]%s[[:>:]]" + OR Phenotype.Lab_code REGEXP "[[:<:]]%s[[:>:]]" + OR Publication.PubMed_ID REGEXP "[[:<:]]%s[[:>:]]" + OR Publication.Abstract REGEXP "[[:<:]]%s[[:>:]]" + OR Publication.Title REGEXP "[[:<:]]%s[[:>:]]" + OR Publication.Authors REGEXP "[[:<:]]%s[[:>:]]" + OR PublishXRef.Id REGEXP "[[:<:]]%s[[:>:]]") + ORDER BY Species.`Name`, InbredSet.`Name`, PublishXRef.`Id` + LIMIT 6000 + """ % (self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms, self.terms) + re = g.db.execute(sql).fetchall() + self.trait_list = [] + with Bench("Creating trait objects"): + for line in re: + dataset = create_dataset(line[2], "Publish") + trait_id = line[3] + this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + self.trait_list.append(this_trait) + + self.results = self.convert_to_json() + + def convert_to_json(self): + json_dict = {} + #json_dict['draw'] = self.draw, + json_dict['recordsTotal'] = len(self.trait_list), + json_dict['data'] = [] + + for i, trait in enumerate(self.trait_list): + trait_row = { "checkbox": "<INPUT TYPE=\"checkbox\" NAME=\"searchResult\" class=\"checkbox trait_checkbox\" style=\"transform: scale(1.5);\" VALUE=\"{}:{}\">".format(trait.name, trait.dataset.name), + "index": i+1, + "species": trait.dataset.group.species, + "group": trait.dataset.group.name, + "tissue": trait.dataset.tissue, + "dataset": trait.dataset.fullname, + "record": "<a href=\"/show_trait?trait_id=" + trait.name + "&dataset=" + trait.dataset.name + "\" target=\"_blank\">" + trait.name + "</a>", + "symbol": trait.symbol, + "description": trait.description_display, + "location": trait.location_repr, + "mean": trait.mean, + "max_lrs": trait.LRS_score_repr, + "max_lrs_location": trait.LRS_location_repr, + "additive_effect": trait.additive} + json_dict['data'].append(trait_row) + + json_results = json.dumps(json_dict) + return json_results + + + + diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index bd2fff50..7854b0df 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -34,6 +34,7 @@ from flask import (render_template, request, make_response, Response, from wqflask import search_results from wqflask import gsearch +from wqflask import update_search_results from wqflask import docs from wqflask import news from base.data_set import DataSet # Used by YAML in marker_regression @@ -169,6 +170,17 @@ def gsearchact(): return render_template("gsearch_gene.html", **result) elif type == "phenotype": return render_template("gsearch_pheno.html", **result) + +@app.route("/gsearch_updating", methods=('POST',)) +def gsearch_updating(): + print("REQUEST ARGS:", request.values) + result = update_search_results.GSearch(request.args).__dict__ + return result['results'] + # type = request.args['type'] + # if type == "gene": + # return render_template("gsearch_gene_updating.html", **result) + # elif type == "phenotype": + # return render_template("gsearch_pheno.html", **result) @app.route("/docedit") def docedit(): |