comparison scripts/contains_these_variants.sh @ 9:695d28139f3e

toolshed8
author biomonika <biomonika@psu.edu>
date Tue, 09 Sep 2014 14:31:02 -0400
parents 1955f03f092e
children
comparison
equal deleted inserted replaced
8:983278b1fdb2 9:695d28139f3e
1 #!/bin/bash
2 #input example: perc% bam comp100134_c0_seq1 28 T C
3 #returns true if the alternative allele occurs in >= than perc (%) cases
4
5 perc=$1; bam=$2; contig=$3; position=$4; ref=$5; alt=$6;
6
7 echo contig $contig position $position ref $ref alt $alt >>kontrola;
8
9 depth=0;
10
11 perl ${LINKYX_PATH}/scripts/bam_analysis.pl $bam reference.fasta $contig $position; #writes to mpileup;
12 pro_hits=`grep -w "$alt" mpileup | cut -f2 -d":"`;
13
14 if [ -z "$pro_hits" ]; then
15 hits=0;
16 else
17 hits=$pro_hits;
18 fi
19
20 depth=`grep -w "DEPTH" mpileup | cut -f2 -d":"`;
21
22 echo "hits: " $hits " depth: " $depth >>kontrola;
23
24 if [[ $depth -eq $zero ]]; then
25 echo "0";
26 exit;
27 fi
28
29 if [ $depth -lt 5 ]; then
30 #depth <=4
31 if [ $hits -gt 0 ]; then
32 echo "1"; #in this depth, none of variants can be tolerated
33 else
34 echo "0"; #ok
35 fi
36 else
37 if [ $depth -lt 25 ]; then
38 #depth 5..24
39 if [ $hits -gt 1 ]; then
40 echo "1"; #in this depth, one variant can be tolerated
41 else
42 echo "0"; #ok
43 fi
44 else
45 #depth >=25
46 hits=$[hits*100];
47 percentage=`echo "scale=3; $hits/$depth" | bc`;
48
49 if (( $(echo "$perc < $percentage"|bc -l) )); then
50 echo "1"; #too much of WRONG variants
51 else
52 echo "0"; #in tolerance
53 fi
54 fi
55 fi
56
57