Subject: | Documentation bug |
Date: | Thu, 13 Dec 2012 12:02:06 -0800 |
To: | bug-Bio-SamTools [...] rt.cpan.org |
From: | Michael Rogoff <miker [...] htblis.com> |
In the pileup example at http://search.cpan.org/~lds/Bio-SamTools/lib/Bio/DB/Sam.pm#The_generic_fetch()_and_pileup()_methods
I believe the example code is incorrect.
my $depth = 0;
my $positions = 0;
my $callback = sub {
my ($seqid,$pos,$pileup) = @_;
next unless $pos >= 501 && $pos <= 600;
$positions++;
$depth += @$pileup;
}
$sam->pileup('seq1:501-600',$callback);
print "coverage = ",$depth/$positions;
Specifically, the callback method. I think the 'next' is out of context and will cause unexpected results if the callback is defined in a loop. I think the callback should simply do nothing if the reported position is outside the requested range, as shown below. As a side note a semi-colon is needed after the callback definition.
my $depth = 0;
my $positions = 0;
my $callback = sub {
my ($seqid,$pos,$pileup) = @_;
if ($pos >= 501 && $pos <= 600) {
$positions++;
$depth += @$pileup;
}
};
$sam->pileup('seq1:501-600',$callback);
print "coverage = ",$depth/$positions;