Class Location
java.lang.Object
org.biojava.nbio.genome.parsers.gff.Location
A location on a sequence.
 A location is a contiguous range of indices, with a single start and end point.
 
Internally, location indices are stored in Java "half-open" format: the start is the (origin 0) index of the first symbol in the range; the end is the origin 0 index of the first symbol PAST the end of the range, so that end - start == length.
Location objects, once constructed, cannot be changed. Instead, all methods return a new location. This allows the use of "method chaining" to implement a particular calculation. For example, consider the chained statement "loc.prefix( 100 ).suffix( 10 )", which first applies the prefix method to the variable named loc, and then the suffix method to the result. Together, the chained operations create a new location object of length 10 whose start is the index of the 90th symbol. Here's another example. This one returns a location object holding the coordinates of the intron between the first exon (location exon1) and the second exon (location exon2) on a sequence (seq): "seq.prefix( exon2 ).suffix( exon1 )"
About the negative (reverse) strand: The location object stores reverse strand locations as negative indices. For example, the positive strand location from index 12 to index 97 is on the opposite side as index -97 (start) to index -12 (end). Note that the larger index is always downstream from the smaller index, (i.e. start <= end, regardless of strand). Obviously this representation makes it trivial to convert a location from one strand to the other.
Additional points regarding the use of locations on opposite strands:
(1) Opposite strand locations cannot be compared, eg isBefore() will throw an exception.
(2) Containment queries ( eg overlaps(), contains() ) also throw exceptions.
(3) The plus() method will map a location to its positive strand equivalent; use it on both args before calling, for example the intersection() method, if your code needs to be indifferent to strand.
Exceptions and how they are (typically) used:
IllegalArgumentException - the location given as a parameter is not on the same strand as the location.
IndexOutOfBoundsException - often means the operation caused the location to span the origin, ie be partially on positive and partially on negative strand.
Internally, location indices are stored in Java "half-open" format: the start is the (origin 0) index of the first symbol in the range; the end is the origin 0 index of the first symbol PAST the end of the range, so that end - start == length.
Location objects, once constructed, cannot be changed. Instead, all methods return a new location. This allows the use of "method chaining" to implement a particular calculation. For example, consider the chained statement "loc.prefix( 100 ).suffix( 10 )", which first applies the prefix method to the variable named loc, and then the suffix method to the result. Together, the chained operations create a new location object of length 10 whose start is the index of the 90th symbol. Here's another example. This one returns a location object holding the coordinates of the intron between the first exon (location exon1) and the second exon (location exon2) on a sequence (seq): "seq.prefix( exon2 ).suffix( exon1 )"
About the negative (reverse) strand: The location object stores reverse strand locations as negative indices. For example, the positive strand location from index 12 to index 97 is on the opposite side as index -97 (start) to index -12 (end). Note that the larger index is always downstream from the smaller index, (i.e. start <= end, regardless of strand). Obviously this representation makes it trivial to convert a location from one strand to the other.
Additional points regarding the use of locations on opposite strands:
(1) Opposite strand locations cannot be compared, eg isBefore() will throw an exception.
(2) Containment queries ( eg overlaps(), contains() ) also throw exceptions.
(3) The plus() method will map a location to its positive strand equivalent; use it on both args before calling, for example the intersection() method, if your code needs to be indifferent to strand.
Exceptions and how they are (typically) used:
IllegalArgumentException - the location given as a parameter is not on the same strand as the location.
IndexOutOfBoundsException - often means the operation caused the location to span the origin, ie be partially on positive and partially on negative strand.
- Author:
- Hanno Hinsch
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionintbioEnd()Get end index, in biocoordinates.intbioStart()Get start index, in biocoordinates.charGet character representation of strand.booleanCheck if this location contains the other.intReturn distance between this location and the other location.downstream(int length) Return the adjacent location of specified length directly downstream of this location.intend()Get the ending index.booleanCheck if this location ends after other location ends.booleanendsBefore(Location other) Check if this location ends before other location ends.booleanstatic LocationfromBio(int start, int end, char strand) Create location from "biocoordinates", as in GFF file.static LocationfromBioExt(int start, int length, char strand, int totalLength) Create a location from MAF file coordinates, which represent negative strand locations as the distance from the end of the sequence.intgetBegin()intgetEnd()inthashCode()intersection(Location other) Return the intersection, or null if no overlap.booleanCheck if this location is entirely after the other location (no overlap).booleanCheck if this location is entirely before other location (no overlap).booleanCheck if location is on negative strand.booleanisSameStrand(Location other) Check if this location is on same strand as other location.iterator()Create a location iterator over this location with a window size of 1 and an increment of +1 (successive symbols from start to end).iterator(int windowSize, int increment) Create a location iterator over this location, using specified window size and increment.intlength()Get length of range.minus()Return location that is in same position on negative strand.opposite()Return location that is in same position on opposite strand.booleanCheck if this location and other location overlap.doublepercentOverlap(Location other) Return percent overlap of two locations.plus()Return location that is in same position on plus strand.prefix(int position) The part of this location before the specified position.The part of this location before the other location (not inclusive).intstart()Get starting index (origin 0).booleanstartsAfter(Location other) Check if this location starts after the other location starts.booleanstartsBefore(Location other) Check if this location starts before other location starts.suffix(int position) The part of this location after the specified position.The part of this location after the other location (not inclusive).toString()Return a string representation of location.Return the union.upstream(int length) Return the adjacent location of specified length directly upstream of this location.window(int windowSize, int increment) Enable a "sliding window" iteration over a location to use with Java's "for" loop construct.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Constructor Details- 
LocationConstruct new location from coordinates. See package description of coordinate format.- Parameters:
- start- Origin 0 index of first symbol.
- end- Origin 0 index of last symbol + 1.
- Throws:
- IllegalArgumentException- End is not after start, or location spans the origin
 
- 
LocationClone other location.- Parameters:
- other- The location to clone.
 
 
- 
- 
Method Details- 
getBegin
- 
getEnd
- 
fromBioCreate location from "biocoordinates", as in GFF file. In biocoordinates, the start index of a range is represented in origin 1 (ie the very first index is 1, not 0), and end= start + length - 1.- Parameters:
- start- Origin 1 index of first symbol.
- end- Origin 1 index of last symbol.
- strand- '+' or '-' or '.' ('.' is interpreted as '+').
- Returns:
- Created location.
- Throws:
- IllegalArgumentException- strand must be '+', '-' or '.'
 
- 
fromBioExtCreate a location from MAF file coordinates, which represent negative strand locations as the distance from the end of the sequence.- Parameters:
- start- Origin 1 index of first symbol.
- length- Number of symbols in range.
- strand- '+' or '-' or '.' ('.' is interpreted as '+').
- totalLength- Total number of symbols in sequence.
- Throws:
- IllegalArgumentException- Strand must be '+', '-', '.'
 
- 
bioStrandGet character representation of strand.- Returns:
- '+' or '-'
 
- 
bioStartGet start index, in biocoordinates.- Returns:
- The origin 1 index of the first symbol in location.
 
- 
bioEndGet end index, in biocoordinates.- Returns:
- The origin 1 index of the final symbol in location.
 
- 
plusReturn location that is in same position on plus strand. If location is already on plus strand, just return the location unchanged.- Returns:
- Location on plus strand.
 
- 
minusReturn location that is in same position on negative strand. If location is already on negative strand, just return the location unchanged.- Returns:
- Location on negative strand.
 
- 
unionReturn the union.- Parameters:
- other- The location to join.
- Returns:
- The union is a range that starts at the lesser of the two starting indices and ends at the greater of the two ends.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
intersectionReturn the intersection, or null if no overlap.- Parameters:
- other- The location to intersect.
- Returns:
- The maximal location that is contained by both. Returns null if no overlap!
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
startGet starting index (origin 0).- Returns:
- The start index.
 
- 
endGet the ending index.- Returns:
- The index of last symbol + 1 (remember Java half-open coordinates).
 
- 
lengthGet length of range.- Returns:
- The length of the range (end - start).
 
- 
windowEnable a "sliding window" iteration over a location to use with Java's "for" loop construct. The returned helper object implements the Iterable interface; the windowSize and increment semantics are implemented by an underlying LocIterator.
 For example, given a location variable "loc":
 //use window size of 3 and increment of +3 for( Location temp: loc.window( 3, 3 )) { //at each iteration, temp will be the location of the next 3 symbols }- Parameters:
- windowSize- The number of symbols to get on each iteration.
- increment- The direction and number of symbols to advance at each iteration.
- Returns:
- An anonymous iterable object to use with Java's for( ... ) loop construct.
 
- 
iteratorCreate a location iterator over this location with a window size of 1 and an increment of +1 (successive symbols from start to end).
- 
iteratorCreate a location iterator over this location, using specified window size and increment.- Parameters:
- windowSize- The number of symbols to get on each iteration.
- increment- The direction and number of symbols to advance at each iteration.
- Returns:
- An iterator over a Location (a LocIterator object).
 
- 
prefixThe part of this location before the specified position. If position is negative, count backwards from the end.
 For position >= 0, return Location( start, start + position ).
 For position < 0, return Location( start, end + position ).- Parameters:
- position- Where the prefix ends.
- Returns:
- New location from start of this location to directly before position.
- Throws:
- IndexOutOfBoundsException- Specified prefix is longer than location.
 
- 
suffixThe part of this location after the specified position. If position is negative, count backwards from the end.
 For position >= 0, return Location( start + position, end ).
 For position < 0, return Location( end - position, end ).- Parameters:
- position- Where the suffix starts.
- Returns:
- New location from position to end of this location.
- Throws:
- IndexOutOfBoundsException- Specified suffix is longer than location.
 
- 
prefixThe part of this location before the other location (not inclusive).- Parameters:
- other- The other location.
- Returns:
- The part of this location before the other location.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
- IndexOutOfBoundsException- This location does not contain other location.
 
- 
suffixThe part of this location after the other location (not inclusive).- Parameters:
- other- The other location.
- Returns:
- The part of this location after the other location.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
- IndexOutOfBoundsException- This location does not contain other location.
 
- 
upstreamReturn the adjacent location of specified length directly upstream of this location.- Parameters:
- length- The length of the upstream location.
- Returns:
- Upstream location.
- Throws:
- IndexOutOfBoundsException- Specified length causes crossing of origin.
 
- 
downstreamReturn the adjacent location of specified length directly downstream of this location.- Parameters:
- length- The length of the downstream location.
- Returns:
- The downstream location.
- Throws:
- IndexOutOfBoundsException- Specified length causes crossing of origin.
 
- 
distanceReturn distance between this location and the other location. Distance is defined only if both locations are on same strand.- Parameters:
- other- The location to compare.
- Returns:
- The integer distance. Returns -1 if they overlap; 0 if directly adjacent.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
percentOverlapReturn percent overlap of two locations.- Parameters:
- other- The location to compare.
- Returns:
- 100.0 * intersection(other).length() / this.length()
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
overlapsCheck if this location and other location overlap.- Parameters:
- other- The location to compare.
- Returns:
- True if they overlap.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
containsCheck if this location contains the other.- Parameters:
- other- The location to compare.
- Returns:
- True if other is entirely contained by this location.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
startsAfterCheck if this location starts after the other location starts. The locations may overlap.- Parameters:
- other- The location to compare.
- Returns:
- True if this starts after other.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
startsBeforeCheck if this location starts before other location starts. The locations may overlap.- Parameters:
- other- The location to compare.
- Returns:
- True if this starts before other.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
endsAfterCheck if this location ends after other location ends. The locations may overlap.- Parameters:
- other- The location to compare.
- Returns:
- True if location ends after other.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
endsBeforeCheck if this location ends before other location ends. The locations may overlap.- Parameters:
- other- The location to compare.
- Returns:
- True if this ends before other.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
isAfterCheck if this location is entirely after the other location (no overlap).- Parameters:
- other- The location to compare.
- Returns:
- True if this is after other.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
isBeforeCheck if this location is entirely before other location (no overlap).- Parameters:
- other- The location to compare.
- Returns:
- True if this is before other.
- Throws:
- IllegalArgumentException- Locations are on opposite strands.
 
- 
isNegativeCheck if location is on negative strand. Note that Location( 0, 0 ) is by construction defined to be on the positive strand.- Returns:
- True if on negative (reverse) strand.
 
- 
oppositeReturn location that is in same position on opposite strand.- Returns:
- Location on opposite strand.
 
- 
isSameStrandCheck if this location is on same strand as other location.- Parameters:
- other- The location to compare.
- Returns:
- True if on same strand.
 
- 
toStringReturn a string representation of location.
- 
hashCode
- 
equals
 
-