Class CircularLocation
- java.lang.Object
-
- org.biojava.bio.symbol.AbstractLocationDecorator
-
- org.biojava.bio.symbol.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() methodNote 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
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.symbol.Location
empty, full, naturalOrder
-
-
Constructor Summary
Constructors Constructor Description CircularLocation(Location wrapped, int length)Constructs a CircularLocation by wrapping another Location It is preferable to use LocationTools to make CircularLocationsCircularLocation(Location wrapped, int length, int fivePrimeEnd)Makes a CircularLocation where the 5' end of the Location is specified.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(int p)Checks if this location contains a point.booleancontains(Location l)Checks if this location contains the other.protected Locationdecorate(Location loc)booleanequals(Object o)Checks if this location is equivalent to the other.ListIteratorfivePrimeBlockIterator()Iterates over the location blocks in order starting with the most 5'intget3PrimeEnd()intget5PrimeEnd()The point at which indicates the 5' end of the Location.intgetLength()intgetMax()This will give you the coordinate of the maximum point contained by this Location.intgetMin()This will give you the coordinate of the minimum point contained by this Location.Locationintersection(Location l)Returns a Location that contains all points common to both ranges.booleanisContiguous()Delegates to the wrapped location.booleanoverlaps(Location l)Checks if these two locations overlap, using this location's concept of overlapping.booleanoverlapsOrigin()Does the Location overlap the origin (position 1) of the sequence?SymbolListsymbols(SymbolList seq)Return the symbols in a sequence that fall within this range.StringtoString()Locationunion(Location l)Return a Location containing all points in either ranges.-
Methods inherited from class org.biojava.bio.symbol.AbstractLocationDecorator
blockIterator, getDecorator, getWrapped, newInstance, translate
-
-
-
-
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. ThefivePrimeEndparameter must match one of the minimum coordinates of the wrappedLocation. This allows the creation of Locations whose polarity can be specified. This method is used internally byLocationTools.union()and by the other constructor.- Parameters:
wrapped- theLocationto map to a Circlelength- the lenght of the circlefivePrimeEnd- the 5' polar end of the sequence- Throws:
IllegalArgumentException- if the 5' end doesn't match the min coordinate of eitherwrappedor one of its blocks.
-
-
Method Detail
-
getLength
public final int getLength()
-
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
-
decorate
protected Location decorate(Location loc)
- Specified by:
decoratein classAbstractLocationDecorator
-
contains
public boolean contains(int p)
Description copied from interface:LocationChecks if this location contains a point.- Specified by:
containsin interfaceLocation- Overrides:
containsin classAbstractLocationDecorator- Parameters:
p- the point to check- Returns:
- true if this contains p, otherwise false
-
intersection
public Location intersection(Location l)
Description copied from interface:LocationReturns a Location that contains all points common to both ranges.- Specified by:
intersectionin interfaceLocation- Overrides:
intersectionin classAbstractLocationDecorator- Parameters:
l- the Location to intersect with- Returns:
- a Location containing all points common to both, or the empty range if there are no such points
-
overlaps
public boolean overlaps(Location l)
Description copied from interface:LocationChecks if these two locations overlap, using this location's concept of overlapping.Abstractly, two locations overlap if they both contain any point.
- Specified by:
overlapsin interfaceLocation- Overrides:
overlapsin classAbstractLocationDecorator- Parameters:
l- the Location to check- Returns:
- true if they overlap, otherwise false
-
union
public Location union(Location l)
Description copied from interface:LocationReturn a Location containing all points in either ranges.- Specified by:
unionin interfaceLocation- Overrides:
unionin classAbstractLocationDecorator- Parameters:
l- the Location to union with- Returns:
- a Location representing the union
-
contains
public boolean contains(Location l)
Description copied from interface:LocationChecks 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:
containsin interfaceLocation- Overrides:
containsin classAbstractLocationDecorator- Parameters:
l- the Location to check- Returns:
- true if this contains l, otherwise false
-
equals
public boolean equals(Object o)
Description copied from interface:LocationChecks 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:
equalsin interfaceLocation- Overrides:
equalsin classAbstractLocationDecorator- 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:
isContiguousin interfaceLocation- Overrides:
isContiguousin classAbstractLocationDecorator- 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 togetMin()- Returns:
- the most 5' coordinate
- See Also:
fivePrimeBlockIterator(),getMin(),get3PrimeEnd()
-
get3PrimeEnd
public int get3PrimeEnd()
- Returns:
- the most 3' coordinate
- See Also:
fivePrimeBlockIterator(),getMax(),get5PrimeEnd()
-
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 callget5PrimeEnd()- Specified by:
getMinin interfaceLocation- Overrides:
getMinin classAbstractLocationDecorator- 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 returngetLength(). If you want to be guarenteed of getting the rightmost coordinate then callget3PrimeEnd()- Specified by:
getMaxin interfaceLocation- Overrides:
getMaxin classAbstractLocationDecorator- Returns:
- the maximum coord
- See Also:
get3PrimeEnd()
-
symbols
public SymbolList symbols(SymbolList seq)
Description copied from interface:LocationReturn the symbols in a sequence that fall within this range.- Specified by:
symbolsin interfaceLocation- Overrides:
symbolsin classAbstractLocationDecorator- Parameters:
seq- the SymbolList to process- Returns:
- the SymbolList containing the symbols in seq in this range
-
fivePrimeBlockIterator
public ListIterator fivePrimeBlockIterator()
Iterates over the location blocks in order starting with the most 5'- Returns:
- a ListIterator
- See Also:
AbstractLocationDecorator.blockIterator(),get5PrimeEnd()
-
-