diff --git a/modules/Bio/EnsEMBL/Mapper.pm b/modules/Bio/EnsEMBL/Mapper.pm index c579d576e009408046cc81ab230b05a97f6b82f5..a86e6ec93fbb12e8e37b9a19e699afa11980c755 100644 --- a/modules/Bio/EnsEMBL/Mapper.pm +++ b/modules/Bio/EnsEMBL/Mapper.pm @@ -149,91 +149,70 @@ sub map_coordinates{ my $last_used_pair; my @result; - my ( $start_idx, $end_idx, $mid_idx, $pair, $self_coord ); - my $lr = $hash->{uc($id)}; - - $start_idx = 0; - $end_idx = $#$lr; - - # binary search the relevant pairs - # helps if the list is big - while(( $end_idx - $start_idx ) <= 1 ) { - $mid_idx = ($start_idx+$end_idx)>>1; - $pair = $lr->[$mid_idx]; - $self_coord = $pair->{$from}; - if( $self_coord->{'end'} < $start ) { - $start_idx = $mid_idx; - } else { - $end_idx = $mid_idx; - } - } + foreach my $pair ( @{$hash->{uc($id)}} ) { + my $self_coord = $pair->{$from}; + my $target_coord = $pair->{$to}; - my $i = $start_idx; - for( my $i = $start_idx; $i<=$#$lr; $i++ ) { - $pair = $lr->[$i]; - my $self_coord = $pair->{$from}; - my $target_coord = $pair->{$to}; + # if we haven't even reached the start, move on + if( $self_coord->{'end'} < $start ) { + next; + } - # if we haven't even reached the start, move on - if( $self_coord->{'end'} < $start ) { - next; - } - - # if we have over run, break - if( $self_coord->{'start'} > $end ) { - last; - } + # if we have over run, break + if( $self_coord->{'start'} > $end ) { + last; + } - if( $start < $self_coord->{'start'} ) { - # gap detected - my $gap = Bio::EnsEMBL::Mapper::Gap->new($start, - $self_coord->{'start'}-1); - - push(@result,$gap); - $start = $gap->{'end'}+1; - } - - my ($target_start,$target_end,$target_ori); - - # start is somewhere inside the region - if( $pair->{'ori'} == 1 ) { - $target_start = - $target_coord->{'start'} + ($start - $self_coord->{'start'}); - } else { - $target_end = - $target_coord->{'end'} - ($start - $self_coord->{'start'}); - } - - # either we are enveloping this map or not. If yes, then end - # point (self perspective) is determined solely by target. If not - # we need to adjust + if( $start < $self_coord->{'start'} ) { + # gap detected + my $gap = Bio::EnsEMBL::Mapper::Gap->new($start, + $self_coord->{'start'}-1); + + push(@result,$gap); + $start = $gap->{'end'}+1; + } + + my ($target_start,$target_end,$target_ori); - if( $end > $self_coord->{'end'} ) { - # enveloped + # start is somewhere inside the region if( $pair->{'ori'} == 1 ) { - $target_end = $target_coord->{'end'}; + $target_start = + $target_coord->{'start'} + ($start - $self_coord->{'start'}); } else { - $target_start = $target_coord->{'start'}; + $target_end = + $target_coord->{'end'} - ($start - $self_coord->{'start'}); } - } else { - # need to adjust end - if( $pair->{'ori'} == 1 ) { - $target_end = - $target_coord->{'start'} + ($end - $self_coord->{'start'}); + + # either we are enveloping this map or not. If yes, then end + # point (self perspective) is determined solely by target. If not + # we need to adjust + + if( $end > $self_coord->{'end'} ) { + # enveloped + if( $pair->{'ori'} == 1 ) { + $target_end = $target_coord->{'end'}; + } else { + $target_start = $target_coord->{'start'}; + } } else { - $target_start = - $target_coord->{'end'} - ($end - $self_coord->{'start'}); + # need to adjust end + if( $pair->{'ori'} == 1 ) { + $target_end = + $target_coord->{'start'} + ($end - $self_coord->{'start'}); + } else { + $target_start = + $target_coord->{'end'} - ($end - $self_coord->{'start'}); + } } - } - my $res = Bio::EnsEMBL::Mapper::Coordinate->new($target_coord->{'id'}, + my $res = Bio::EnsEMBL::Mapper::Coordinate->new($target_coord->{'id'}, $target_start, $target_end, $pair->{'ori'} * $strand); - push(@result,$res); - - $last_used_pair = $pair; - $start = $self_coord->{'end'}+1; + push(@result,$res); + + $last_used_pair = $pair; + $start = $self_coord->{'end'}+1; } if( !defined $last_used_pair ) {