targeted bed file average coverage
0
0
Entering edit mode
9.5 years ago
bioguy24 ▴ 230

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 • 3.3k views
ADD COMMENT
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Thank you :)

ADD REPLY
0
Entering edit mode

Here is a nice blog post describing cumulative coverage across bait regions using bedtools. Very elegant.

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1946 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6