@@ -45,6 +45,7 @@ final class NfCorePipelineResult {
4545
4646 private SampleIds sampleIds
4747
48+ // The RunId is only generated if the result was generated by a NF-Tower instance
4849 private RunId runId
4950
5051 private PipelineInformationFolder pipelineInformationFolder
@@ -53,7 +54,7 @@ final class NfCorePipelineResult {
5354
5455 private List<DataFolder > processFolders
5556
56- NfCorePipelineResult (PipelineInformationFolder pipelineInformationFolder , QualityControlFolder qualityControlFolder , List<DataFolder > processFolders , RunId runId , SampleIds sampleIds ) {
57+ NfCorePipelineResult (PipelineInformationFolder pipelineInformationFolder , QualityControlFolder qualityControlFolder , List<DataFolder > processFolders , RunId runId , SampleIds sampleIds ) {
5758 Objects . requireNonNull(pipelineInformationFolder, " Please provide a PipelineInformation folder." )
5859 Objects . requireNonNull(qualityControlFolder, " Please provide a QualityControl folder" )
5960 Objects . requireNonNull(processFolders, " Please provide a List of process folders" )
@@ -67,6 +68,17 @@ final class NfCorePipelineResult {
6768 this . sampleIds = sampleIds
6869 }
6970
71+ NfCorePipelineResult (PipelineInformationFolder pipelineInformationFolder , QualityControlFolder qualityControlFolder , List<DataFolder > processFolders , SampleIds sampleIds ) {
72+ Objects . requireNonNull(pipelineInformationFolder, " Please provide a PipelineInformation folder." )
73+ Objects . requireNonNull(qualityControlFolder, " Please provide a QualityControl folder" )
74+ Objects . requireNonNull(processFolders, " Please provide a List of process folders" )
75+ Objects . requireNonNull(sampleIds, " Please provide a sampleIds file" )
76+ this . pipelineInformationFolder = pipelineInformationFolder
77+ this . qualityControlFolder = qualityControlFolder
78+ this . processFolders = processFolders
79+ this . sampleIds = sampleIds
80+ }
81+
7082 /**
7183 * Static factory method that creates a new nfcoreExperiment instance from the bioinformatic pipeline output.
7284 * See this @{link <a href =" https://github.com/qbicsoftware/data-model-lib/blob/master/src/test/resources/examples/resultset/valid-resultset-example.json" >example</a>}
@@ -80,14 +92,13 @@ final class NfCorePipelineResult {
8092
8193 // Check if all required folders are in root directory
8294 Objects . requireNonNull(bioinformaticPipelineOutput. get(" pipelineInformation" ), " The root folder must contain a PipelineInformation folder." )
83- Objects . requireNonNull(bioinformaticPipelineOutput. get(" qualityControl" )," The root folder must contain a QualityControl folder." )
95+ Objects . requireNonNull(bioinformaticPipelineOutput. get(" qualityControl" ), " The root folder must contain a QualityControl folder." )
8496 Objects . requireNonNull(bioinformaticPipelineOutput. get(" processFolders" ), " The root folder must contain at least one process folder." )
8597 // Check if all required files are in the pipeline_info directory
8698 Map pipelineInfoMap = bioinformaticPipelineOutput[" pipelineInformation" ] as Map
8799 Objects . requireNonNull(pipelineInfoMap. get(" softwareVersions" ), " The pipeline_info folder must contain a softwareVersions.yml file." )
88100 Objects . requireNonNull(pipelineInfoMap. get(" executionReport" ), " The pipeline_info folder must contain a executionReport.html file." )
89101 // Check if all required files are in root directory
90- Objects . requireNonNull(bioinformaticPipelineOutput. get(" runId" ), " The root folder must contain a run_id.txt file." )
91102 Objects . requireNonNull(bioinformaticPipelineOutput. get(" sampleIds" ), " The root folder must contain an sample_ids.txt file." )
92103
93104 // Parse all folders in the root directory
@@ -108,12 +119,16 @@ final class NfCorePipelineResult {
108119 pipelineInformation. softwareVersions = softwareVersions as SoftwareVersions
109120 pipelineInformation. executionReport = executionReport as ExecutionReport
110121
111- // Parse all files in the root directory
112- DataFile runId = parseFile(bioinformaticPipelineOutput. get(" runId" ) as Map ) as RunId
122+ // Parse all mandatory files in the root directory
113123 DataFile sampleIds = parseFile(bioinformaticPipelineOutput. get(" sampleIds" ) as Map ) as SampleIds
114124
115- // Create new NfCorePipelineResult with parsed information
116- return new NfCorePipelineResult (pipelineInformation, qualityControl, processFolders, runId, sampleIds)
125+ // Parse optional Files in the root directory and generate NfCorePipelineResult accordingly
126+ if (bioinformaticPipelineOutput. get(" runId" ) != null ) {
127+ DataFile runId = parseFile(bioinformaticPipelineOutput. get(" runId" ) as Map ) as RunId
128+ return new NfCorePipelineResult (pipelineInformation, qualityControl, processFolders, runId, sampleIds)
129+ } else {
130+ return new NfCorePipelineResult (pipelineInformation, qualityControl, processFolders, sampleIds)
131+ }
117132 }
118133
119134 /**
@@ -165,11 +180,12 @@ final class NfCorePipelineResult {
165180 /*
166181 * Helper method that creates a DataFile instance from a map
167182 */
183+
168184 private static DataFile parseFile (Map fileTree ) throws IllegalArgumentException {
169185 String name = fileTree. get(" name" )
170186 String fileType = fileTree. get(" fileType" )
171187 String path = fileTree. get(" path" )
172-
188+
173189 for (String nfCoreFileType : nfCoreFileTypes) {
174190 Class<?> c = Class . forName(nfCoreFileType)
175191 Method method = c. getDeclaredMethod(" create" , String . class, String . class)
@@ -183,15 +199,15 @@ final class NfCorePipelineResult {
183199 }
184200 }
185201 // We have to check for files of unknown type since this Parser will encounter variable file output dependent on the pipeline
186- if (! fileType)
187- {
188- throw new IllegalArgumentException (" File $name with path $path is of unknown nfcore file type." )
202+ if (! fileType) {
203+ throw new IllegalArgumentException (" File $name with path $path is of unknown nfcore file type." )
189204 }
190205 }
191206
192207 /*
193208 * Helper method that creates a DataFolder instance from a map
194209 */
210+
195211 private static DataFolder parseFolder (Map fileTree ) throws IllegalArgumentException {
196212
197213 def name = fileTree. get(" name" ) as String
@@ -215,25 +231,27 @@ final class NfCorePipelineResult {
215231 * Helper method that tries to create a DataFolder instance
216232 * based on the DataFolder's different static factory create methods.
217233 */
234+
218235 private static Optional<DataFolder > tryToCreateDataFolder (Method method ,
219236 String name ,
220237 String relativePath ,
221238 List children ) {
222239 Optional<DataFolder > folder = Optional . empty()
223- try {
224- // We only have named Folders
225- def dataFolder = method. invoke(null , name, relativePath, children) as DataFolder
226- folder = Optional . of(dataFolder)
227- } catch (InvocationTargetException e2) {
228- // Do nothing
229- }
240+ try {
241+ // We only have named Folders
242+ def dataFolder = method. invoke(null , name, relativePath, children) as DataFolder
243+ folder = Optional . of(dataFolder)
244+ } catch (InvocationTargetException e2) {
245+ // Do nothing
246+ }
230247
231248 return folder
232249 }
233250
234251 /*
235252 * Helper method that parses the children of a folder.
236253 */
254+
237255 private static List parseChildren (List<Map > children ) {
238256 def parsedChildren = []
239257 children. each { Map unknownChild ->
0 commit comments