<p>The loop you're using does not work, as it overwrites the value of <code>sample_basename</code> each time. Plus, given that you're passing in the full path to the bam (using <code>$dir/$sample_basename</code>) anyway, I don't see the reason to use the <code>sample_basename</code> variable at all.</p>

<p>Just this:</p>

<pre><code>dir=/path/to/bam
data=/path/to/processed/data
ref_fa=/path/to/ref/fasta

cd $dir

for bam_file in *.bam
do
  <span class="math-container">${path_to_strelka}/bin/configureStrelkaGermlineWorkflow.py \
    --bam $</span>{bam_file} \
    --referenceFasta <span class="math-container">${ref_fa} \
    --runDir $</span>{data}
  ${data}/runWorkflow.py -m local -j 20 #I'm assuming this goes inside the loop. If not, move it outside the loop. You don't need a `wait` in a shell script that's working line-by-line already.
done
</code></pre>

CC BY-SA 4.0
2019-12-17T22:37:47.623Z
Thank you very much :).
justaguy
CC BY-SA 4.0
2019-12-16T20:40:37.840Z
2019-12-16T20:40:37.840Z
Ram RS
<p>In the below <code>bash loop for strelka2</code>, 3 bam files are being stored in a variable. The two questions are:</p>

<p>Is this proper way to loop through multi bam and wait for workflow to be created for <code>strelka2</code> processing,
and can you create a workflow in a directory without the bam in it. Thank you :).</p>

<p><strong>contents of dir</strong></p>

<pre><code>s1.bam
s2.bam
s3.bam
</code></pre>

<p><strong>bash</strong></p>

<pre><code>dir=/path/to/bam
data=/path/to/processed/data

cd <span class="math-container">$dir
 for bam in $</span>{dir}/*.bam; do sample_basename=<span class="math-container">$(basename "$</span>{bam}"); done # loop through dir and get bam

<span class="math-container">${path_to_strelka}/bin/configureStrelkaGermlineWorkflow.py \
  --bam $</span>{dir}/<span class="math-container">${sample_basename} \
  --referenceFasta &lt;fasta&gt; \
  --runDir $</span>{data}
  wait  # wait until workflow in data is created before executing below  in data
${data}/runWorkflow.py -m local -j 20
</code></pre>

<bash>
bash loop for strelka2 processing for multiple files from one directory
# bash loop for strelka2 processing for multiple files from one directory

(Asked by: username_0 on 2019-12-15)

In the below bash loop for strelka2, 3 bam files are being stored in a variable. The two questions are:
Is this proper way to loop through multi bam and wait for workflow to be created for strelka2 processing,
and can you create a workflow in a directory without the bam in it. Thank you :).
contents of dir
s1.bam
s2.bam
s3.bam

bash
dir=/path/to/bam
data=/path/to/processed/data

cd $dir
 for bam in ${dir}/*.bam; do sample_basename=$(basename "${bam}"); done # loop through dir and get bam

${path_to_strelka}/bin/configureStrelkaGermlineWorkflow.py \
  --bam ${dir}/${sample_basename} \
  --referenceFasta  \
  --runDir ${data}
  wait  # wait until workflow in data is created before executing below  in data
${data}/runWorkflow.py -m local -j 20

**Tags:** bash

---

## 1 answers

### Answer by username_1 on 2019-12-16. Score: 1 | Accepted answer

The loop you're using does not work, as it overwrites the value of sample_basename each time. Plus, given that you're passing in the full path to the bam (using $dir/$sample_basename) anyway, I don't see the reason to use the sample_basename variable at all.
Just this:
dir=/path/to/bam
data=/path/to/processed/data
ref_fa=/path/to/ref/fasta

cd $dir

for bam_file in *.bam
do
  ${path_to_strelka}/bin/configureStrelkaGermlineWorkflow.py \
    --bam ${bam_file} \
    --referenceFasta ${ref_fa} \
    --runDir ${data}
  ${data}/runWorkflow.py -m local -j 20 #I'm assuming this goes inside the loop. If not, move it outside the loop. You don't need a `wait` in a shell script that's working line-by-line already.
done

> **Comments:**
> **username_0**: Thank you very much :).  

---

