From 8427ddfd7b60d74f4be3a453dd0b21ce7bfdb6f3 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 21 Nov 2019 14:55:50 -0600 Subject: Added 3-letter codes to unpublished phenotype traits and fixed issue with ordering phenotype results from searches --- wqflask/base/data_set.py | 19 +++++++++---------- wqflask/base/trait.py | 9 +++++++-- wqflask/wqflask/do_search.py | 6 ++++-- wqflask/wqflask/gsearch.py | 6 +++++- wqflask/wqflask/search_results.py | 4 ++++ wqflask/wqflask/show_trait/show_trait.py | 1 - wqflask/wqflask/templates/gsearch_gene.html | 6 ++++-- wqflask/wqflask/templates/gsearch_pheno.html | 8 +++++--- wqflask/wqflask/templates/search_result_page.html | 2 +- wqflask/wqflask/templates/show_trait.html | 2 +- wqflask/wqflask/views.py | 13 +++++++------ 11 files changed, 47 insertions(+), 29 deletions(-) diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index f58367ca..6e07e383 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -26,6 +26,7 @@ import collections import codecs import json +import requests import gzip import cPickle as pickle import itertools @@ -63,7 +64,7 @@ logger = getLogger(__name__ ) # Each subclass will add to this DS_NAME_MAP = {} -def create_dataset(dataset_name, dataset_type = None, get_samplelist = True, group_name = None): +def create_dataset(dataset_name, rebuild=True, dataset_type = None, get_samplelist = True, group_name = None): if not dataset_type: dataset_type = Dataset_Getter(dataset_name) logger.debug("dataset_type", dataset_type) @@ -77,7 +78,7 @@ def create_dataset(dataset_name, dataset_type = None, get_samplelist = True, gro class Dataset_Types(object): - def __init__(self): + def __init__(self, rebuild=False): """Create a dictionary of samples where the value is set to Geno, Publish or ProbeSet. E.g. @@ -93,8 +94,10 @@ Publish or ProbeSet. E.g. """ self.datasets = {} - if USE_GN_SERVER: - data = gen_menu.gen_dropdown_json() + if rebuild: #ZS: May make this the only option + data = json.loads(requests.get("http://gn2.genenetwork.org/api/v_pre1/gen_dropdown").content) + logger.debug("THE DATA:", data) + #data = gen_menu.gen_dropdown_json() else: file_name = "wqflask/static/new/javascript/dataset_menu_structure.json" with open(file_name, 'r') as fh: @@ -119,12 +122,8 @@ Publish or ProbeSet. E.g. def __call__(self, name): return self.datasets[name] -def rebuild_dataset_ob(): - Dataset_Getter = Dataset_Types() - return Dataset_Getter - # Do the intensive work at startup one time only -Dataset_Getter = rebuild_dataset_ob() +Dataset_Getter = Dataset_Types() def create_datasets_list(): if USE_REDIS: @@ -705,7 +704,7 @@ class PhenotypeDataSet(DataSet): 'PublishXRef.Id'] # Figure out what display_fields is - self.display_fields = ['name', + self.display_fields = ['name', 'group_code', 'pubmed_id', 'pre_publication_description', 'post_publication_description', diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 322fb252..5fae34cf 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -352,7 +352,7 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False): if dataset.type == 'Publish': query = """ SELECT - PublishXRef.Id, Publication.PubMed_ID, + PublishXRef.Id, InbredSet.InbredSetCode, Publication.PubMed_ID, Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description, Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation, Phenotype.Lab_code, Phenotype.Submitter, Phenotype.Owner, Phenotype.Authorized_Users, @@ -361,12 +361,13 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False): Publication.Month, Publication.Year, PublishXRef.Sequence, Phenotype.Units, PublishXRef.comments FROM - PublishXRef, Publication, Phenotype, PublishFreeze + PublishXRef, Publication, Phenotype, PublishFreeze, InbredSet WHERE PublishXRef.Id = %s AND Phenotype.Id = PublishXRef.PhenotypeId AND Publication.Id = PublishXRef.PublicationId AND PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND + PublishXRef.InbredSetId = InbredSet.Id AND PublishFreeze.Id = %s """ % (trait.name, dataset.id) @@ -428,6 +429,7 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False): # holder = unicode(trait_info[i], "utf-8", "ignore") setattr(trait, field, holder) + trait.display_name = trait.name if dataset.type == 'Publish': trait.confidential = 0 if trait.pre_publication_description and not trait.pubmed_id: @@ -462,6 +464,9 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False): if trait.pubmed_id: trait.pubmed_link = webqtlConfig.PUBMEDLINK_URL % trait.pubmed_id + else: + if trait.group_code: + trait.display_name = trait.group_code + "_" + str(trait.name) if dataset.type == 'ProbeSet' and dataset.group: description_string = unicode(str(trait.description).strip(codecs.BOM_UTF8), 'utf-8') diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index b6580bbe..0df72b0d 100644 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -251,7 +251,8 @@ class PhenotypeSearch(DoSearch): WHERE PublishXRef.InbredSetId = %s and PublishXRef.PhenotypeId = Phenotype.Id and PublishXRef.PublicationId = Publication.Id - and PublishFreeze.Id = %s""" % ( + and PublishFreeze.Id = %s + ORDER BY PublishXRef.Id""" % ( from_clause, escape(str(self.dataset.group.id)), escape(str(self.dataset.id)))) @@ -262,7 +263,8 @@ class PhenotypeSearch(DoSearch): and PublishXRef.InbredSetId = %s and PublishXRef.PhenotypeId = Phenotype.Id and PublishXRef.PublicationId = Publication.Id - and PublishFreeze.Id = %s""" % ( + and PublishFreeze.Id = %s + ORDER BY PublishXRef.Id""" % ( from_clause, where_clause, escape(str(self.dataset.group.id)), diff --git a/wqflask/wqflask/gsearch.py b/wqflask/wqflask/gsearch.py index dbb77826..53e5f2b7 100644 --- a/wqflask/wqflask/gsearch.py +++ b/wqflask/wqflask/gsearch.py @@ -118,7 +118,8 @@ class GSearch(object): Publication.`Year`, Publication.`PubMed_ID`, PublishXRef.`LRS`, - PublishXRef.`additive` + PublishXRef.`additive`, + InbredSet.`InbredSetCode` FROM Species,InbredSet,PublishFreeze,PublishXRef,Phenotype,Publication WHERE PublishXRef.`InbredSetId`=InbredSet.`Id` AND PublishFreeze.`InbredSetId`=InbredSet.`Id` @@ -146,6 +147,7 @@ class GSearch(object): this_trait = {} this_trait['index'] = i + 1 this_trait['name'] = str(line[4]) + this_trait['display_name'] = this_trait['name'] this_trait['dataset'] = line[2] this_trait['dataset_fullname'] = line[3] this_trait['hmac'] = user_manager.data_hmac('{}:{}'.format(line[4], line[2])) @@ -167,6 +169,8 @@ class GSearch(object): this_trait['pubmed_link'] = webqtlConfig.PUBMEDLINK_URL % line[8] else: this_trait['pubmed_link'] = "N/A" + if line[12]: + this_trait['display_name'] = line[12] + "_" + str(this_trait['name']) this_trait['LRS_score_repr'] = "N/A" if line[10] != "" and line[10] != None: this_trait['LRS_score_repr'] = '%3.1f' % line[10] diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index 5a5a850b..2ac6d4b5 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -110,6 +110,10 @@ views.py). trait_dict['index'] = index + 1 this_trait = trait.GeneralTrait(dataset=self.dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) trait_dict['name'] = this_trait.name + if this_trait.dataset.type == "Publish": + trait_dict['display_name'] = this_trait.display_name + else: + trait_dict['display_name'] = this_trait.name trait_dict['dataset'] = this_trait.dataset.name trait_dict['hmac'] = user_manager.data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) if this_trait.dataset.type == "ProbeSet": diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 64597711..09004396 100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -45,7 +45,6 @@ class ShowTrait(object): if 'trait_id' in kw and kw['dataset'] != "Temp": self.temp_trait = False self.trait_id = kw['trait_id'] - data_set.rebuild_dataset_ob() helper_functions.get_species_dataset_trait(self, kw) elif 'group' in kw: self.temp_trait = True diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 1a4ff752..85127e99 100644 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -9,8 +9,10 @@
To study a record, click on its Record ID below.
Check records below and click Add button to add to selection.
To study a record, click on its ID below.
Check records below and click Add button to add to selection.