|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javagene.seq.Location
public class 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, ie 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.
Constructor Summary | |
---|---|
Location(int start,
int end)
Construct new location from coordinates. |
|
Location(Location other)
Clone other location. |
Method Summary | |
---|---|
int |
bioEnd()
Get end index, in biocoordinates. |
int |
bioStart()
Get start index, in biocoordinates. |
char |
bioStrand()
Get character representation of strand. |
int |
compareTo(Location other)
Compare the starting indices (implements Comparable.compareTo()) |
boolean |
contains(Location other)
Check if this location contains the other. |
int |
distance(Location other)
Return distance between this location and the other location. |
Location |
downstream(int length)
Return the adjacent location of specified length directly downstream of this location. |
int |
end()
Get the ending index. |
boolean |
endsAfter(Location other)
Check if this location ends after other location ends. |
boolean |
endsBefore(Location other)
Check if this location ends before other location ends. |
boolean |
equals(Location other)
Compare locations for equality. |
static Location |
fromBio(int start,
int end,
char strand)
Create location from "biocoordinates", as in GFF file. |
static Location |
fromBioExt(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. |
Location |
intersection(Location other)
Return the intersection, or null if no overlap. |
boolean |
isAfter(Location other)
Check if this location is entirely after the other location (no overlap). |
boolean |
isBefore(Location other)
Check if this location is entirely before other location (no overlap). |
boolean |
isNegative()
Check if location is on negative strand. |
boolean |
isSameStrand(Location other)
Check if this location is on same strand as other location. |
LocIterator |
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). |
LocIterator |
iterator(int windowSize,
int increment)
Create a location iterator over this location, using specified window size and increment. |
int |
length()
Get length of range. |
Location |
minus()
Return location that is in same position on negative strand. |
Location |
opposite()
Return location that is in same position on opposite strand. |
boolean |
overlaps(Location other)
Check if this location and other location overlap. |
double |
percentOverlap(Location other)
Return percent overlap of two locations. |
Location |
plus()
Return location that is in same position on plus strand. |
Location |
prefix(int position)
The part of this location before the specified position. |
Location |
prefix(Location other)
The part of this location before the other location (not inclusive). |
int |
start()
Get starting index (origin 0). |
boolean |
startsAfter(Location other)
Check if this location starts after the other location starts. |
boolean |
startsBefore(Location other)
Check if this location starts before other location starts. |
Location |
suffix(int position)
The part of this location after the specified position. |
Location |
suffix(Location other)
The part of this location after the other location (not inclusive). |
java.lang.String |
toString()
Return a string representation of location. |
Location |
union(Location other)
Return the union. |
Location |
upstream(int length)
Return the adjacent location of specified length directly upstream of this location. |
java.lang.Iterable<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.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Location(int start, int end)
start
- Origin 0 index of first symbol.end
- Origin 0 index of last symbol + 1.
java.lang.IllegalArgumentException
- End is not after start, or location spans the originpublic Location(Location other)
other
- The location to clone.Method Detail |
---|
public int bioEnd()
public int bioStart()
public char bioStrand()
public int compareTo(Location other)
compareTo
in interface java.lang.Comparable<Location>
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean contains(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public int distance(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public Location downstream(int length)
length
- The length of the downstream location.
java.lang.IndexOutOfBoundsException
- Specified length causes crossing of origin.public int end()
public boolean endsAfter(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean endsBefore(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean equals(Location other)
other
- The location to compare.
public static Location fromBio(int start, int end, char strand)
start
- Origin 1 index of first symbol.end
- Origin 1 index of last symbol.strand
- '+' or '-' or '.' ('.' is interpreted as '+').
java.lang.IllegalArgumentException
- strand must be '+', '-' or '.'public static Location fromBioExt(int start, int length, char strand, int totalLength)
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.
java.lang.IllegalArgumentException
- Strand must be '+', '-', '.'public Location intersection(Location other)
other
- The location to intersect.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean isAfter(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean isBefore(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean isNegative()
public boolean isSameStrand(Location other)
other
- The location to compare.
public LocIterator iterator()
iterator
in interface java.lang.Iterable<Location>
public LocIterator iterator(int windowSize, int increment)
windowSize
- The number of symbols to get on each iteration.increment
- The direction and number of symbols to advance at each iteration.
public int length()
public Location minus()
public Location opposite()
public boolean overlaps(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public double percentOverlap(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public Location plus()
public Location prefix(int position)
position
- Where the prefix ends.
java.lang.IndexOutOfBoundsException
- Specified prefix is longer than location.public Location prefix(Location other)
other
- The other location.
java.lang.IllegalArgumentException
- Locations are on opposite strands.
java.lang.IndexOutOfBoundsException
- This location does not contain other location.public int start()
public boolean startsAfter(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public boolean startsBefore(Location other)
other
- The location to compare.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public Location suffix(int position)
position
- Where the suffix starts.
java.lang.IndexOutOfBoundsException
- Specified suffix is longer than location.public Location suffix(Location other)
other
- The other location.
java.lang.IllegalArgumentException
- Locations are on opposite strands.
java.lang.IndexOutOfBoundsException
- This location does not contain other location.public java.lang.String toString()
toString
in class java.lang.Object
public Location union(Location other)
other
- The location to join.
java.lang.IllegalArgumentException
- Locations are on opposite strands.public Location upstream(int length)
length
- The length of the upstream location.
java.lang.IndexOutOfBoundsException
- Specified length causes crossing of origin.public java.lang.Iterable<Location> window(int windowSize, int increment)
//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 }
windowSize
- The number of symbols to get on each iteration.increment
- The direction and number of symbols to advance at each iteration.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |