aboutsummaryrefslogtreecommitdiff
path: root/wqflask/maintenance
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/maintenance')
-rwxr-xr-xwqflask/maintenance/gen_select_dataset.py52
-rwxr-xr-xwqflask/maintenance/get_group_samplelists.py18
2 files changed, 61 insertions, 9 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()
diff --git a/wqflask/maintenance/get_group_samplelists.py b/wqflask/maintenance/get_group_samplelists.py
index c9ec3872..b8397b47 100755
--- a/wqflask/maintenance/get_group_samplelists.py
+++ b/wqflask/maintenance/get_group_samplelists.py
@@ -17,8 +17,13 @@ def process_genofiles(geno_dir=webqtlConfig.GENODIR):
sample_list = get_samplelist(geno_file)
-def get_samplelist(geno_file):
- genofilename = os.path.join(webqtlConfig.GENODIR, geno_file)
+def get_samplelist(file_type, geno_file):
+ if file_type == "geno":
+ return get_samplelist_from_geno(geno_file)
+ elif file_type == "plink":
+ return get_samplelist_from_plink(geno_file)
+
+def get_samplelist_from_geno(genofilename):
if os.path.isfile(genofilename + '.gz'):
genofilename += '.gz'
genofile = gzip.open(genofilename)
@@ -41,3 +46,12 @@ def get_samplelist(geno_file):
samplelist = headers[3:]
return samplelist
+def get_samplelist_from_plink(genofilename):
+ genofile = open(genofilename)
+
+ samplelist = []
+ for line in genofile:
+ line = line.split(" ")
+ samplelist.append(line[0])
+
+ return samplelist \ No newline at end of file