aboutsummaryrefslogtreecommitdiff
path: root/scripts/maintenance/utilities.py
diff options
context:
space:
mode:
authorArthur Centeno2021-10-25 21:04:23 +0000
committerArthur Centeno2021-10-25 21:04:23 +0000
commit499a80f138030c4de1629c043c8f9401a99894ea (patch)
tree449dcae965d13f966fb6d52625fbc86661c8c6a0 /scripts/maintenance/utilities.py
parent6151faa9ea67af4bf4ea95fb681a9dc4319474b6 (diff)
parent700802303e5e8221a9d591ba985d6607aa61e1ce (diff)
downloadgenenetwork2-499a80f138030c4de1629c043c8f9401a99894ea.tar.gz
Merge github.com:genenetwork/genenetwork2 into acenteno
Diffstat (limited to 'scripts/maintenance/utilities.py')
-rw-r--r--scripts/maintenance/utilities.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/scripts/maintenance/utilities.py b/scripts/maintenance/utilities.py
new file mode 100644
index 00000000..886410c2
--- /dev/null
+++ b/scripts/maintenance/utilities.py
@@ -0,0 +1,89 @@
+import MySQLdb
+import re
+import configparser
+
+def get_cursor():
+ host = 'tux.uthsc.edu'
+ user = 'webqtlout'
+ passwd = 'webqtlout'
+ 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