This is a test version of Biostars. For the public version, visit https://www.biostars.org.
For loop to go over all files in a folder to execute bwa mem

Hello friends !!

Actually I am tiring to execute bwa mem to align my reads to reference genome. Here are the manual command I ma doing

#For 1st sample
cd SRR1

 bwa mem -t 20 genome/genomic.fna ./SRR1/good/SRR10176137_1.good.fq  ./SRR1/good/SRR10176137_2.good.fq > mappings/SRR10176137.sam
cd ..

# For 2nd sample

cd SRR2

 bwa mem -t 20 genome/genomic.fna ./SRR2/good/SRR10176138_1.good.fq  ./SRR2/good/SRR10176138_2.good.fq > mappings/SRR10176138.sam

like I have 200 SRR samples so I am trying following code for loop i.e.

my data structure is i.e. = data/SRR......SRR200/good/S_1.fq.

working directory : data list SRR...SRR; mappings; vcf; genome

So each SRR* directory has good directory containing paired sequence .fq files

Here out sam files in data/mapping directory in data directory

#!/bin/bash

for d in SRR*/good; do
     cd $d;
     # my command
     bwa mem -t 40 genome/genomic S*_1.good.fq S*_2.good.fq > ../mappings/*.sam
     cd ..
done

Any modification highly appreciated

Thank you :)

shell bwa

everyone am mem Hello working to i bwa with take a few minutes to write the rights tags please....

1 answer

For loop to go over all files in a folder to execute bwa mem

this is a good idea, but you'd better use a workflow manager like snakemake or nextflow. If you're not familiar with those tools try to use a simple Makefile. See Parallel for bwa mem - problem with -R argument for ID and SM for an example.

Hi Pierre, thanks for your suggestion. Actually in my code can you please suggest any modification, or correction because it gives me error i.e. command not found i.e. bwa_mem.bash: line 1: $'\r': command not found

Did you write your script in Windows? $'\r' sounds like a Microsoft style linebreak. Run dos2unix yourScript.sh and then try again

Log in to answer this question.