diff options
Diffstat (limited to 'wqflask')
-rwxr-xr-x | wqflask/base/data_set.py | 99 | ||||
-rw-r--r-- | wqflask/base/species.py | 10 | ||||
-rw-r--r-- | wqflask/wqflask/correlation/show_corr_results.py | 7 | ||||
-rw-r--r-- | wqflask/wqflask/search_results.py | 2 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 13 |
5 files changed, 103 insertions, 28 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 1668940c..803cbc4f 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -27,8 +27,12 @@ import string import collections import json +import cPickle as pickle import itertools +from redis import Redis +Redis = Redis() + from flask import Flask, g import reaper @@ -46,17 +50,18 @@ from pprint import pformat as pf # Used by create_database to instantiate objects DS_NAME_MAP = {} -def create_dataset(dataset_name): +def create_dataset(dataset_name, dataset_type = None): #print("dataset_name:", dataset_name) - query = """ - SELECT DBType.Name - FROM DBList, DBType - WHERE DBList.Name = '{}' and - DBType.Id = DBList.DBTypeId - """.format(escape(dataset_name)) - #print("query is: ", pf(query)) - dataset_type = g.db.execute(query).fetchone().Name + if not dataset_type: + query = """ + SELECT DBType.Name + FROM DBList, DBType + WHERE DBList.Name = '{}' and + DBType.Id = DBList.DBTypeId + """.format(escape(dataset_name)) + #print("query is: ", pf(query)) + dataset_type = g.db.execute(query).fetchone().Name #dataset_type = cursor.fetchone()[0] #print("[blubber] dataset_type:", pf(dataset_type)) @@ -69,6 +74,19 @@ def create_dataset(dataset_name): dataset_class = globals()[dataset_ob] return dataset_class(dataset_name) +def create_datasets_list(): + key = "all_datasets" + result = Redis.get(key) + if result: + print("Cache hit!!!") + result = pickle.loads(result) + else: + with Bench("Creating DataSets object"): + ds = DataSets() + Redis.set(key, pickle.dumps(result)) + Redis.expire(key, 2*60) + + def create_in_clause(items): """Create an in clause for mysql""" in_clause = ', '.join("'{}'".format(x) for x in mescape(*items)) @@ -167,8 +185,8 @@ class DatasetGroup(object): self.incparentsf1 = False self.allsamples = None - - + + def get_markers(self): #print("self.species is:", self.species) if self.species == "human": @@ -222,6 +240,38 @@ class DatasetGroup(object): self.samplelist = list(genotype.prgy) +class DataSets(object): + """Builds a list of DataSets""" + + def __init__(self): + self.datasets = list() + + type_dict = {'Publish': 'PublishFreeze', + 'ProbeSet': 'ProbeSetFreeze', + 'Geno': 'GenoFreeze'} + + for dataset_type in type_dict: + query = "SELECT Name FROM {}".format(type_dict[dataset_type]) + for result in g.db.execute(query).fetchall(): + #The query at the beginning of this function isn't necessary here, but still would + #rather just reuse it + print("type: {}\tname: {}".format(dataset_type, result.Name)) + create_dataset(result.Name, dataset_type) + + + #query = """SELECT Name FROM ProbeSetFreeze + # UNION + # SELECT Name From PublishFreeze + # UNION + # SELECT Name From GenoFreeze""" + # + #for result in g.db.execute(query).fetchall(): + # dataset = DataSet(result.Name) + # self.datasets.append(dataset) + +#ds = DataSets() +#print("[orange] ds:", ds.datasets) + class DataSet(object): """ DataSet class defines a dataset in webqtl, can be either Microarray, @@ -234,6 +284,8 @@ class DataSet(object): assert name, "Need a name" self.name = name self.id = None + self.shortname = None + self.fullname = None self.type = None self.setup() @@ -293,7 +345,7 @@ class DataSet(object): self.name, self.name, self.name)) - #print("query_args are:", query_args) + print("query_args are:", query_args) #print(""" # SELECT Id, Name, FullName, ShortName @@ -301,17 +353,17 @@ class DataSet(object): # WHERE public > %s AND # (Name = '%s' OR FullName = '%s' OR ShortName = '%s') # """ % (query_args)) - - self.id, self.name, self.fullname, self.shortname = g.db.execute(""" - SELECT Id, Name, FullName, ShortName - FROM %s - WHERE public > %s AND - (Name = '%s' OR FullName = '%s' OR ShortName = '%s') - """ % (query_args)).fetchone() - - #self.cursor.execute(query) - #self.id, self.name, self.fullname, self.shortname = self.cursor.fetchone() + try: + self.id, self.name, self.fullname, self.shortname = g.db.execute(""" + SELECT Id, Name, FullName, ShortName + FROM %s + WHERE public > %s AND + (Name = '%s' OR FullName = '%s' OR ShortName = '%s') + """ % (query_args)).fetchone() + except TypeError: + print("Dataset {} is not yet available in GeneNetwork.".format(self.name)) + pass class PhenotypeDataSet(DataSet): DS_NAME_MAP['Publish'] = 'PhenotypeDataSet' @@ -940,6 +992,5 @@ def geno_mrna_confidentiality(ob): authorized_users) = result.fetchall()[0] if confidential: - # Allow confidential data later - NoConfindetialDataForYouTodaySorry + return True diff --git a/wqflask/base/species.py b/wqflask/base/species.py index 191f4535..ebc2bfed 100644 --- a/wqflask/base/species.py +++ b/wqflask/base/species.py @@ -56,6 +56,7 @@ class Chromosomes(object): InbredSet.Name = %s Order by OrderId """, self.dataset.group.name).fetchall() + print("group: ", self.dataset.group.name) print("bike:", results) for item in results: @@ -68,9 +69,14 @@ class Chromosomes(object): def set_mb_graph_interval(self): """Empirical megabase interval""" + if self.chromosomes: + self.mb_graph_interval = self.get_genome_mb_length()/(len(self.chromosomes)*12) + else: + self.mb_graph_interval = 1 + #if self.chromosomes: - assert self.chromosomes, "Have to add some code back in apparently to set it to 1" - self.mb_graph_interval = self.get_genome_mb_length()/(len(self.chromosomes)*12) + #assert self.chromosomes, "Have to add some code back in apparently to set it to 1" + #self.mb_graph_interval = self.get_genome_mb_length()/(len(self.chromosomes)*12) #else: #self.mb_graph_interval = 1 diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 1410ae0c..3b47e970 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -203,6 +203,13 @@ class CorrelationResults(object): # mb = trait_object.mb # ) + + + trait_list = self.getTissueCorrelationByList( primary_trait_symbol = self.this_trait.symbol, + corr_results = self.correlation_results, + TissueProbeSetFreezeId = 1, + method=1) + #XZ, 09/18/2008: get all information about the user selected database. #target_db_name = fd.corr_dataset #self.target_db_name = start_vars['corr_dataset'] diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index f76af374..504a67ce 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -162,8 +162,6 @@ class SearchResultPage(object): import redis Redis = redis.Redis() - - #def get_group_species_tree(self): # self.species_groups = collections.default_dict(list) # for key in self.results: diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 90be7a71..bd56f7a9 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -27,6 +27,7 @@ from flask import render_template, request, make_response, Response, Flask, g, c from wqflask import search_results from base.data_set import DataSet # Used by YAML in marker_regression +from base.data_set import create_datasets_list from wqflask.show_trait import show_trait from wqflask.show_trait import export_trait_data from wqflask.marker_regression import marker_regression @@ -53,6 +54,18 @@ def connect_db(): @app.route("/") def index_page(): print("Sending index_page") + create_datasets_list() + #key = "all_datasets" + #result = Redis.get(key) + #if result: + # print("Cache hit!!!") + # result = pickle.loads(result) + #else: + # with Bench("Creating DataSets object"): + # ds = DataSets() + # Redis.set(key, pickle.dumps(result)) + # Redis.expire(key, 2*60) + #print("[orange] ds:", ds.datasets) return render_template("index_page.html") @app.route("/data_sharing") |