Subject: | Bio::DB::Sam segfaults when reading a BAM file without reading the header first |
Steps to reproduce:
Run this script, passing in any BAM file:
use Bio::DB::Sam;
$bam=Bio::DB::Bam->open($ARGV[0]);
while ($read=$bam->read1) {
print "segfault\n";
}
Workaround:
Read the header after Bio::DB::Bam->open:
use Bio::DB::Sam;
$bam=Bio::DB::Bam->open($ARGV[0]);
$bam->header;
while ($read=$bam->read1) {
print "works\n";
}
Possible fix:
Change the code block in Bio::DB::Bam bam_open in Sam.xs to be:
RETVAL = bam_open(filename,mode);
bam_header_destroy(bam_header_read(RETVAL));