-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_schema_types.config
159 lines (144 loc) · 5.1 KB
/
custom_schema_types.config
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
/**
* This custom schema namespace implements a custom type for checking input BAMs for call-gSNP
*/
custom_schema_types {
allowed_input_types = [
'BAM'
]
allowed_bam_types = [
'normal',
'tumor'
]
allowed_resource_types = [
'memory',
'cpus'
]
/**
* Check that input types are in allowed list
*/
check_input_type_keys = { List given, String name, List choices=custom_schema_types.allowed_input_types ->
for (elem in given) {
if (!(elem in choices)) {
throw new Exception("Invalid paramter ${name}. Valid types: ${choices}.")
}
}
}
/**
* Check if input is a String or GString
*/
is_string = { val ->
return (val in String || val in GString)
}
/**
* Check if given input is a Namespace
*/
check_if_namespace = { val, String name ->
if (!(val in Map)) {
throw new Exception("${name} should be a Namespace, not ${val.getClass()}.")
}
}
/**
* Check if given input is a list
*/
check_if_list = { val, String name ->
if (!(val in List || val in Set)) {
throw new Exception("${name} should be a List, not ${val.getClass()}.")
}
}
/**
* Check if given input is a number
*/
check_if_number = { val, String name ->
if (!(val in Integer || val in Float)) {
throw new Exception("${name} should be an Integer or Float, not ${val.getClass()}")
}
}
/**
* Check if given input is valid process list
*/
check_if_process_list = { val, String name ->
if (custom_schema_types.is_string(val)) {
if (val.isEmpty()) {
throw new Exception("Empty string specified for ${name}. Please provide valid input.")
}
} else {
try {
custom_schema_types.check_if_list(val, name)
} catch(Exception e) {
throw new Exception("${name} should be either a string or a list. Please provide valid input.")
}
}
}
/**
* Check that input is namespace of expected types
*/
check_input_namespace = { Map options, String name, Map properties ->
// Check parameters keys
custom_schema_types.check_if_namespace(options[name], name)
def given_keys = options[name].keySet() as ArrayList
custom_schema_types.check_input_type_keys(given_keys, name)
options[name].each { entry ->
def entry_as_map = [:]
entry_as_map[entry.key] = entry.value
schema.validate_parameter(entry_as_map, entry.key, properties.elements[entry.key])
}
}
/**
* Check namespace BAM
*/
check_bam_namespace = { Map options, String name, Map properties ->
custom_schema_types.check_if_namespace(options[name], name)
def given_keys = options[name].keySet() as ArrayList
if (given_keys.size() <= 0) {
throw new Exception("No inputs provided! Please provide inputs in the CSV or YAML.")
}
custom_schema_types.check_input_type_keys(given_keys, name, custom_schema_types.allowed_bam_types)
options[name].each { entry ->
def entry_as_map = [:]
entry_as_map[entry.key] = entry.value
schema.validate_parameter(entry_as_map, entry.key, properties.elements[entry.key])
}
}
/**
* Check namespace for resource updates
*/
check_resource_update_namespace = { Map options, String name, Map properties ->
custom_schema_types.check_if_namespace(options[name], name)
def given_keys = options[name].keySet() as ArrayList
if (given_keys.size() <= 0) {
return
}
custom_schema_types.check_input_type_keys(given_keys, name, custom_schema_types.allowed_resource_types)
options[name].each { entry ->
def entry_as_map = [:]
entry_as_map[entry.key] = entry.value
schema.validate_parameter(entry_as_map, entry.key, properties.elements[entry.key])
}
}
/**
* Check if proper BAM entry list
*/
check_bam_list = { Map options, String name, Map properties ->
custom_schema_types.check_if_list(options[name], name)
for (item in options[name]) {
schema.check_path(item, 'r')
}
}
/**
* Check list of resource updates
*/
check_resource_update_list = { Map options, String name, Map properties ->
custom_schema_types.check_if_list(options[name], name)
for (item in options[name]) {
custom_schema_types.check_if_process_list(item[0], name)
custom_schema_types.check_if_number(item[1], name)
}
}
types = [
'InputNamespace': custom_schema_types.check_input_namespace,
'InputBAMNamespace': custom_schema_types.check_bam_namespace,
'BAMEntryList': custom_schema_types.check_bam_list,
'ResourceUpdateNamespace': custom_schema_types.check_resource_update_namespace,
'ResourceUpdateList': custom_schema_types.check_resource_update_list
]
}