Index: t/CoordinateMapper.t =================================================================== --- t/CoordinateMapper.t (revision 14857) +++ t/CoordinateMapper.t (working copy) @@ -7,7 +7,7 @@ use lib 't/lib'; use BioperlTest; - test_begin(-tests => 175); + test_begin(-tests => 179); use_ok('Bio::Location::Simple'); use_ok('Bio::Coordinate::Pair'); @@ -359,10 +359,18 @@ is $res->match->end, 5; # match more than two -$pos = Bio::Location::Simple->new (-start => 5, -end => 19 ); +my @testres = ( + ['gene', 2, 4, undef], + ['gene', 10, 14, undef], + ['gene', 20, 20, undef] +); + +$pos = Bio::Location::Simple->new (-start => 2, -end => 20 ); ok $res = $transcribe->map($pos); -is $res->each_gap, 2; +is $res->each_gap, 3; is $res->each_match, 2; +my @res = $res->each_gap; +compare (shift @res, shift @testres); @@ -393,7 +401,7 @@ $transcribe->add_mapper($pair1); $transcribe->add_mapper($pair2); ok $transcribe->sort; -my @res; +@res = (); map {push @res, $_->in->start } $transcribe->each_mapper; ok compare_arrays ([5, 15, 25], \@res); @@ -418,7 +426,7 @@ is $res->match->seq_id, '627012'; ## now a split coord -my @testres = ( +@testres = ( [314696, 31917, 31937, -1], [341, 126, 59773, -1], [315843, 5332, 5963, +1] @@ -433,7 +441,7 @@ ## now a simple gap @testres = ( [627011, 7447, 7507, +1], - ["chr1", 273762, 273781, 1] + ["chr1", 273762, 273781, undef] ); $pos = Bio::Location::Simple->new (-start => 273701, -end => 273781, -strand => 1); $res = $mapper->map($pos); @@ -547,6 +555,7 @@ } +use Carp; sub compare { my ($match, $test) = @_; is $match->seq_id eq $test->[0], 1, Index: Bio/Coordinate/Collection.pm =================================================================== --- Bio/Coordinate/Collection.pm (revision 14857) +++ Bio/Coordinate/Collection.pm (working copy) @@ -96,6 +96,7 @@ # Object preamble - inherits from Bio::Root::Root use Bio::Coordinate::Result; use Bio::Coordinate::Result::Gap; +use Set::IntSpan; use base qw(Bio::Root::Root Bio::Coordinate::MapperI); @@ -323,6 +324,8 @@ my ($self,$value) = @_; my $result = Bio::Coordinate::Result->new(-is_remote=>1); + my $gaps = Set::IntSpan->new($value->start . '-' . $value->end); + my $gap_seq_id; # place to stash seq_id of "in" for later. IDMATCH: { @@ -342,10 +345,30 @@ last if $pair->in->start > $value->end; my $subres = $pair->map($value); + + my $gaps_for_this_pair = Set::IntSpan->new(); + map { + $gaps_for_this_pair->U($_->start() . '-' . $_->end()); + $gap_seq_id = $_->seq_id; + } $subres->each_gap(); + $gaps->I($gaps_for_this_pair) if ( $gaps_for_this_pair ); + + $subres->purge_gaps(); $result->add_result($subres); } } + foreach my $span ($gaps->spans()) { + my $gap = Bio::Coordinate::Result::Gap->new(-start => $span->[0], + -end => $span->[1], + -location_type => + $value->location_type + ); + $gap->seq_id($gap_seq_id) if defined $gap_seq_id; + + $result->add_sub_Location($gap); + } + $result->seq_id($result->match->seq_id) if $result->match; unless ($result->each_Location) { #build one gap; Index: Build.PL =================================================================== --- Build.PL (revision 14857) +++ Build.PL (working copy) @@ -30,7 +30,8 @@ 'IO::String' => 0, 'DB_File' => 0, 'Data::Stag' => 0.10, # Bio::SeqIO::swiss, we can change to 'recommend' if needed - 'Scalar::Util' => 0 # not in Perl 5.6.1, arrived in core in 5.7.3 + 'Scalar::Util' => 0, # not in Perl 5.6.1, arrived in core in 5.7.3 + 'Set::IntSpan' => 1.13, }, build_requires => { 'Test::More' => 0,