Adding code to get fastqs from directory
[arvados-tutorial.git] / cwl / helper / getfastq.cwl
diff --git a/cwl/helper/getfastq.cwl b/cwl/helper/getfastq.cwl
new file mode 100644 (file)
index 0000000..a38bc91
--- /dev/null
@@ -0,0 +1,49 @@
+$namespaces:
+  arv: "http://arvados.org/cwl#"
+  cwltool: "http://commonwl.org/cwltool#"
+class: ExpressionTool
+cwlVersion: v1.1
+label: Create array of gvcfs to process
+requirements:
+  InlineJavascriptRequirement: {}
+inputs:
+  fastjdir:
+    type: Directory
+    label: Input directory of fastj
+    loadListing: 'shallow_listing' 
+outputs:
+  fastq1: 
+    type: File[]
+  fastq2:
+    type: File[]
+expression: |
+  ${function compare(a, b) {
+    var baseA = a.basename;
+    var baseB = b.basename;
+
+    var comparison = 0;
+    if (baseA > baseB) {
+    comparison = 1;
+    } else if (baseA < baseB) {
+    comparison = -1;
+    }
+    return comparison;
+    }
+
+    var fastq1 = [];
+    var fastq2 = [];
+    for (var i = 0; i < inputs.fastjdir.listing.length; i++) {
+      var name = inputs.fastjdir.listing[i];
+      if (name.basename.indexOf('_1.fastq.gz') != -1 ) {
+        fastq1.push(name);
+      }
+      if (name.basename.indexOf('_2.fastq.gz') != -1 ) {
+        fastq2.push(name);
+      }
+    }
+  
+    fastq1 = fastq1.sort(compare)
+    fastq2 = fastq2.sort(compare)
+    return {"fastq1": fastq1, "fastq2": fastq2};
+  }