This is a test version of Biostars. For the public version, visit https://www.biostars.org.
targeted bed file average coverage

I am trying to modify this very useful post by Michael James Clark which he wrote a perl script to calculate average coverage in a bam.

coverage.pl
($num,$den)=(0,0);
while ($cov=<STDIN>) {
    $num=$num+$cov;
    $den++;
}
$cov=$num/$den;
print "Mean Coverage = $cov\n";

What I am trying to do is use that code to calculate average coverage in a bam for targeted regions in a bed file.

/path/to/samtools view -b in.bam <genomic region> | /path/to/samtools mpileup - | awk '{print $4}' | perl ~/coverage.pl

Thank you :).

next-gen exome

If you looking for alternative, both bedtools and bedmap from bedOpscan do it standalone.

Thank you :)

Thank you, I will try bedtools. Does samtools have a similar feature?

0 answers

No answers yet.

Log in to answer this question.