updating metadata
[arvados-tutorial.git] / WGS-processing / cwl / helper / getfastq.cwl
1 class: ExpressionTool
2 cwlVersion: v1.1
3 label: Find matching FASTQ pairs 
4 requirements:
5   InlineJavascriptRequirement: {}
6
7 inputs:
8   fastqdir:
9     type: Directory
10     label: Input directory of FASTQs
11     loadListing: 'shallow_listing' 
12
13 outputs:
14   fastq1: 
15     type: File[]
16     format: edam:format_1930 # FASTQ
17     label: Half set of pair-end FASTQs (R1)
18   fastq2:
19     type: File[]
20     format: edam:format_1930 # FASTQ
21     label: Half set of pair-end FASTQs (R2)
22   sample:
23     type: string[]
24     label: Sample Names
25
26 expression: |
27   ${function compare(a, b) {
28     var baseA = a.basename;
29     var baseB = b.basename;
30
31     var comparison = 0;
32     if (baseA > baseB) {
33     comparison = 1;
34     } else if (baseA < baseB) {
35     comparison = -1;
36     }
37     return comparison;
38     }
39
40     var fastq1 = [];
41     var fastq2 = [];
42     for (var i = 0; i < inputs.fastqdir.listing.length; i++) {
43       var name = inputs.fastqdir.listing[i];
44       if (name.basename.indexOf('_1.fastq.gz') != -1 ) {
45         fastq1.push(name);
46       }
47       if (name.basename.indexOf('_2.fastq.gz') != -1 ) {
48         fastq2.push(name);
49       }
50     }
51   
52     fastq1 = fastq1.sort(compare)
53     fastq2 = fastq2.sort(compare)
54
55     var sample = [];
56
57     for (var i = 0; i < fastq1.length; i++) {
58       var name = fastq1[i].basename;
59       var samplename = name.replace(/_1.fastq.gz/,'');
60       sample.push(samplename);
61       }
62
63  
64     return {"fastq1": fastq1, "fastq2": fastq2, "sample": sample};
65   }
66
67
68 s:codeRepository: https://github.com/arvados/arvados-tutorial
69 s:license: https://www.gnu.org/licenses/agpl-3.0.en.html
70
71 $namespaces:
72  s: https://schema.org/
73  edam: http://edamontology.org/
74  arv: "http://arvados.org/cwl#"
75  cwltool: "http://commonwl.org/cwltool#"
76
77 $schemas:
78  - https://schema.org/version/latest/schema.rdf
79  - http://edamontology.org/EDAM_1.18.owl