diff options
author | pjotrp | 2015-05-12 15:35:41 -0500 |
---|---|---|
committer | pjotrp | 2015-05-12 15:35:41 -0500 |
commit | dcb0ef4e2b41d189d59d7d49c190ada02be45e0f (patch) | |
tree | 7a9d55455b9c17c90cc7496ef2672f009f25c5cd /wqflask/maintenance | |
parent | f228118ac112f3ebab5faf41ac9e1bc2a6e2c0fa (diff) | |
parent | a544231453be26339d9b1c45888f1e7fffa1ca2e (diff) | |
download | genenetwork2-dcb0ef4e2b41d189d59d7d49c190ada02be45e0f.tar.gz |
Merge branch 'master' of https://github.com/zsloan/genenetwork2
Diffstat (limited to 'wqflask/maintenance')
-rwxr-xr-x | wqflask/maintenance/gen_select_dataset.py | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/wqflask/maintenance/gen_select_dataset.py b/wqflask/maintenance/gen_select_dataset.py index 694efeca..a2ad8c91 100755 --- a/wqflask/maintenance/gen_select_dataset.py +++ b/wqflask/maintenance/gen_select_dataset.py @@ -35,7 +35,9 @@ from __future__ import print_function, division #config = config.Config(cdict).from_envvar('WQFLASK_SETTINGS') #print("cdict is:", cdict) -import our_settings +import sys +sys.path.append("/home/zas1024/") +import zach_settings import MySQLdb @@ -47,7 +49,7 @@ import urlparse from pprint import pformat as pf -#Engine = sa.create_engine(our_settings.SQLALCHEMY_DATABASE_URI) +#Engine = sa.create_engine(zach_settings.SQLALCHEMY_DATABASE_URI) # build MySql database connection @@ -60,7 +62,7 @@ from pprint import pformat as pf def parse_db_uri(db_uri): """Converts a database URI to the db name, host name, user name, and password""" - parsed_uri = urlparse.urlparse(our_settings.DB_URI) + parsed_uri = urlparse.urlparse(zach_settings.DB_URI) db_conn_info = dict( db = parsed_uri.path[1:], @@ -104,12 +106,48 @@ def get_types(groups): types[species] = {} for group_name, _group_full_name in group_dict: # make group an alias to shorten the code - types[species][group_name] = [("Phenotypes", "Phenotypes"), ("Genotypes", "Genotypes")] - types[species][group_name] += build_types(species, group_name) + #types[species][group_name] = [("Phenotypes", "Phenotypes"), ("Genotypes", "Genotypes")] + if phenotypes_exist(group_name): + types[species][group_name] = [("Phenotypes", "Phenotypes")] + if genotypes_exist(group_name): + if group_name in types[species]: + types[species][group_name] += [("Genotypes", "Genotypes")] + else: + types[species][group_name] = [("Genotypes", "Genotypes")] + if group_name in types[species]: + types[species][group_name] += build_types(species, group_name) + else: + types[species][group_name] = build_types(species, group_name) return types +def phenotypes_exist(group_name): + print("group_name:", group_name) + Cursor.execute("""select Name from PublishFreeze + where PublishFreeze.Name = %s""", (group_name+"Publish")) + + results = Cursor.fetchone() + print("RESULTS:", results) + + if results != None: + return True + else: + return False + +def genotypes_exist(group_name): + print("group_name:", group_name) + Cursor.execute("""select Name from GenoFreeze + where GenoFreeze.Name = %s""", (group_name+"Geno")) + + results = Cursor.fetchone() + print("RESULTS:", results) + + if results != None: + return True + else: + return False + def build_types(species, group): """Fetches tissues @@ -196,7 +234,7 @@ def build_datasets(species, group, type_name): def main(): """Generates and outputs (as json file) the data for the main dropdown menus on the home page""" - parse_db_uri(our_settings.DB_URI) + parse_db_uri(zach_settings.DB_URI) species = get_species() groups = get_groups(species) @@ -236,6 +274,6 @@ def _test_it(): #print("build_datasets:", pf(datasets)) if __name__ == '__main__': - Conn = MySQLdb.Connect(**parse_db_uri(our_settings.DB_URI)) + Conn = MySQLdb.Connect(**parse_db_uri(zach_settings.DB_URI)) Cursor = Conn.cursor() main() |