Hi guys, 

I'm totally new in the field of ChipSeq histon acetylation data analysis. 

I have to analyse some ChipSeq data. As from many tutorials and on-line documentation I started generating .fastq.gz from raw sequenced data. Then the trimming with Trimmomatic and then the alignment using BWA align. 

After bwa align I ended up with .sai files each for each lane, i.e. each for each .fastq.gz file. 

The situation is this: 

    X1_10_S8_L001_R1_001.aligned.sai     
    X1_10_S8_L001_R1_001.fastq.gz
    X2_11_S8_L001_R1_001.aligned.sai     
    X2_11_S8_L001_R1_001.fastq.gz
    X3_13_S8_L001_R1_001.aligned.sai     
    X3_13_S8_L001_R1_001.fastq.gz      

I have thousands of files like this. 

I would like to create .sam files to finally generate .bam files. 

Is there a way to loop over all the "paired" files to generate the .sam files and then the bam files? 


Thank you in advance for your help

B.
If your system supports parallel the try the following command with some modifications in the file name pattern.

    parallel --verbose -j 20 'bwa mem -t 10  bwa_index {1}_1.fastq.gz {1}_2.fastq.gz|samtools sort -@5 -o {1}_sorted.bam -' ::: $(cat files.txt)

Change the number after `-j` to increase or decrease the number of files to be processed per batch.

`files.txt` contains all the file names.

Without parallel. 

    #!/bin/bash
    for file in `cat files.txt`
    do
    bwa mem -t 10  bwa_index ${file}_1.fastq.gz ${file}_2.fastq.gz|samtools sort -@5 -o ${file}_sorted.bam -
    done

*BWA Version: 0.7.17-r1194-dirty

