-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBatchMap.sh
51 lines (40 loc) · 1.26 KB
/
BatchMap.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
50
51
#!/bin/bash
set -e
# script by ellisrichardj
# This will perform mapping of all samples within a directory
# Requires BWA and samtools
# Version 0.1.1 21/10/14
#
# check for mandatory positional parameters
if [ $# -lt 2 ]; then
echo "
Usage: $0 <path to reference> <path to Data Folder> "
exit 1
fi
Start=$(date +%s)
Ref=$1
DataFolder="$2"
Count=0
threads=$(grep -c ^processor /proc/cpuinfo)
ref=$(basename "$Ref")
refname=${ref%%_*}
reffile=${ref%%.*}
homedir=$(pwd)
cp "$Ref" "$homedir"
bwa index "$ref"
for file in "$DataFolder"/*R1*.gz
do
((Count=Count+1))
fname=$(basename "$file")
samplename=${fname%%_*}
mkdir "$samplename"_mapto_"$refname"
cd "$samplename"_mapto_"$refname"
echo "Mapping sample "$Count": "$samplename" to "$ref""
bwa mem -t "$threads" "$homedir"/"$ref" "$DataFolder"/"$samplename"*R1*.gz "$DataFolder"/"$samplename"*R2*.gz | samtools view -Su - | samtools sort - "$samplename"-"$refname"_map_sorted
samtools index "$samplename"-"$refname"_map_sorted.bam
samtools flagstat "$samplename"-"$refname"_map_sorted.bam > "$samplename"-"$refname"_MappingStats.txt
cd "$homedir"
done
End=$(date +%s)
TimeTaken=$((End-Start))
echo | awk -v D=$TimeTaken '{printf "Mapped '$Count' samples in: %02d'h':%02d'm':%02d's'\n",D/(60*60),D%(60*60)/60,D%60}'