-
Notifications
You must be signed in to change notification settings - Fork 12
/
make-pileups.sh
executable file
·65 lines (52 loc) · 1.76 KB
/
make-pileups.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env sh
# [[file:~/Work/simsec/org/simsec.org::*Create%20sim%20pileup%20for%20each%20contig][block-26]]
#!/bin/bash -x
usage () {
echo usage: `basename $0` -i indiv -d dir -a all -r range -p parent1 -q parent2
exit 2
}
die () {
echo "$1"
exit ${2:-1}
}
true=0
false="false"
all=$false
while getopts "ai:d:p:q:" opt
do
case $opt in
i) indiv=$OPTARG ;;
d) dir=$OPTARG ;;
a) all=$true ;;
r) range=$OPTARG ;;
p) parent1=$OPTARG ;;
q) parent2=$OPTARG ;;
*) usage ;;
esac
done
shift $(($OPTIND - 1))
[ -n "$indiv" ] && [ -n "$dir" ] && [ -n "$parent1" ] && [ -n "$parent2" ] || usage
species=par1
[ -e $parent1 ] || die "$parent1 doesn't exist"
#[ $all ] && refs=$(ls $dir/refs/par1/*-ref.alleles | perl -pe 's/-ref.alleles//' | sed -n "${range}p") || \
[ $all ] && refs=$(ls $dir/refs/par1 | grep '\-ref.alleles' | perl -pe 's/-ref.alleles//' | sed -n "${range}p") || \
refs="4 X 3L 3R 2L 2R"
file=$dir/aln_${indiv}_${species}-filtered
echo "$file"
[ -e $parent1.fai ] || samtools faidx $parent1
[ -e $file-sorted.bam ] || {
echo "samtools view -bt $parent1.fai $file.sam | samtools sort - $file-sorted"
samtools view -bt $parent1.fai $file.sam | samtools sort - $file-sorted
}
[ -e $file-sorted.bam.bai ] || samtools index $file-sorted.bam
for ref in $refs ; do
[ -e $file-$ref-sorted.pileup ] || {
echo "Making pileup for $species contig $ref"
samtools view -bu $file-sorted.bam $ref | samtools sort - $file-$ref-sorted
samtools index $file-$ref-sorted.bam
samtools pileup -Bcf $parent1 $file-$ref-sorted.bam > $file-$ref-sorted.pileup
rm $file-$ref-sorted.bam $file-$ref-sorted.bam.bai
}
done
## rm -f $file-sorted.bam $file-sorted.bam.bai
# block-26 ends here