-
Notifications
You must be signed in to change notification settings - Fork 0
/
alignPE_bwa.sh
49 lines (36 loc) · 1.34 KB
/
alignPE_bwa.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#PBS -lselect=1:ncpus=8:mem=16gb
#PBS -lwalltime=12:00:00
# modules
# load modules
module load bwa/0.7.8
module load samtools/1.3.1
# index array
i=$PBS_ARRAY_INDEX
# Expand a space-sperated parameter of file names into addressable array
reads1=(${args1})
reads2=(${args2})
# Reference to map to
ref=${ref}
# Output folder
bamout=${bamout}
# Various readgroup meta-data for the BAM files
#fcid=$(echo ${reads1[$i]##*/} | cut -d_ -f4 )
#lane=$(echo ${reads1[$i]##*/} | cut -d_ -f5 )
sample=$( basename $(dirname ${reads1[$i]}) )
lib="serial_afum${sample}"
RG="@RG\tID:1.1\tSM:${sample}\tPL:ILLUMINA\tLB:${lib}"
# number of threads
threads=8
# make output directory if it doesn't exist
if [ ! -d "${bamout}/${sample}" ]; then mkdir -p "${bamout}/${sample}"; fi
# read mapping
bwa mem -t $threads -R "$RG" "$ref" "${reads1[$i]}" "${reads2[$i]}" >"${bamout}/${sample}/${sample%%.*}.${lane}.sam"
# convert to .bam file
samtools view -b "${bamout}/${sample}/${sample%%.*}.${lane}.sam" > "${bamout}/${sample}/${sample%%.*}.${lane}.bam"
# delete sam file
rm "${bamout}/${sample}/${sample%%.*}.${lane}.sam"
# sort bam
samtools sort -O bam -T "${EPHEMERAL}" "${bamout}/${sample}/${sample%%.*}.${lane}.bam" > "${bamout}/${sample}/${sample%%.*}.${lane}.sorted.bam"
# index bam file
samtools index "${bamout}/${sample}/${sample%%.*}.${lane}.sorted.bam"