Rearranging for clarity
[arvados-tutorial.git] / WGS-processing / cwl / helper / getfastq.cwl
1 $namespaces:
2   arv: "http://arvados.org/cwl#"
3   cwltool: "http://commonwl.org/cwltool#"
4 class: ExpressionTool
5 cwlVersion: v1.1
6 label: Create array of gvcfs to process
7 requirements:
8   InlineJavascriptRequirement: {}
9 inputs:
10   fastjdir:
11     type: Directory
12     label: Input directory of fastj
13     loadListing: 'shallow_listing' 
14 outputs:
15   fastq1: 
16     type: File[]
17   fastq2:
18     type: File[]
19 expression: |
20   ${function compare(a, b) {
21     var baseA = a.basename;
22     var baseB = b.basename;
23
24     var comparison = 0;
25     if (baseA > baseB) {
26     comparison = 1;
27     } else if (baseA < baseB) {
28     comparison = -1;
29     }
30     return comparison;
31     }
32
33     var fastq1 = [];
34     var fastq2 = [];
35     for (var i = 0; i < inputs.fastjdir.listing.length; i++) {
36       var name = inputs.fastjdir.listing[i];
37       if (name.basename.indexOf('_1.fastq.gz') != -1 ) {
38         fastq1.push(name);
39       }
40       if (name.basename.indexOf('_2.fastq.gz') != -1 ) {
41         fastq2.push(name);
42       }
43     }
44   
45     fastq1 = fastq1.sort(compare)
46     fastq2 = fastq2.sort(compare)
47  
48     return {"fastq1": fastq1, "fastq2": fastq2};
49   }