Bio-EnsEMBL

 view release on metacpan or  search on metacpan

lib/Bio/EnsEMBL/Mapper.pm  view on Meta::CPAN

      } else {
        $m2->{'end'}--;
      }
      if($strand == -1) {
        if ($include_original_region) {
          $c2->{'mapped'} = $m2;
          unshift @coords, $c2;
        } else {
          unshift @coords, $m2;
        }
      } else {
        if ($include_original_region) {
          $c2->{'mapped'} = $m2;
          push @coords, $c2;
        } else {
          push @coords, $m2;
        }
      }
    }

    # as with @coords == 1 above, if we are in
    # include_original_region mode, then we have
    # to flip back the original region as well
    if ($include_original_region) {
      foreach my $coord (@coords) {
        my $orig = $coord->{'original'};
          ($orig->{'start'}, $orig->{'end'}) =
            ($orig->{'end'}, $orig->{'start'});
      }
    }
  }

  if($fastmap) {
    return undef if(@coords != 1);
    my $c = $include_original_region ? $coords[0]->{'mapped'} : $coords[0];
    return ($c->{'id'}, $c->{'start'}, $c->{'end'},
            $c->{'strand'}, $c->{'coord_system'});
  }

  return @coords;
}






=head2 fastmap

    Arg  1      string $id
                id of 'source' sequence
    Arg  2      int $start
                start coordinate of 'source' sequence
    Arg  3      int $end
                end coordinate of 'source' sequence
    Arg  4      int $strand
                raw contig orientation (+/- 1)
    Arg  5      int $type
                nature of transform - gives the type of
                coordinates to be transformed *from*
    Function    inferior map method. Will only do ungapped unsplit mapping.
                Will return id, start, end strand in a list.
    Returntype  list of results
    Exceptions  none
    Caller      Bio::EnsEMBL::AssemblyMapper

=cut

sub fastmap {
   my ($self, $id, $start, $end, $strand, $type) = @_;

   my ($from, $to, $cs);

   if($end+1 == $start) {
     return $self->map_insert($id, $start, $end, $strand, $type, 1);
   }

   if( ! $self->{'_is_sorted'} ) { $self->_sort() }

   if($type eq $self->{'to'}) {
     $from = 'to';
     $to = 'from';
     $cs = $self->{'from_cs'};
   } else {
     $from = 'from';
     $to = 'to';
     $cs = $self->{'to_cs'};
   }

   my $hash = $self->{"_pair_$type"} or
       throw("Type $type is neither to or from coordinate systems");


   my $pairs = $hash->{uc($id)};

   foreach my $pair (@$pairs) {
     my $self_coord   = $pair->{$from};
     my $target_coord = $pair->{$to};

     # only super easy mapping is done 
     if( $start < $self_coord->{'start'} ||
         $end > $self_coord->{'end'} ) {
       next;
     }

     if( $pair->{'ori'} == 1 ) {
       return ( $target_coord->{'id'},
                $target_coord->{'start'}+$start-$self_coord->{'start'},
                $target_coord->{'start'}+$end-$self_coord->{'start'},
                $strand, $cs );
     } else {
       return ( $target_coord->{'id'},
                $target_coord->{'end'} - ($end - $self_coord->{'start'}),
                $target_coord->{'end'} - ($start - $self_coord->{'start'}),
                -$strand, $cs );
     }
   }

   return ();
}



( run in 1.721 second using v1.01-cache-2.11-cpan-39bf76dae61 )