Skip to content
Snippets Groups Projects
Commit b232d552 authored by Chloe Marie Loiseau's avatar Chloe Marie Loiseau
Browse files

BWA script

parent c0a25c77
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#SBATCH --job-name=BWA
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=4G
#SBATCH --time=6:00:00
#SBATCH --output=BWA.o
#SBATCH --error=BWA.e
#SBATCH --qos=6hours
### 3.1.1 Making the index
singularity exec container.img bwa index -a bwtsw ~/Workshop_SA/notebooks/reference_genome/MTB_ancestor_reference.fasta
### 3.1.2 Running BWA
singularity exec container.img bwa mem -M ~/Workshop_SA/notebooks/reference_genome/MTB_ancestor_reference.fasta ERR760779_1P.trimmed.fastq.gz ERR760779_2P.trimmed.fastq.gz > ERR760779_paired.sam
singularity exec container.img bwa mem -M ~/Workshop_SA/notebooks/reference_genome/MTB_ancestor_reference.fasta ERR760779_1U.trimmed.fastq.gz > ERR760779_1U.sam
singularity exec container.img bwa mem -M ~/Workshop_SA/notebooks/reference_genome/MTB_ancestor_reference.fasta ERR760779_2U.trimmed.fastq.gz > ERR760779_2U.sam
### convert the SAM to BAM format
singularity exec container.img samtools view -bhu ERR760779_paired.sam > ERR760779_paired.bam
singularity exec container.img samtools view -bhu ERR760779_1U.sam > ERR760779_1U.bam
singularity exec container.img samtools view -bhu ERR760779_2U.sam > ERR760779_2U.bam
### sort the BAM file by position
singularity exec container.img samtools sort -m 4G ERR760779_paired.bam > ERR760779.sorted.bam
singularity exec container.img samtools sort -m 4G ERR760779_1U.bam > ERR760779_1U.sorted.bam
singularity exec container.img samtools sort -m 4G ERR760779_2U.bam > ERR760779_2U.sorted.bam
### To go faster one could bring the three last commands into one using pipe:
### bwa mem -t 2 -M ~/Workshop_SA/notebooks/reference_genome/MTB_ancestor_reference.fasta ERR760779_1P.trimmed.fastq.gz ERR760779_2P.trimmed.fastq.gz | samtools view -Sbhu -|samtools sort -m 4G - ERR760779_paired.sorted
### 3.1.3 Merging the BAMs
singularity exec container.img samtools merge ERR760779_merged.bam ERR760779.sorted.bam ERR760779_1U.sorted.bam ERR760779_2U.sorted.bam
### 3.1.4 Retrieving the unmapped reads
singularity exec container.img samtools view -b -f 4 ERR760779_merged.bam > ERR760779.unmapped.bam
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment