diff options
author | Lei Yan | 2013-07-03 20:56:45 +0000 |
---|---|---|
committer | Lei Yan | 2013-07-03 20:56:45 +0000 |
commit | 76ad4e6ae15f4d42ddd420cd14936c149aa0bb31 (patch) | |
tree | 7f82df4895e80788e5b9e9fb07b0d7adb97a0738 /wqflask | |
parent | d95eff3f0410ec5cddd82398f6db0fffa5d9be0b (diff) | |
parent | 253df1a5adb060df3202de5b80a5065a3614e368 (diff) | |
download | genenetwork2-76ad4e6ae15f4d42ddd420cd14936c149aa0bb31.tar.gz |
Merge /home/zas1024/gene
Diffstat (limited to 'wqflask')
-rwxr-xr-x | wqflask/base/data_set.py | 105 | ||||
-rw-r--r-- | wqflask/base/species.py | 10 | ||||
-rw-r--r-- | wqflask/cfg/default_settings.py | 2 | ||||
-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/static/new/javascript/login.coffee | 6 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/login.js | 5 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/thank_you.coffee | 4 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/thank_you.js | 10 | ||||
-rw-r--r-- | wqflask/wqflask/templates/admin/group_manager.html | 83 | ||||
-rw-r--r-- | wqflask/wqflask/templates/base.html | 6 | ||||
-rw-r--r-- | wqflask/wqflask/templates/security/thank_you.html | 8 | ||||
-rw-r--r-- | wqflask/wqflask/user_manager.py | 16 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 32 |
14 files changed, 256 insertions, 40 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 1668940c..03b24230 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,36 @@ 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!!!") + datasets = pickle.loads(result) + + else: + datasets = list() + with Bench("Creating DataSets object"): + 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)) + dataset = create_dataset(result.Name, dataset_type) + datasets.append(dataset) + + Redis.set(key, pickle.dumps(datasets, pickle.HIGHEST_PROTOCOL)) + Redis.expire(key, 60*60) + + return datasets + + def create_in_clause(items): """Create an in clause for mysql""" in_clause = ', '.join("'{}'".format(x) for x in mescape(*items)) @@ -167,8 +202,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 +257,27 @@ class DatasetGroup(object): self.samplelist = list(genotype.prgy) +#class DataSets(object): +# """Builds a list of DataSets""" +# +# def __init__(self): +# self.datasets = list() +# + + + #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 +290,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 +351,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 +359,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 +998,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/cfg/default_settings.py b/wqflask/cfg/default_settings.py index 96f7f1a5..e638a9c0 100644 --- a/wqflask/cfg/default_settings.py +++ b/wqflask/cfg/default_settings.py @@ -13,3 +13,5 @@ SECURITY_REGISTERABLE = True SECURITY_RECOVERABLE = True SECURITY_EMAIL_SENDER = "no-reply@genenetwork.org" + +SECURITY_POST_LOGIN_VIEW = "/thank_you" diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 03059d68..11eca936 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/static/new/javascript/login.coffee b/wqflask/wqflask/static/new/javascript/login.coffee index c49353d5..15dafd9a 100644 --- a/wqflask/wqflask/static/new/javascript/login.coffee +++ b/wqflask/wqflask/static/new/javascript/login.coffee @@ -13,8 +13,8 @@ $ -> - - $(document).on("click", ".modalize", modalize) + $(document).one("click", ".modalize", modalize) + console.log("Modalized click!!!") form_success = (data) -> $.colorbox( @@ -39,4 +39,4 @@ $ -> ) - $("form").on("submit", submit_form) + $("#colorbox form").on("submit", submit_form) diff --git a/wqflask/wqflask/static/new/javascript/login.js b/wqflask/wqflask/static/new/javascript/login.js index 6c6120ec..ce301353 100644 --- a/wqflask/wqflask/static/new/javascript/login.js +++ b/wqflask/wqflask/static/new/javascript/login.js @@ -14,7 +14,8 @@ } }); }; - $(document).on("click", ".modalize", modalize); + $(document).one("click", ".modalize", modalize); + console.log("Modalized click!!!"); form_success = function(data) { return $.colorbox({ open: true, @@ -38,7 +39,7 @@ success: form_success }); }; - return $("form").on("submit", submit_form); + return $("#colorbox form").on("submit", submit_form); }); }).call(this); diff --git a/wqflask/wqflask/static/new/javascript/thank_you.coffee b/wqflask/wqflask/static/new/javascript/thank_you.coffee new file mode 100644 index 00000000..975f85c6 --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/thank_you.coffee @@ -0,0 +1,4 @@ +$ -> + console.log("Starting transform") + $('#login_out').text('Sign out').attr('href', '/logout').removeClass('modalize') + console.log("Transformed to sign out I hope") diff --git a/wqflask/wqflask/static/new/javascript/thank_you.js b/wqflask/wqflask/static/new/javascript/thank_you.js new file mode 100644 index 00000000..2871dd2d --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/thank_you.js @@ -0,0 +1,10 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + + $(function() { + console.log("Starting transform"); + $('#login_out').text('Sign out').attr('href', '/logout').removeClass('modalize'); + return console.log("Transformed to sign out I hope"); + }); + +}).call(this); diff --git a/wqflask/wqflask/templates/admin/group_manager.html b/wqflask/wqflask/templates/admin/group_manager.html new file mode 100644 index 00000000..df3eda33 --- /dev/null +++ b/wqflask/wqflask/templates/admin/group_manager.html @@ -0,0 +1,83 @@ +{% extends "base.html" %} +{% block title %}Group Manager{% endblock %} +{% block content %} +<!-- Start of body --> + <header class="jumbotron subhead" id="overview"> + <div class="container"> + <h1>Group Manager</h1> + </div> + </header> + + <div class="container"> + <div class="page-header"> + + </div> + <form> + <div class="control-group"> + <b>Group Name: </b> + <div class="input-append"> + <input type="text" name="group_name"> + <button type="submit" class="btn btn-primary">Save</button> + </div> + </div> + + <table id="dataset_list" class="table table-hover"> + <thead> + <tr> + <th>Read</th> + <th>Type</th> + <th>ID</th> + <th>Name</th> + <th>Full Name</th> + </tr> + </thead> + {% for dataset in datasets %} + <tr> + <td><input type="checkbox" name="read" value="{{ dataset.type }}:{{ dataset.name }}"></td> + <td>{{ dataset.type }}</td> + <td>{{ dataset.id }}</td> + <td>{{ dataset.name }}</td> + <td>{{ dataset.fullname }}</td> + </tr> + {% endfor %} + </table> + </form> + </div> + +<!-- End of body --> + +{% endblock %} + +{% block js %} + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script> + + <script type="text/javascript" charset="utf-8"> + $(document).ready( function () { + console.time("Creating table"); + $('#dataset_list').dataTable( { + "sDom": "Tftipr", + "oTableTools": { + "aButtons": [ + "copy", + "print", + { + "sExtends": "collection", + "sButtonText": 'Save <span class="caret" />', + "aButtons": [ "csv", "xls", "pdf" ] + } + ], + "sSwfPath": "/static/packages/TableTools/media/swf/copy_csv_xls_pdf.swf" + }, + "iDisplayLength": 50, + "bLengthChange": true, + "bDeferRender": true, + "bSortClasses": false + } ); + console.timeEnd("Creating table"); + }); + </script> +{% endblock %}
\ No newline at end of file diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 741c5425..cbed5859 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -70,9 +70,9 @@ </li> <li class=""> {% if g.identity.name=="anon" %} - <a id="login" class="modalize" href="/login">Sign in</a> + <a id="login_out" class="modalize" href="/login">Sign in</a> {% else %} - <a href="/logout">Sign out</a> + <a id="login_out" href="/logout">Sign out</a> {% endif %} </li> </ul> @@ -180,7 +180,7 @@ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script> <script language="javascript" type="text/javascript" src="/static/packages/colorbox/jquery.colorbox.js"></script> -<!-- <script type="text/javascript" src="/static/new/javascript/login.js"></script>--> + <script type="text/javascript" src="/static/new/javascript/login.js"></script> {% block js %} {% endblock %} diff --git a/wqflask/wqflask/templates/security/thank_you.html b/wqflask/wqflask/templates/security/thank_you.html new file mode 100644 index 00000000..dd6c7297 --- /dev/null +++ b/wqflask/wqflask/templates/security/thank_you.html @@ -0,0 +1,8 @@ +{% from "security/_macros.html" import render_only_errors %} +{% include "security/_messages.html" %} + +<div class="security_box"> + <h4>Thank you for signing in!</h4> +</div> + +<script src="/static/new/javascript/thank_you.js"></script> diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index b8ebc71f..9e666bbd 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -13,6 +13,8 @@ from flask import Flask, g from pprint import pformat as pf +from base.data_set import create_datasets_list + #from app import db print("globals are:", globals()) @@ -32,6 +34,20 @@ class UserManager(object): #print("user is:", user) self.user = model.User.query.get(self.user_id) print("user is:", self.user) + datasets = create_datasets_list() + for dataset in datasets: + if not dataset.check_confidentiality(): + continue + print("\n Name:", dataset.name) + print(" Type:", dataset.type) + print(" ID:", dataset.id) + print(" Confidential:", dataset.check_confidentiality()) + #print(" ---> self.datasets:", self.datasets) + + +class GroupsManager(object): + def __init__(self, kw): + self.datasets = create_datasets_list() class RolesManager(object): diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index b9aa3acf..813075b8 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, pickle.HIGHEST_PROTOCOL)) + # Redis.expire(key, 2*60) + #print("[orange] ds:", ds.datasets) return render_template("index_page.html") @app.route("/data_sharing") @@ -87,7 +100,7 @@ def search_page(): print("key is:", pf(key)) with Bench("Loading cache"): result = Redis.get(key) - + if result: print("Cache hit!!!") with Bench("Loading results"): @@ -97,9 +110,9 @@ def search_page(): print("request.args is", request.args) the_search = search_results.SearchResultPage(request.args) result = the_search.__dict__ - + print("result: ", pf(result)) - Redis.set(key, pickle.dumps(result)) + Redis.set(key, pickle.dumps(result, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60*60) if result['quick']: @@ -219,7 +232,7 @@ def marker_regression_page(): # print(" ---**--- {}: {}".format(type(template_vars.__dict__[item]), item)) #causeerror - Redis.set(key, pickle.dumps(result)) + Redis.set(key, pickle.dumps(result, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60*60) with Bench("Rendering template"): @@ -249,11 +262,17 @@ def sharing_info_page(): return template_vars +# Take this out or secure it before going into production @app.route("/get_temp_data") def get_temp_data(): temp_uuid = request.args['key'] return flask.jsonify(temp_data.TempData(temp_uuid).get_all()) + +@app.route("/thank_you") +def thank_you(): + return render_template("security/thank_you.html") + @app.route("/manage/users") def manage_users(): template_vars = user_manager.UsersManager() @@ -264,6 +283,11 @@ def manage_user(): template_vars = user_manager.UserManager(request.args) return render_template("admin/ind_user_manager.html", **template_vars.__dict__) +@app.route("/manage/groups") +def manage_groups(): + template_vars = user_manager.GroupsManager(request.args) + return render_template("admin/group_manager.html", **template_vars.__dict__) + def json_default_handler(obj): '''Based on http://stackoverflow.com/a/2680060/1175849''' |