forked from ibebio/TIGER_Scripts-for-distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bamtotiger.sh
64 lines (48 loc) · 1.91 KB
/
bamtotiger.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
#!/bin/bash
#samtotiger.sh
#uses sam files to generate vcf files and files for TIGER input
#22 September 2015
#By Beth Rowan
#usage
if [ $# -eq 0 ]
then
echo "bamtotiger.sh <path to sam tools> <reference genome> <path to bcf tools> <path to tiger scripts> <complete_marker_file> <corrected_marker_file> <sampleno>"
exit 1
fi
#variables
SAMDIR=$1
REF=$2
BCFDIR=$3
TIGER=$4
MARKCOMP=$5
MARKCORR=$6
NUM=$7
#Convert sam file to sorted bam file
#from each sample directory
#cd into each directory
for i in $(eval echo {1..$NUM\});
do
cd INDEX$i
#convert to bam
#$SAMDIR/samtools view -bS INDEX$i.fastq.sam > INDEX$i.bam
#sort
$SAMDIR/samtools sort INDEX$i.bam INDEX$i.sorted
#convert sorted bam file to vcf
$SAMDIR/samtools mpileup -vu -f $REF INDEX$i.sorted.bam | $BCFDIR/bcftools call -m -Ov > INDEX$i.vcf
#extract DP4 lines
$BCFDIR/bcftools query -f '%CHROM %POS %REF %ALT %QUAL [ %INDEL %DP %DP4]\n' INDEX$i.vcf -o INDEX$i.comma.txt
#replace comma separators with tabs
tr ',' '\t' < INDEX$i.comma.txt > INDEX$i.tabbed.txt
#get rid of mito and cp reads; create columns for read counts for ref allele and alt allele by adding the first two of the DP4 fields and the second two of the DP4 fields. ##INFO=<ID=DP4,Number=4,Type=Integer,Description="# high-quality ref-forward bases, ref-reverse, alt-forward and alt-reverse bases">
awk '{if ($1 !="ChrC" && $1!="ChrM") print $1 "\t" $2 "\t" $3 "\t" $8+$9 "\t" $4 "\t" $10+$11}' INDEX$i.tabbed.txt > INDEX$i.input.temp
#call bash script to change chromosome column to numbers only (to match TIGER input)
bash $TIGER/chr_convert.sh INDEX$i.input.temp
#filter indels only (to generate "complete" file for TIGER)
perl $TIGER/get_subset.pl input.out 1,2 $MARKCOMP 1,2 0 > input_complete$i.txt
#use stricter filters (to generate "corrected" file for TIGER)
perl $TIGER/get_subset.pl input.out 1,2 $MARKCORR 1,2 0 > input_corrected$i.txt
rm *tabbed*
rm *temp
rm *comma*
cd ../
done