Adding modified code to select variants and gather arrays
[arvados-tutorial.git] / cwl / helper / gather-vcf.cwl
index 8e5b29a8c6063496f152e5533b49721f449f9a26..cd1532c7deb91bcc6d6b5e7fd69a9f512f64484c 100644 (file)
@@ -9,10 +9,7 @@ requirements:
   DockerRequirement:
     dockerPull: broadinstitute/gatk:4.1.7.0
   ShellCommandRequirement: {}
-  InitialWorkDirRequirement:
-    listing:
-      - $(inputs.gvcf1)
-      - $(inputs.gvcf2)
+  InlineJavascriptRequirement: {}
 
 hints:
   ResourceRequirement:
@@ -22,10 +19,10 @@ hints:
     outputDirType: keep_output_dir
 
 inputs:
-  gvcf1:
-    type: File
-  gvcf2:
-    type: File
+  gvcfdir: 
+    type: Directory
+    label: Input directory of gvcfs
+    loadListing: 'shallow_listing'
   sample: string
   reference:
     type: File
@@ -40,6 +37,8 @@ inputs:
 outputs:
   gatheredgvcf:
     type: File
+    secondaryFiles:
+      - .tbi
     outputBinding:
       glob: "*.g.vcf.gz"
 
@@ -48,10 +47,38 @@ baseCommand: /gatk/gatk
 arguments:
   - "--java-options"
   - "-Xmx8G" 
-  - GatherVcfs
-  - "-I"
-  - $(inputs.gvcf1.basename) 
-  - "-I"
-  - $(inputs.gvcf2.basename)
+  - MergeVcfs
+  - shellQuote: false
+    valueFrom: | 
+     ${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 samples = [];
+      for (var i = 0; i < inputs.gvcfdir.listing.length; i++) {
+        var name = inputs.gvcfdir.listing[i];
+        if (name.nameext ==='.gz' ) {
+          samples.push(name.path);
+        }
+      }
+      samples = samples.sort(compare);
+      var sampleinput = [];
+
+      for (var i = 0; i < samples.length; i++) {
+       var s1 = samples[i];
+       sampleinput = sampleinput + "-I " + s1 + " "
+      }
+    
+      return sampleinput;
+      }
   - prefix: "-O"
     valueFrom: $(inputs.sample).g.vcf.gz