annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
1 #!/bin/bash
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
2 #get_average_contig_coverage $perc $contig $bam
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
3 #returns "1" -> #low coverage, "0" -> #in tolerance
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
4 perc=$1; contig=$2; bam=$3; reference=$4;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
5
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
6 pro_coverage=`samtools mpileup -f $reference -r $contig $bam | cut -f 4 | awk '{s+=$1}END{print s}' 2>/dev/null`;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
7
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
8 if [ -z "$pro_coverage" ]; then
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
9 coverage=0;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
10 else
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
11 coverage=$pro_coverage;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
12 fi
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
13
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
14 pro_positions=`samtools mpileup -f $reference -r $contig $bam | wc -l 2>/dev/null`
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
15
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
16 if [ -z "$pro_positions" ]; then
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
17 positions=0;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
18 else
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
19 positions=$pro_positions;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
20 fi
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
21
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
22 if [[ $positions -eq $zero ]]; then
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
23 echo "1";
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
24 exit;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
25 fi
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
26
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
27
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
28 average_coverage=`echo "scale=3; $coverage/$positions" | bc`;
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
29
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
30 if (( $(echo "$average_coverage < $perc"|bc -l) )); then
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
31 echo "1"; #low coverage
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
32 else
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
33 echo "0"; #in tolerance
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
34 fi
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
35
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
36
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
37
05c27700e5ca initial commit
biomonika <biomonika@psu.edu>
parents:
diff changeset
38