This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to loop over multiple files for BWA MEM in bash for loop?

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:

#!/bin/bash
REF=$1
ID=$2

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

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

I tried:

#!/bin/bash
REF=$1
ID=$2

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

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

bwa bash

I saw that one. My bad.

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

Hello DNAngel, I have the same problem, i need to do a loop for paired end, did you find the solution? i couldn't find it at the link

0 answers

No answers yet.

Log in to answer this question.