-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidate_options.php
executable file
·164 lines (143 loc) · 3.91 KB
/
validate_options.php
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
//////////////////////////////////////////////
// Validate TNRS options passed to API
//
// Note that if multiple errors detected, only
// the last gets reported
//////////////////////////////////////////////
// For testing only
$sources_bak = $opt_arr['sources'];
$class_bak = $opt_arr['class'];
$mode_bak = $opt_arr['mode'];
/////////////////////////////////////////////
// TNRS options
/////////////////////////////////////////////
// Processing mode
if (array_key_exists('mode', $opt_arr)) {
$mode = $opt_arr['mode'];
if ( trim($mode) == "" ) {
$mode = $TNRS_DEF_MODE;
} else {
$valid = in_array($mode, $TNRS_MODES);
if ( $valid === false ) {
$err_msg="ERROR: Invalid option '$mode' for 'mode'";
$err_code=400; $err=true;
}
}
} else {
$mode = $TNRS_DEF_MODE;
}
// Taxonomic sources
if (array_key_exists('sources', $opt_arr)) {
$sources = $opt_arr['sources'];
if ( trim($sources) == "" ) {
$sources = $TNRS_DEF_SOURCES;
} else {
$src_arr = explode(",",$sources);
$valid = count(array_intersect($src_arr, $TNRS_SOURCES)) == count($src_arr);
if ( $valid === false ) {
$err_msg="ERROR: one or more invalid values '$sources' for option 'sources'";
$err_code=400; $err=true;
}
}
} else {
if ( $mode=='syn' ) {
$err_msg="ERROR: option 'sources' missing, required for mode='syn'";
$err_code=400; $err=true;
} else {
$sources = $TNRS_DEF_SOURCES;
}
}
// Classification
if (array_key_exists('class', $opt_arr)) {
$class = $opt_arr['class'];
if ( trim($class) == "" ) {
$class = $TNRS_DEF_CLASSIFICATION;
} else {
$valid = in_array($class, $TNRS_CLASSIFICATIONS);
if ( $valid === false ) {
$err_msg="ERROR: Invalid option '$class' for 'class'"; $err_code=400; $err=true;
}
}
} else {
$class = $TNRS_DEF_CLASSIFICATION;
}
// Constain matches by higher taxonomy
// CURRENTLY NOT IMPLEMENTED
if (array_key_exists('constr_ht', $opt_arr)) {
$constr_ht = $opt_arr['constr_ht'];
if ( trim($constr_ht) == "" ) {
$constr_ht = $TNRS_DEF_CONSTR_HT;
} else {
$valid = in_array($constr_ht, $TNRS_CONSTR_HT);
if ( $valid === false ) {
$err_msg="ERROR: Invalid option '$constr_ht' for 'constr_ht'";
$err_code=400; $err=true;
}
}
} else {
$constr_ht = $TNRS_DEF_CONSTR_HT;
}
// Constraint matches by taxonomic sources
// CURRENTLY NOT IMPLEMENTED
if (array_key_exists('constr_ts', $opt_arr)) {
$constr_ts = $opt_arr['constr_ts'];
if ( trim($constr_ts) == "" ) {
$constr_ts = $TNRS_DEF_CONSTR_TS;
} else {
$valid = in_array($constr_ts, $TNRS_CONSTR_TS);
if ( $valid === false ) {
$err_msg="ERROR: Invalid option '$constr_ts' for 'constr_ts'";
$err_code=400; $err=true;
}
}
} else {
$constr_ts = $TNRS_DEF_CONSTR_TS;
}
// Match accuracy
if (array_key_exists('acc', $opt_arr)) {
$acc = $opt_arr['acc'];
if ( trim($acc) == "" ) {
$acc = $TNRS_DEF_ACC;
} else {
$valid = false;
if ( is_numeric($acc) ) {
if ($acc>=$TNRS_ACC_MIN && $acc<=$TNRS_ACC_MAX ) $valid=true;
}
if ( $valid === false ) {
$err_msg="ERROR: Invalid value '$acc' for option '$acc'";
$err_code=400; $err=true;
}
}
} else {
$acc = $TNRS_DEF_ACC;
}
// Matches to return
if (array_key_exists('matches', $opt_arr)) {
$matches = $opt_arr['matches'];
if (trim($matches) == "" ) {
$matches = $TNRS_DEF_MATCHES;
} else {
$valid = in_array($matches, $TNRS_MATCHES);
if ( $valid === false ) {
$err_msg="ERROR: Invalid option '$matches' for 'matches'";
$err_code=400; $err=true;
}
}
} else {
$matches = $TNRS_DEF_MATCHES;
}
/////////////////////////////////////////////
// Other options
/////////////////////////////////////////////
// Number of batches for makeflow threads
// If not set, uses default $NBATCH
if (array_key_exists('batches', $opt_arr)) {
$batches = $opt_arr['batches'];
if ( $batches==intval($batches) ) {
$NBATCH = $batches;
} else {
$err_msg="ERROR: Invalid value '$batches' for option 'batches': must be an integer"; $err_code=400; $err=true;
}
}
?>