[Bio] / FigKernelPackages / BasicLocation.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/BasicLocation.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8, Fri Feb 3 03:34:04 2006 UTC revision 1.9, Wed Apr 19 03:38:32 2006 UTC
# Line 639  Line 639 
639      return ($loc->Contig, $loc->Begin, $loc->EndPoint);      return ($loc->Contig, $loc->Begin, $loc->EndPoint);
640  }  }
641    
642    =head3 Overlap
643    
644    C<< my $len = $loc->Overlap($b,$e); >>
645    
646    Determine how many positions in this location overlap the specified region. The region is defined
647    by its leftmost and rightmost positions.
648    
649    =over 4
650    
651    =item b
652    
653    Leftmost position in the region to check.
654    
655    =item e
656    
657    Rightmost position in the region to check.
658    
659    =item RETURN
660    
661    Returns the number of overlapping positions, or 0 if there is no overlap.
662    
663    =back
664    
665    =cut
666    #: Return Type $%;
667    sub Overlap {
668        # Get the parameters.
669        my ($self, $b, $e) = @_;
670        # Declare the return variable.
671        my $retVal;
672        # Process according to the type of overlap.
673        if ($b < $self->Left) {
674            # Here the other region extends to our left.
675            if ($e >= $self->Left) {
676                # The other region's right is past our left, so we have overlap. The overlap length
677                # is determined by whether or not we are wholly inside the region.
678                if ($e < $self->Right) {
679                    $retVal = $e - $self->Left + 1;
680                } else {
681                    $retVal = $self->Length;
682                }
683            } else {
684                # The other region ends before we start, so no overlap.
685                $retVal = 0;
686            }
687        } elsif ($b > $self->Right) {
688            # The other region starts after we end, so no overlap.
689            $retVal = 0;
690        } else {
691            # The other region starts inside us.
692            $retVal = $self->Right - $b + 1;
693        }
694        # Return the result.
695        return $retVal;
696    }
697    
698  =head2 Virtual Methods  =head2 Virtual Methods
699    
700  These methods are implemented by the subclasses. They are included here for documentation  These methods are implemented by the subclasses. They are included here for documentation
# Line 837  Line 893 
893  =cut  =cut
894  #: Return Type ;  #: Return Type ;
895    
896    =head3 Upstream
897    
898    C<< my $newLoc = $loc->Upstream($distance, $max); >>
899    
900    Return a new location upstream of the given location, taking care not to
901    extend past either end of the contig.
902    
903    =over 4
904    
905    =item distance
906    
907    Number of positions to add to the front (upstream) of the location.
908    
909    =item max (optional)
910    
911    Maximum possible value for the right end of the location.
912    
913    =item RETURN
914    
915    Returns a new location object whose last position is next to the first
916    position of this location.
917    
918    =back
919    
920    =cut
921    #: Return Type $%;
922    
923    =head3 Truncate
924    
925    C<< $loc->Truncate($len); >>
926    
927    Truncate the location to a new length. If the length is larger than the location length, then
928    the location is not changed.
929    
930    =over 4
931    
932    =item len
933    
934    Proposed new length for the location.
935    
936    =back
937    
938    =cut
939    #: Return Type $%;
940    
941  1;  1;
942    
943    
# Line 1157  Line 1258 
1258      $self->SetEnd($newEnd);      $self->SetEnd($newEnd);
1259  }  }
1260    
1261    =head3 Upstream
1262    
1263    C<< my $newLoc = $loc->Upstream($distance, $max); >>
1264    
1265    Return a new location upstream of the given location, taking care not to
1266    extend past either end of the contig.
1267    
1268    =over 4
1269    
1270    =item distance
1271    
1272    Number of positions to add to the front (upstream) of the location.
1273    
1274    =item max (optional)
1275    
1276    Maximum possible value for the right end of the location.
1277    
1278    =item RETURN
1279    
1280    Returns a new location object whose last position is next to the first
1281    position of this location.
1282    
1283    =back
1284    
1285    =cut
1286    #: Return Type $%;
1287    
1288    sub Upstream {
1289        # Get the parameters.
1290        my ($self, $distance, $max) = @_;
1291        # Subtract the distance from the begin point, keeping the position safe.
1292        my $newBegin = $self->Begin - $distance;
1293        if ($newBegin <= 0) {
1294            $newBegin = 1;
1295        }
1296        # Compute the new length. It may be zero.
1297        my $len = $self->Begin - $newBegin;
1298        # Return the result.
1299        return BasicLocation->new($self->Contig, $newBegin, "+", $len);
1300    }
1301    
1302    =head3 Truncate
1303    
1304    C<< $loc->Truncate($len); >>
1305    
1306    Truncate the location to a new length. If the length is larger than the location length, then
1307    the location is not changed.
1308    
1309    =over 4
1310    
1311    =item len
1312    
1313    Proposed new length for the location.
1314    
1315    =back
1316    
1317    =cut
1318    #: Return Type $%;
1319    sub Truncate {
1320        # Get the parameters.
1321        my ($self, $len) = @_;
1322        # Only proceed if the new length would be shorter.
1323        if ($len < $self->Length) {
1324            $self->SetEnd($self->Begin + $len - 1);
1325        }
1326    }
1327    
1328  1;  1;
1329    
1330  package BBasicLocation;  package BBasicLocation;
# Line 1473  Line 1641 
1641      $self->SetBegin($newEnd);      $self->SetBegin($newEnd);
1642  }  }
1643    
1644    =head3 Upstream
1645    
1646    C<< my $newLoc = $loc->Upstream($distance, $max); >>
1647    
1648    Return a new location upstream of the given location, taking care not to
1649    extend past either end of the contig.
1650    
1651    =over 4
1652    
1653    =item distance
1654    
1655    Number of positions to add to the front (upstream) of the location.
1656    
1657    =item max (optional)
1658    
1659    Maximum possible value for the right end of the location.
1660    
1661    =item RETURN
1662    
1663    Returns a new location object whose last position is next to the first
1664    position of this location.
1665    
1666    =back
1667    
1668    =cut
1669    #: Return Type $%;
1670    
1671    sub Upstream {
1672        # Get the parameters.
1673        my ($self, $distance, $max) = @_;
1674        # Add the distance to the begin point, keeping the position safe.
1675        my $newBegin = $self->Begin + $distance;
1676        if ($max && $newBegin > $max) {
1677            $newBegin = $max;
1678        }
1679        # Compute the new length. It may be zero.
1680        my $len = $newBegin - $self->Begin;
1681        # Return the result.
1682        return BasicLocation->new($self->Contig, $newBegin, "-", $len);
1683    }
1684    
1685    =head3 Truncate
1686    
1687    C<< $loc->Truncate($len); >>
1688    
1689    Truncate the location to a new length. If the length is larger than the location length, then
1690    the location is not changed.
1691    
1692    =over 4
1693    
1694    =item len
1695    
1696    Proposed new length for the location.
1697    
1698    =back
1699    
1700    =cut
1701    #: Return Type $%;
1702    sub Truncate {
1703        # Get the parameters.
1704        my ($self, $len) = @_;
1705        # Only proceed if the new length would be shorter.
1706        if ($len < $self->Length) {
1707            $self->SetEnd($self->Begin - $len + 1);
1708        }
1709    }
1710    
1711  1;  1;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3