/
meta_globals.py
114 lines (87 loc) · 3.55 KB
/
meta_globals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
######################################
# #
# Byron C. Wallace #
# Tufts Medical Center #
# OpenMeta[analyst] #
# #
# Contains globals used #
# throughout. #
# #
######################################
import os
# number of digits to display
NUM_DIGITS = 3
# for calculating CIs (normal 95% CI)
MULT = 1.96
# completely made up. need an actual versioning system.
VERSION = .005
## For now we're going to hardcode which metrics are available.
# In the future, we may want to pull these out dynamically from
# the R side. But then meta-analytic methods would have either to
# only operate over the effects and variances or else themselves
# know how to compute arbitrary metrics.
# Binary metrics
BINARY_TWO_ARM_METRICS = ["OR", "RD", "RR", "AS", "YUQ", "YUY"]
BINARY_ONE_ARM_METRICS = ["PR", "PLN", "PLO", "PAS", "PFT"]
# Continuous metrics
CONTINUOUS_TWO_ARM_METRICS = ["MD", "SMD"]
CONTINUOUS_ONE_ARM_METRICS = ["TX Mean"]
# Sometimes it's useful to know if we're dealing with a one-arm outcome,
# in general
ONE_ARM_METRICS = BINARY_ONE_ARM_METRICS + CONTINUOUS_ONE_ARM_METRICS
TWO_ARM_METRICS = BINARY_TWO_ARM_METRICS + CONTINUOUS_TWO_ARM_METRICS
# Diagnostic metrics
DIAGNOSTIC_METRICS = ["Sens", "Spec", "PLR", "NLR", "DOR"]
DIAGNOSTIC_LOG_METRICS = ["PLR", "NLR", "DOR"]
# enumeration of data types and dictionaries mapping both ways
BINARY, CONTINUOUS, DIAGNOSTIC, OTHER = range(4)
# we need two types for covariates; factor and continuous. we'll use the
# above definition (enumerated as part of a general data type) for continuous
# and just define factor here.
FACTOR = 4
# making life easier
COV_INTS_TO_STRS = {4:"Factor", 1:"Continuous"}
STR_TO_TYPE_DICT = {u"binary":BINARY, u"continuous":CONTINUOUS,
u"diagnostic":DIAGNOSTIC, u"OTHER":OTHER}
TYPE_TO_STR_DICT = {BINARY:u"binary", CONTINUOUS:u"continuous", DIAGNOSTIC:u"diagnostic",
OTHER:u"OTHER", FACTOR:u"factor"}
# enumeration of meta-analytic types
VANILLA, NETWORK = range(2)
EMPTY_VALS = ("", None) # these indicate an empty row/cell
BASE_PATH = str(os.path.abspath(os.getcwd())) # where temporary R output should go
# this is the (local) path to a (pickled) dictionary containing
# user preferences
PREFS_PATH = "user_prefs.dict"
# this is a useful function sometimes.
none_to_str = lambda x: "" if x is None else x
# for diagnostic data -- this dictionary maps
# the mteric names as they appear in the UI/ure
# used here to the names used in the model.
# see get_diag_metrics_to_run.
DIAG_METRIC_NAMES_D = {
"sens":["Sens"],
"spec":["Spec"],
"dor":["DOR"],
"lr":["PLR", "NLR"]
}
DIAG_FIELDS_TO_RAW_INDICES = {"TP":0, "FN":1, "FP":2, "TN":3}
PATH_TO_HELP = "http://tuftscaes.org/open_meta/help/openMA_help.html"#os.path.join("doc", "openMA_help.html")
# list of methods with no forest plot parameters
METHODS_WITH_NO_FOREST_PLOT = ["diagnostic.hsroc", "diagnostic.bivariate.ml"]
'''
some useful static methods
'''
def seems_sane(xticks):
num_list = xticks.split(",")
if len(num_list) == 1:
return False
try:
num_list = [eval(x) for x in num_list]
except:
return False
return True
def check_plot_bound(bound):
try:
return float(bound)
except:
return False