forked from pko89403/Monte-Carlo_Based_KS-Test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allele_depth_pipe.sh
executable file
·156 lines (127 loc) · 3.78 KB
/
allele_depth_pipe.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
function description
{
echo -e "\t<USAGE of preprocessing for KS-test>"
echo -e "\t:\n"
echo -e "\t[allele_depth_pipe.sh -r <reference sequence> -d <working directory> -o <output prefix of sync file>]\n"
echo -e "\t:[-d] The working directory which includes the raw sequencing data. \n"
echo -e "\t:Note that the raw sequencing data have to be formatted as 'XXXX_timepoint.fastq'\n"
}
while [ -n "$1" ]
do
case $1 in
-h)
description
exit 1
;;
-r)
reference=$2
shift 2
;;
-d)
workingDir=$2
shift 2
;;
-o)
outputPrefix=$2
shift 2
;;
-*)
echo "you used wrong options $1"
description
exit 1
;;
*)
break
;;
esac
done
if [ $? != 0 ]; then description; fi
if [ -z "$reference" ]; then description;
echo -e "The reference sequence -r is missed."; exit 1; fi
if [ -z "$workingDir" ]; then description;
echo -e "The working director -d is missed."; exit 1; fi
#####01.Sequence allignment###############################
# 1. Sequence alignment with bwa.
# 2. Convert file formats of sam to bam.
#
# Parameter : [1](Reference fasta file)
# [2](Workind directory)
#
##########################################################
echo "Reference file $reference."
echo "Working directory with fastq files $workingDir."
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cutoff_freq="0.05"
for fastq in $workingDir/*.fastq
do
echo "Bwa for $fastq"
prefix="${fastq%.fastq}"
bwa mem -t 28 $reference $fastq > "${prefix}.sam"
done
for sam in $workingDir/*.sam
do
echo "Samtools for $sam"
prefix="${sam%.sam}"
samtools view -b $sam > "${prefix}.bam"
done
for bam in $workingDir/*.bam
do
echo "Bamtools sort for $bam"
prefix="${bam%.bam}"
bamtools sort -in $bam -out "${prefix}_sorted.bam"
done
mkdir $workingDir/tmp
mv $workingDir/*_sorted.bam $workingDir/tmp
rm $workingDir/*.bam
mv $workingDir/./tmp/*_sorted.bam .
rm -r $workingDor/tmp
for bam in $workingDir/*.bam
do
removed="${bam%_sorted.bam}"
mv $bam "${removed}.bam"
done
echo "Merge alignment files . . ."
python $DIR/align2sync.py -i $workingDir -r $reference > "{$workingDir}/{$outputPrefix}.sync"
echo "Convert the merged alignment file to .sync format. . ."
java -ea Xmx8g -jar $DIR/mpileup2sync.jar --input "{$workingDir}/{$outputPrefix}.sync" --output "{$workingDir}/{$outputPrefix}.sync" --threads 16
echo "Filtering alleles . . ."
python2 $DIR/filtAF.py -i "{$workingDir}/{$outputPrefix}.sync" -o "{$workingDir}/{$outputPrefix}_filt1.sync"
python2 $DIR/filtZeroAF.py -i "{$workingDir}/{$outputPrefix}_filt1.sync" -o "{$workingDir}/{$outputPrefix}_filt2.sync"
#####02.SNP calling from alignment #########################
# Freebayes to call varient for every bam file in the
# current directory.
#
# Vcftools to filter out indels and take only SNPs.
#
# Parameter : [1](Reference fasta file)
#
############################################################
#echo "Reference file $1."
#for bam in *.bam
#do
# echo "freebayes for $bam"
# prefix="${bam%.bam}"
# freebayes -f $1 $bam >"${prefix}.vcf"
#done
#for vcf in *.vcf
#do
# echo "Filtering indels for $vcf"
# prefix="${vcf%.vcf}"
# vcftools --vcf $vcf --remove-indels --recode --recode-INFO-all --out "${prefix}"
#done
#mkdir tmp
#mv *.recode.vcf tmp
#rm *.vcf
#mv ./tmp/*.vcf .
#rm -r tmp
#vcf-merge *.vcf > merged.vcf
#####02.SNP calling from alignment #########################
# Make allele depth file using vcf files.
############################################################
#for vcf in *.vcf
#do
# echo "Make allele depth for $vcf"
# prefix="${vcf%.vcf}"
# python vcf2AD.py $vcf > "${prefix}.depth"
#done