Subject: | Error in get_directory() function |
Date: | Wed, 24 Feb 2010 23:41:49 -0800 |
To: | bug-Bio-Trace-ABIF [...] rt.cpan.org |
From: | PF <kernel [...] pkts.ca> |
Hi..
I'm tinkering with ABIF files, and I think I found a bug. I wrote a
test program that uses Bio::Trace::ABIF to extract the raw data for
channel 1 in two ways, once with $abif->raw_data_for_channel(1), and
once with $abif->get_directory("DATA",1). If everything is working
correctly, it should generate the same data. Here is the test program:
#!/usr/bin/perl -w
use strict;
use Bio::Trace::ABIF;
my $abif = Bio::Trace::ABIF->new();
$abif->open_abif("input.bin");
my @track = $abif->raw_data_for_channel(1);
open(OUT,">output.bin"); print OUT pack("n*",@track);
close(OUT);
my %D=$abif->get_directory("DATA",1);
open(OUT,">output2.bin"); print OUT $D{'DATA_ITEM'}; close(OUT);
$abif->close_abif();
system("md5sum output.bin output2.bin");
The problem is that the get_directory() function is returning bad data;
looking at it with a hex editor you can see the start of the input file.
The fix is the attached patch, the heart of which is this:
- $field = map { ($_ < $LONG_MID) ? $_ : $_ - $LONG_MAX }
- unpack('N', $field);
- seek($self->{'_FH'}, $field, 0);
+ $flength=unpack('N',$field);
+ if ($flength>$LONG_MID) {$flength-=$LONG_MAX;}
+ seek($self->{'_FH'}, $flength, 0);
$field gets set to 1 because map returns an array of length 1. It's a
clever bit of code, but it was never tested. :-(
--
PF <kernel@pkts.ca>
Message body is not shown because sender requested not to inline it.