Mercurial > repos > biomonika > linkyx
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/get_average_contig_coverage.sh Thu Sep 04 18:24:19 2014 -0400 @@ -0,0 +1,38 @@ +#!/bin/bash +#get_average_contig_coverage $perc $contig $bam +#returns "1" -> #low coverage, "0" -> #in tolerance +perc=$1; contig=$2; bam=$3; reference=$4; + +pro_coverage=`samtools mpileup -f $reference -r $contig $bam | cut -f 4 | awk '{s+=$1}END{print s}' 2>/dev/null`; + +if [ -z "$pro_coverage" ]; then + coverage=0; +else + coverage=$pro_coverage; +fi + +pro_positions=`samtools mpileup -f $reference -r $contig $bam | wc -l 2>/dev/null` + +if [ -z "$pro_positions" ]; then + positions=0; +else + positions=$pro_positions; +fi + +if [[ $positions -eq $zero ]]; then + echo "1"; + exit; +fi + + +average_coverage=`echo "scale=3; $coverage/$positions" | bc`; + + if (( $(echo "$average_coverage < $perc"|bc -l) )); then + echo "1"; #low coverage + else + echo "0"; #in tolerance + fi + + + +