@@ -164,17 +164,17 @@ class SamplesheetConverter {
164
164
if (metaNames) {
165
165
for (name : metaNames) {
166
166
meta[name] = (input != ' ' && input) ?
167
- transform (input, field) :
167
+ castToType (input, field) :
168
168
field[' value' ][' default' ] ?
169
- transform (field[' value' ][' default' ] as String , field) :
169
+ castToType (field[' value' ][' default' ] as String , field) :
170
170
null
171
171
}
172
172
}
173
173
else {
174
174
def inputFile = (input != ' ' && input) ?
175
- transform (input, field) :
175
+ castToType (input, field) :
176
176
field[' value' ][' default' ] ?
177
- transform (field[' value' ][' default' ] as String , field) :
177
+ castToType (field[' value' ][' default' ] as String , field) :
178
178
[]
179
179
output. add(inputFile)
180
180
}
@@ -240,14 +240,14 @@ class SamplesheetConverter {
240
240
}
241
241
242
242
// Function to transform an input field from the samplesheet to its desired type
243
- private static transform (
243
+ private static castToType (
244
244
String input ,
245
245
Map.Entry <String , Map > field
246
246
) {
247
247
def String type = field[' value' ][' type' ]
248
248
def String key = field. key
249
249
250
- // Check and convert string values
250
+ // Convert string values
251
251
if (type == " string" || ! type) {
252
252
def String result = input as String
253
253
@@ -262,21 +262,38 @@ class SamplesheetConverter {
262
262
return result
263
263
}
264
264
265
- // Check and convert integer values
266
- else if (type == " integer" || type == " number" ) {
265
+ // Convert number values
266
+ else if (type == " number" ) {
267
+ try {
268
+ def int result = input as int
269
+ return result
270
+ }
271
+ catch (NumberFormatException e) {
272
+ log. debug(" Could not convert ${ input} to an integer. Trying to convert to a float." )
273
+ }
274
+
275
+ try {
276
+ def float result = input as float
277
+ return result
278
+ }
279
+ catch (NumberFormatException e) {
280
+ log. debug(" Could not convert ${ input} to a float. Trying to convert to a double." )
281
+ }
282
+
283
+ def double result = input as double
284
+ return result
285
+ }
267
286
268
- // Stop conversion if there are errors (prevents unwanted exceptions)
269
- if (this . getErrors()){ return }
287
+ // Convert integer values
288
+ else if (type == " integer " ) {
270
289
271
- // Convert the string value to an integer value and return it
272
- def Integer result = input as Integer
290
+ def int result = input as int
273
291
return result
274
292
}
275
293
276
- // Check and convert boolean values
294
+ // Convert boolean values
277
295
else if (type == " boolean" ) {
278
296
279
- // Convert and return the boolean value
280
297
if (input. toLowerCase() == " true" ) {
281
298
return true
282
299
}
0 commit comments