comparison scripts/get_average_contig_coverage.sh @ 0:05c27700e5ca

initial commit
author biomonika <biomonika@psu.edu>
date Thu, 04 Sep 2014 18:24:19 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:05c27700e5ca
1 #!/bin/bash
2 #get_average_contig_coverage $perc $contig $bam
3 #returns "1" -> #low coverage, "0" -> #in tolerance
4 perc=$1; contig=$2; bam=$3; reference=$4;
5
6 pro_coverage=`samtools mpileup -f $reference -r $contig $bam | cut -f 4 | awk '{s+=$1}END{print s}' 2>/dev/null`;
7
8 if [ -z "$pro_coverage" ]; then
9 coverage=0;
10 else
11 coverage=$pro_coverage;
12 fi
13
14 pro_positions=`samtools mpileup -f $reference -r $contig $bam | wc -l 2>/dev/null`
15
16 if [ -z "$pro_positions" ]; then
17 positions=0;
18 else
19 positions=$pro_positions;
20 fi
21
22 if [[ $positions -eq $zero ]]; then
23 echo "1";
24 exit;
25 fi
26
27
28 average_coverage=`echo "scale=3; $coverage/$positions" | bc`;
29
30 if (( $(echo "$average_coverage < $perc"|bc -l) )); then
31 echo "1"; #low coverage
32 else
33 echo "0"; #in tolerance
34 fi
35
36
37
38