@@ -17,7 +17,6 @@ import java.nio.file.NotDirectoryException
17
17
import java.nio.file.Path
18
18
import java.text.ParseException
19
19
20
-
21
20
/**
22
21
* <h1>Parser storing the fileTree of a nf-core pipeline output directory into JSON format</h1>
23
22
* <br >
@@ -27,7 +26,7 @@ import java.text.ParseException
27
26
* @param directory path of nf-core directory whose fileTree should be converted into a JSON String
28
27
*
29
28
*/
30
- class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult > {
29
+ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult > {
31
30
32
31
/**
33
32
* Contains the associated keys of the required root directory subFolders
@@ -36,19 +35,28 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
36
35
* @since 1.8.0
37
36
*/
38
37
enum RequiredRootFolderKeys {
39
- QUALITY_CONTROL (" qualityControl" ),
40
- PIPELINE_INFORMATION (" pipelineInformation" ),
41
- PROCESS_FOLDERS (" processFolders" )
38
+ QUALITY_CONTROL (" qualityControl" , " multiqc" ),
39
+ PIPELINE_INFORMATION (" pipelineInformation" , " pipeline_info" ),
40
+ // Process_Folder names can vary so no directory name can be assumed for now
41
+ PROCESS_FOLDERS (" processFolders" , null )
42
42
43
43
private String keyName
44
44
45
- RequiredRootFolderKeys (String keyName ) {
45
+ private String folderName
46
+
47
+ RequiredRootFolderKeys (String keyName , String folderName ) {
46
48
this . keyName = keyName
49
+ this . folderName = folderName
47
50
}
48
51
49
52
String getKeyName () {
50
53
return this . keyName
51
54
}
55
+
56
+ String getFolderName () {
57
+ return this . folderName
58
+ }
59
+
52
60
}
53
61
54
62
/**
@@ -58,18 +66,24 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
58
66
* @since 1.8.0
59
67
*/
60
68
enum RequiredRootFileKeys {
61
- RUN_ID (" runId" ),
62
- SAMPLE_ID (" sampleIds" ),
69
+ RUN_ID (" runId" , " run_id.txt " ),
70
+ SAMPLE_ID (" sampleIds" , " sample_ids.txt " )
63
71
64
72
private String keyName
73
+ private String fileName
65
74
66
- RequiredRootFileKeys (String keyName ) {
75
+ RequiredRootFileKeys (String keyName , String fileName ) {
67
76
this . keyName = keyName
77
+ this . fileName = fileName
68
78
}
69
79
70
80
String getKeyName () {
71
81
return this . keyName
72
82
}
83
+
84
+ String getFileName () {
85
+ return this . fileName
86
+ }
73
87
}
74
88
75
89
/**
@@ -79,19 +93,25 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
79
93
* @since 1.8.0
80
94
*/
81
95
enum RequiredPipelineFileKeys {
82
- SOFTWARE_VERSIONS (" softwareVersions" ),
83
- EXECUTION_REPORT (" executionReport" ),
96
+ SOFTWARE_VERSIONS (" softwareVersions" , " software_versions.yml " ),
97
+ EXECUTION_REPORT (" executionReport" , " execution_report " ),
84
98
85
99
private String keyName
86
100
87
- RequiredPipelineFileKeys (String keyName ) {
101
+ private String fileName
102
+
103
+ RequiredPipelineFileKeys (String keyName , String fileName ) {
88
104
this . keyName = keyName
105
+ this . fileName = fileName
89
106
}
90
107
91
108
String getKeyName () {
92
109
return this . keyName
93
110
}
94
111
112
+ String getFileName () {
113
+ return this . fileName
114
+ }
95
115
}
96
116
97
117
/* * {@InheritDoc} */
@@ -139,32 +159,23 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
139
159
List<Map > processFolders = []
140
160
rootChildren. each { currentChild ->
141
161
if (currentChild. containsKey(" children" )) {
142
- // folder
162
+ // directory
143
163
String folderName = currentChild. get(" name" )
144
- switch (folderName) {
145
- case " multiqc" :
146
- insertAsProperty(map, currentChild, RequiredRootFolderKeys . QUALITY_CONTROL . getKeyName())
147
- break
148
- case " pipeline_info" :
164
+ RequiredRootFolderKeys requiredRootFolderKeys = RequiredRootFolderKeys . values(). find { rootFolderKeys -> (rootFolderKeys. getFolderName() == folderName) }
165
+ if (requiredRootFolderKeys) {
166
+ if (requiredRootFolderKeys == RequiredRootFolderKeys . PIPELINE_INFORMATION ) {
149
167
parsePipelineInformation(currentChild)
150
- insertAsProperty(map, currentChild, RequiredRootFolderKeys . PIPELINE_INFORMATION . getKeyName())
151
- break
152
- default :
153
- processFolders. add(currentChild)
154
- break
168
+ }
169
+ insertAsProperty(map, currentChild, requiredRootFolderKeys. getKeyName())
170
+ } else {
171
+ processFolders. add(currentChild)
155
172
}
156
173
} else if (currentChild. containsKey(" fileType" )) {
157
174
// file
158
- switch (currentChild. get(" name" )) {
159
- case " run_id.txt" :
160
- insertAsProperty(map, currentChild, RequiredRootFileKeys . RUN_ID . getKeyName())
161
- break
162
- case " sample_ids.txt" :
163
- insertAsProperty(map, currentChild, RequiredRootFileKeys . SAMPLE_ID . getKeyName())
164
- break
165
- default :
166
- // ignore other files
167
- break
175
+ String fileName = currentChild. get(" name" )
176
+ RequiredRootFileKeys requiredRootFileKeys = RequiredRootFileKeys . values(). find { rootFileKeys -> (rootFileKeys. getFileName() == fileName) }
177
+ if (requiredRootFileKeys) {
178
+ insertAsProperty(map, currentChild, requiredRootFileKeys. getKeyName())
168
179
}
169
180
}
170
181
}
@@ -200,12 +211,10 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
200
211
private static void parsePipelineInformation (Map pipelineInformation ) {
201
212
202
213
pipelineInformation. get(" children" ). each { Map child ->
203
- String filename = child. get(" name" )
204
- if (filename. equals(" software_versions.yml" )){
205
- insertAsProperty(pipelineInformation, child, RequiredPipelineFileKeys . SOFTWARE_VERSIONS . getKeyName())
206
- }
207
- else if (filename. matches(" ^execution_report.*" )) {
208
- insertAsProperty(pipelineInformation, child, RequiredPipelineFileKeys . EXECUTION_REPORT . getKeyName())
214
+ String fileName = child. get(" name" )
215
+ RequiredPipelineFileKeys requiredPipelineFileKeys = RequiredPipelineFileKeys . values(). find { pipelineFileKeys -> (fileName. contains(pipelineFileKeys. fileName)) }
216
+ if (requiredPipelineFileKeys) {
217
+ insertAsProperty(pipelineInformation, child, requiredPipelineFileKeys. getKeyName())
209
218
}
210
219
}
211
220
}
@@ -218,7 +227,7 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
218
227
* @since 1.8.0
219
228
*/
220
229
private static void insertAsProperty (Map parent , Object content , String propertyName ) {
221
- parent. put(propertyName,content)
230
+ parent. put(propertyName, content)
222
231
}
223
232
224
233
/**
@@ -236,7 +245,7 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
236
245
/**
237
246
* Method which checks if a given Json String matches a given Json schema
238
247
* @param json Json String which will be compared to schema
239
- * @param path to Json schema for validation of Json String
248
+ * @param path to Json schema for validation of Json String
240
249
* @throws org.everit.json.schema.ValidationException
241
250
*/
242
251
private static void validateJson (String json ) throws ValidationException {
@@ -258,6 +267,7 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
258
267
/*
259
268
* Converts a file tree into a json object.
260
269
*/
270
+
261
271
private static class DirectoryConverter {
262
272
263
273
/**
@@ -321,11 +331,11 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
321
331
322
332
private static Map convertToRelativePaths (Map content , Path root ) {
323
333
// Since each value in the root map is a map we need to iterate over each key/value pair
324
- content[" path" ] = toRelativePath(content[" path" ] as String , root)
325
- if (content[" children" ]) {
326
- // Children always contains a map, so convert recursively
327
- content[" children" ] = (content[" children" ] as List ). collect { convertToRelativePaths(it as Map , root) }
328
- }
334
+ content[" path" ] = toRelativePath(content[" path" ] as String , root)
335
+ if (content[" children" ]) {
336
+ // Children always contains a map, so convert recursively
337
+ content[" children" ] = (content[" children" ] as List ). collect { convertToRelativePaths(it as Map , root) }
338
+ }
329
339
return content
330
340
331
341
}
@@ -351,8 +361,8 @@ class BioinformaticAnalysisParser implements DatasetParser<NfCorePipelineResult>
351
361
352
362
353
363
def convertedFile = [
354
- " name" : name,
355
- " path" : path,
364
+ " name" : name,
365
+ " path" : path,
356
366
" fileType" : fileType
357
367
]
358
368
return convertedFile
0 commit comments