diff options
author | Zachary Sloan | 2014-07-21 16:07:42 +0000 |
---|---|---|
committer | Zachary Sloan | 2014-07-21 16:07:42 +0000 |
commit | d952a23662eb4c46041be3945b5c3ccacf5506b6 (patch) | |
tree | 00750c5c88fb7dc6f300a148ea40f95a7b46be3a /wqflask/maintenance/dataset/utilities.py | |
parent | 818de422631392c246646b52a5b227d23153e667 (diff) | |
parent | c424db452c243c6f0f64ee58d2d7baeb147dd3c8 (diff) | |
download | genenetwork2-d952a23662eb4c46041be3945b5c3ccacf5506b6.tar.gz |
Merge /home/lei/gene
Diffstat (limited to 'wqflask/maintenance/dataset/utilities.py')
-rw-r--r-- | wqflask/maintenance/dataset/utilities.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/wqflask/maintenance/dataset/utilities.py b/wqflask/maintenance/dataset/utilities.py new file mode 100644 index 00000000..787c9481 --- /dev/null +++ b/wqflask/maintenance/dataset/utilities.py @@ -0,0 +1,89 @@ +import MySQLdb +import re +import ConfigParser + +def get_cursor(): + host = 'localhost' + user = 'gn2' + passwd = 'UhHJuiS6gC8hj4a' + db = 'db_webqtl' + con = MySQLdb.Connect(db=db, host=host, user=user, passwd=passwd) + cursor = con.cursor() + return cursor, con + +def clearspaces(s, default=None): + if s: + s = re.sub('\s+', ' ', s) + s = s.strip() + return s + else: + return default + +def to_dic(keys, values): + dic = {} + for i in range(len(keys)): + key = keys[i] + value = values[i] + dic[key] = value + return dic + +def overlap(dic1, dic2): + keys = [] + values1 = [] + values2 = [] + for key in dic1.keys(): + if key in dic2: + value1 = dic1[key] + value2 = dic2[key] + if value1 and value2: + keys.append(key) + values1.append(value1) + values2.append(value2) + return keys, values1, values2 + +def to_db_string(s, default): + if s: + s = s.strip() + if len(s) == 0: + return default + elif s == 'x': + return default + else: + return s + else: + return default + +def to_db_float(s, default): + if s: + s = s.strip() + if len(s) == 0: + return default + elif s == 'x': + return default + else: + try: + return float(s) + except: + return default + else: + return default + +def to_db_int(s, default): + if s: + s = s.strip() + if len(s) == 0: + return default + elif s == 'x': + return default + else: + try: + return int(s) + except: + return default + else: + return default + +def get_config(configfile): + config = ConfigParser.ConfigParser() + config.read(configfile) + return config |