From 710cb79676d11663c8d951373265c9c80325aee3 Mon Sep 17 00:00:00 2001
From: JasperBoom <jboom@infernum.nl>
Date: Tue, 11 Aug 2020 14:14:55 +0200
Subject: [PATCH] Fix index localization.

---
 CHANGELOG.md  |  2 ++
 bam2fastx.wdl | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 272499c..af61315 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ that users understand how the changes affect the new version.
 
 version 5.0.0-dev
 ---------------------------
++ Add copy command to bam2fastx tasks to make sure bam file and its index are
+  always in the same directory.
 + Add wdl file for pacbio's bam2fastx tool.
 
 version 4.0.0
diff --git a/bam2fastx.wdl b/bam2fastx.wdl
index 5e5fb50..6a09202 100644
--- a/bam2fastx.wdl
+++ b/bam2fastx.wdl
@@ -24,6 +24,7 @@ task Bam2Fasta {
     input {
         File inputFile
         File bamIndex
+        String basenameInputFile = basename(inputFile)
         String outputPrefix
         Int compressionLevel = 1
         Boolean splitByBarcode = false
@@ -38,12 +39,16 @@ task Bam2Fasta {
     command {
         set -e
         mkdir -p "$(dirname ~{outputPrefix})"
+        # The bam file and its index need to be in the same directory.
+        # Cromwell will put them in separate iputs folders.
+        cp ~{inputFile} ./
+        cp ~{bamIndex} ./
         bam2fasta \
         --output ~{outputPrefix} \
         -c ~{compressionLevel} \
         ~{true="--split-barcodes" false="" splitByBarcode} \
         ~{"--seqid-prefix " + seqIdPrefix} \
-        ~{inputFile}
+        ./~{basenameInputFile}
     }
 
     output {
@@ -76,6 +81,7 @@ task Bam2Fasta {
 task Bam2Fastq {
     input {
         File inputFile
+        String basenameInputFile = basename(inputFile)
         File bamIndex
         String outputPrefix
         Int compressionLevel = 1
@@ -91,12 +97,16 @@ task Bam2Fastq {
     command {
         set -e
         mkdir -p "$(dirname ~{outputPrefix})"
+        # The bam file and its index need to be in the same directory.
+        # Cromwell will put them in separate iputs folders.
+        cp ~{inputFile} ./
+        cp ~{bamIndex} ./
         bam2fastq \
         --output ~{outputPrefix} \
         -c ~{compressionLevel} \
         ~{true="--split-barcodes" false="" splitByBarcode} \
         ~{"--seqid-prefix " + seqIdPrefix} \
-        ~{inputFile}
+        ./~{basenameInputFile}
     }
 
     output {
-- 
GitLab