Question: (Closed) How to loop over multiple files for BWA MEM in bash for loop?
gravatar for DNAngel
9 months ago by
DNAngel70 wrote:

Hi all,

I've written a large bash script for single-end paired reads which uses bwa mem. It works great. But now I have a new dataset that is paired-end and the only part I need to change is the beginning where bwa mem uses a reference file and sample files to align them. I cannot figure out how to edit my for loop to allow this.

All my sample files have a forward_R1 while and a reverse_R1 file as they are paired files.

My regular bwa mem loop in bash is:


for files in *.fastq
     bwa mem -B 2 -M-t 40 $REF $files > ${files%%.fastq}_aln.sam

How do I edit this so that it can take two files for the program, but still output the one aligned file?

I tried:


for forfiles, revfiles in *.fastq
     bwa mem -B 2 -M -t 40 $REF $forfiles $revfiles > ${forfiles%%.fastq}_paired_aln.sam

But this gives an error because the loop doesn't understand two arguments.

bash bwa • 884 views
ADD COMMENTlink written 9 months ago by DNAngel70

Hello DNAngel!

Questions similar to yours can already be found at:

We have closed your question to allow us to keep similar content in the same thread.

If you disagree with this please tell us why in a reply below. We'll be happy to talk about it.


ADD REPLYlink modified 9 months ago • written 9 months ago by Joe18k

I saw that one. My bad.

ADD REPLYlink modified 9 months ago • written 9 months ago by DNAngel70

Save yourself the trouble and use pipelines. I'm pretty sure there is a nf-core pipeline for what you are trying to achieve.

ADD REPLYlink written 9 months ago by Asaf8.4k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1379 users visited in the last hour