Class CircularLocation

  • All Implemented Interfaces:
    Location

    public class CircularLocation
    extends AbstractLocationDecorator
    Circular view onto an underlying Location instance. If the location overlaps the origin of the sequence the underlying location will be a CompoundLocation Note that in this case isContiguous() will return false. This behaviour is desirable for proper treatment of the location with LocationTools. To find if a location overlaps the origin use the overlapsOrigin() method

    Note also that as a location that overlaps the origin is a compound location it's min will be 1 and its max will be length (by default). In these cases it is imperative to use the block iterator if you wish to know the 'true' min and max (bearing in mind that there is no logical value for a min or max on a circular sequence).

    The symbols() method has been overridden to handle the weirdness of a location crossing the origin.

    Since:
    1.2
    Author:
    Matthew Pocock, Mark Schreiber
    • Constructor Detail

      • CircularLocation

        public CircularLocation​(Location wrapped,
                                int length)
        Constructs a CircularLocation by wrapping another Location It is preferable to use LocationTools to make CircularLocations
        Parameters:
        wrapped - the Location to wrap.
        length - the length of the Sequence
      • CircularLocation

        public CircularLocation​(Location wrapped,
                                int length,
                                int fivePrimeEnd)
        Makes a CircularLocation where the 5' end of the Location is specified. The fivePrimeEnd parameter must match one of the minimum coordinates of the wrapped Location. This allows the creation of Locations whose polarity can be specified. This method is used internally by LocationTools.union() and by the other constructor.
        Parameters:
        wrapped - the Location to map to a Circle
        length - the lenght of the circle
        fivePrimeEnd - the 5' polar end of the sequence
        Throws:
        IllegalArgumentException - if the 5' end doesn't match the min coordinate of either wrapped or one of its blocks.
    • Method Detail

      • overlapsOrigin

        public boolean overlapsOrigin()
        Does the Location overlap the origin (position 1) of the sequence?

        If it does the Location will internally be composed of a CompoundLocation.

        Returns:
        true if it does, false otherwise
      • overlaps

        public boolean overlaps​(Location l)
        Description copied from interface: Location
        Checks if these two locations overlap, using this location's concept of overlapping.

        Abstractly, two locations overlap if they both contain any point.

        Specified by:
        overlaps in interface Location
        Overrides:
        overlaps in class AbstractLocationDecorator
        Parameters:
        l - the Location to check
        Returns:
        true if they overlap, otherwise false
      • contains

        public boolean contains​(Location l)
        Description copied from interface: Location
        Checks if this location contains the other.

        Abstractly, a location contains another if every point in the other location is contained within this one.

        Specified by:
        contains in interface Location
        Overrides:
        contains in class AbstractLocationDecorator
        Parameters:
        l - the Location to check
        Returns:
        true if this contains l, otherwise false
      • equals

        public boolean equals​(Object o)
        Description copied from interface: Location
        Checks if this location is equivalent to the other.

        Abstractly, a location is equal to another if for every point in one it is also in the other. This is equivalent to a.contains(b) && b.contains(a). You should call LocationTools.areEqual after casting l to Location.

        Specified by:
        equals in interface Location
        Overrides:
        equals in class AbstractLocationDecorator
        Parameters:
        o - the Object to check
        Returns:
        true if this equals l, otherwise false
      • isContiguous

        public boolean isContiguous()
        Delegates to the wrapped location. Currently as locations that cross the origin are wrapped CompoundLocations they are not considered contiguous. This is desirable from the point of view of logical operations as it greatly simplifies the calculations of things such as contains, overlaps etc.
        Specified by:
        isContiguous in interface Location
        Overrides:
        isContiguous in class AbstractLocationDecorator
        Returns:
        true if the location is contiguous and doesn't overlap the origin
      • get5PrimeEnd

        public int get5PrimeEnd()
        The point at which indicates the 5' end of the Location. This is needed as compound circular locations have polarity. For example (18..30, 1..12) is not the same as (1..12, 18..30). The 5' coordinate is derived during construction of the Location. In particular during a union operation the 5' coordinate is generally the 5' coordinate of the first location in the union. In the case where this cannot be logically maintained the 5' coordinate will revert to getMin()
        Returns:
        the most 5' coordinate
        See Also:
        fivePrimeBlockIterator(), getMin(), get3PrimeEnd()
      • getMin

        public int getMin()
        This will give you the coordinate of the minimum point contained by this Location. Generally this will be the leftmost end however if the Location crosses the origin then it will actually be the origin that is the minimum point and the method will return 1. If you want to be guarenteed of getting the leftmost coordinate then call get5PrimeEnd()
        Specified by:
        getMin in interface Location
        Overrides:
        getMin in class AbstractLocationDecorator
        Returns:
        the minimum coord
        See Also:
        get5PrimeEnd()
      • getMax

        public int getMax()
        This will give you the coordinate of the maximum point contained by this Location. Generally this will be the rightmost end however if the Location crosses the origin then it will actually be the point before the origin that is the maximum point and the method will return getLength(). If you want to be guarenteed of getting the rightmost coordinate then call get3PrimeEnd()
        Specified by:
        getMax in interface Location
        Overrides:
        getMax in class AbstractLocationDecorator
        Returns:
        the maximum coord
        See Also:
        get3PrimeEnd()