-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbwa.sh
More file actions
executable file
·46 lines (32 loc) · 785 Bytes
/
bwa.sh
File metadata and controls
executable file
·46 lines (32 loc) · 785 Bytes
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
#!/bin/bash
usage="./bwa.sh db.fa reads1.fq reads2.fq out.bam"
db=$1; shift
reads1=$1; shift
reads2=$1; shift
temp_string=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10)
aln1=bwa_$temp_string.1.sai
aln2=bwa_$temp_string.2.sai
bam=bwa_$temp_string.bam
#############################################
### BWA
bwa aln $db $reads1 > $aln1
bwa aln $db $reads2 > $aln2
bwa sampe $db $aln1 $aln2 $reads1 $reads2 \
| samtools view -Sb - \
> $bam
if [[ $? -ne 0 ]];then
print "bwa sampe failed" >&2
exit 2
fi
rm $aln1 $aln2
#############################################
### SORT
samtools sort $bam ${out/.bam/}
if [[ $? -ne 0 ]];then
print "samtools sort failed" >&2
exit 2
fi
rm $bam
#############################################
### INDEX
samtools index $out