diff options
Diffstat (limited to 'wqflask/base')
-rw-r--r-- | wqflask/base/data_set.py | 113 | ||||
-rw-r--r-- | wqflask/base/trait.py | 19 | ||||
-rw-r--r-- | wqflask/base/webqtlConfig.py | 1 |
3 files changed, 100 insertions, 33 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index ebf3f021..1457ba8d 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -56,7 +56,7 @@ from pprint import pformat as pf from db.gn_server import menu_main from db.call import fetchall,fetchone,fetch1 -from utility.tools import USE_GN_SERVER, USE_REDIS, flat_files, flat_file_exists +from utility.tools import USE_GN_SERVER, USE_REDIS, flat_files, flat_file_exists, GN2_BASE_URL from utility.logger import getLogger logger = getLogger(__name__ ) @@ -64,10 +64,9 @@ logger = getLogger(__name__ ) # Each subclass will add to this DS_NAME_MAP = {} -def create_dataset(dataset_name, rebuild=True, dataset_type = None, get_samplelist = True, group_name = None): +def create_dataset(dataset_name, 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) dataset_ob = DS_NAME_MAP[dataset_type] dataset_class = globals()[dataset_ob] @@ -78,7 +77,7 @@ def create_dataset(dataset_name, rebuild=True, dataset_type = None, get_sampleli class Dataset_Types(object): - def __init__(self, rebuild=False): + def __init__(self): """Create a dictionary of samples where the value is set to Geno, Publish or ProbeSet. E.g. @@ -94,33 +93,95 @@ Publish or ProbeSet. E.g. """ self.datasets = {} - 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: - data = json.load(fh) - - for species in data['datasets']: - for group in data['datasets'][species]: - for dataset_type in data['datasets'][species][group]: - for dataset in data['datasets'][species][group][dataset_type]: - short_dataset_name = dataset[1] - if dataset_type == "Phenotypes": - new_type = "Publish" - elif dataset_type == "Genotypes": - new_type = "Geno" - else: - new_type = "ProbeSet" - self.datasets[short_dataset_name] = new_type + + data = Redis.get("dataset_structure") + if data: + self.datasets = json.loads(data) + else: #ZS: I don't think this should ever run unless Redis is emptied + try: + data = json.loads(requests.get(GN2_BASE_URL + "/api/v_pre1/gen_dropdown", timeout = 5).content) + for species in data['datasets']: + for group in data['datasets'][species]: + for dataset_type in data['datasets'][species][group]: + for dataset in data['datasets'][species][group][dataset_type]: + short_dataset_name = dataset[1] + if dataset_type == "Phenotypes": + new_type = "Publish" + elif dataset_type == "Genotypes": + new_type = "Geno" + else: + new_type = "ProbeSet" + self.datasets[short_dataset_name] = new_type + except: + pass + + Redis.set("dataset_structure", json.dumps(self.datasets)) # Set LOG_LEVEL_DEBUG=5 to see the following: logger.debugf(5, "datasets",self.datasets) def __call__(self, name): - return self.datasets[name] + if name not in self.datasets: + mrna_expr_query = """ + SELECT + ProbeSetFreeze.Id + FROM + ProbeSetFreeze + WHERE + ProbeSetFreeze.Name = "{0}" + """.format(name) + + results = g.db.execute(mrna_expr_query).fetchall() + if len(results): + self.datasets[name] = "ProbeSet" + Redis.set("dataset_structure", json.dumps(self.datasets)) + return self.datasets[name] + + group_name = name.replace("Publish", "") + + pheno_query = """SELECT InfoFiles.GN_AccesionId + FROM InfoFiles, PublishFreeze, InbredSet + WHERE InbredSet.Name = '{0}' AND + PublishFreeze.InbredSetId = InbredSet.Id AND + InfoFiles.InfoPageName = PublishFreeze.Name""".format(group_name) + + results = g.db.execute(pheno_query).fetchall() + if len(results): + self.datasets[name] = "Publish" + Redis.set("dataset_structure", json.dumps(self.datasets)) + return self.datasets[name] + + #ZS: For when there isn't an InfoFiles ID; not sure if this and the preceding query are both necessary + other_pheno_query = """SELECT PublishFreeze.Name + FROM PublishFreeze, InbredSet + WHERE InbredSet.Name = '{}' AND + PublishFreeze.InbredSetId = InbredSet.Id""".format(group_name) + + results = g.db.execute(other_pheno_query).fetchall() + if len(results): + self.datasets[name] = "Publish" + Redis.set("dataset_structure", json.dumps(self.datasets)) + return self.datasets[name] + + geno_query = """ + SELECT + GenoFreeze.Id + FROM + GenoFreeze + WHERE + GenoFreeze.Name = "{0}" + """.format(name) + + results = g.db.execute(geno_query).fetchall() + if len(results): + self.datasets[name] = "Geno" + Redis.set("dataset_structure", json.dumps(self.datasets)) + return self.datasets[name] + + #ZS: It shouldn't ever reach this + return None + else: + return self.datasets[name] # Do the intensive work at startup one time only Dataset_Getter = Dataset_Types() diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 5525472e..1b7cb23c 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -5,15 +5,15 @@ import resource import codecs import requests -import redis -Redis = redis.StrictRedis() - from base import webqtlConfig from base.webqtlCaseData import webqtlCaseData from base.data_set import create_dataset from db import webqtlDatabaseFunction from utility import webqtlUtil from utility import hmac +from utility.tools import GN2_BASE_URL +from utility.redis_tools import get_redis_conn +Redis = get_redis_conn() from wqflask import app @@ -135,9 +135,9 @@ class GeneralTrait(object): alias = 'Not available' if self.symbol: - human_response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + self.symbol.upper()) - mouse_response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + self.symbol.capitalize()) - other_response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + self.symbol.lower()) + human_response = requests.get(GN2_BASE_URL + "gn3/gene/aliases/" + self.symbol.upper()) + mouse_response = requests.get(GN2_BASE_URL + "gn3/gene/aliases/" + self.symbol.capitalize()) + other_response = requests.get(GN2_BASE_URL + "gn3/gene/aliases/" + self.symbol.lower()) if human_response and mouse_response and other_response: alias_list = json.loads(human_response.content) + json.loads(mouse_response.content) + json.loads(other_response.content) @@ -348,8 +348,13 @@ def jsonable_table_row(trait, dataset_name, index): def retrieve_trait_info(trait, dataset, get_qtl_info=False): assert dataset, "Dataset doesn't exist" - + if dataset.type == 'Publish': + resource_id = hmac.data_hmac("{}:{}".format(dataset.id, trait.name)) + + the_url = "http://localhost:8080/run_action/?resource={}&user={}&branch=data&action=view".format(resource_id, g.user_session.user_id) + trait_data = json.loads(requests.get("http://localhost:8080/run_action/?resource={}&user={}&branch=data&action=view".format(resource_id, g.user_session.user_id))) + query = """ SELECT PublishXRef.Id, InbredSet.InbredSetCode, Publication.PubMed_ID, diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py index 018d5d54..55407123 100644 --- a/wqflask/base/webqtlConfig.py +++ b/wqflask/base/webqtlConfig.py @@ -58,6 +58,7 @@ PROTEIN_ATLAS_URL = "http://www.proteinatlas.org/search/%s" OPEN_TARGETS_URL = "https://genetics.opentargets.org/gene/%s" UNIPROT_URL = "https://www.uniprot.org/uniprot/%s" RGD_URL = "https://rgd.mcw.edu/rgdweb/elasticResults.html?term=%s&category=Gene&species=%s" +PHENOGEN_URL = "https://phenogen.org/gene.jsp?speciesCB=Rn&auto=Y&geneTxt=%s&genomeVer=rn6§ion=geneEQTL" # Temporary storage (note that this TMPDIR can be set as an # environment variable - use utility.tools.TEMPDIR when you |