public final class ChromInterval extends java.lang.Object implements IntInterval, java.lang.Comparable<ChromInterval>
Class ChromInterval
represents a chromosome interval whose
end points are genome coordinates.
ChromInterval
are immutable.Constructor and Description |
---|
ChromInterval(Marker start,
Marker end)
Constructs a new
ChromInterval instance. |
ChromInterval(java.lang.String chrom,
int start,
int end)
Constructs a new
ChromInterval instance. |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
chrom()
Returns the chromosome identifier.
|
int |
chromIndex()
Returns the chromosome index.
|
int |
compareTo(ChromInterval o)
Compares this
ChromInteval with the specified
ChromInterval instance for order, and
returns -1, 0, or 1 depending on whether this
is less than, equal or greater than the specified instance. |
int |
end()
Returns the last genome coordinate in this chromosome interval.
|
boolean |
equals(java.lang.Object obj)
Returns
true if the specified object is a
ChromInterval instance representing the same
interval of genome coordinates as this , and
returns false otherwise. |
int |
hashCode()
Returns a hash code value for the object.
|
static ChromInterval |
merge(ChromInterval a,
ChromInterval b)
Returns the union of the specified overlapping chromosome intervals.
|
static boolean |
overlap(ChromInterval a,
ChromInterval b)
Returns
true if the specified chromosome intervals
have non-empty intersection and returns false otherwise. |
static ChromInterval |
parse(java.lang.String str)
Returns a
ChromInterval instance corresponding to the
specified string, or returns null if the specified
string does not represent a valid chromosome interval or if the
specified string is null . |
int |
start()
Returns the first genome coordinate in this chromosome interval.
|
java.lang.String |
toString()
Returns the string:
this.chrom() + ":" + this.start() + "-" + this.end() |
public ChromInterval(Marker start, Marker end)
ChromInterval
instance.start
- the first marker in the interval.end
- the last marker in the interval.java.lang.IllegalArgumentException
- if
start.chromIndex()!=end.chromIndex() ||
start.pos()<0 || start.pos()>end.pos()
.java.lang.NullPointerException
- if
start==null || end==null
.public ChromInterval(java.lang.String chrom, int start, int end)
ChromInterval
instance.chrom
- the chromosome,start
- the first genome coordinate in the interval.end
- the last genome coordinate in the interval.java.lang.IllegalArgumentException
- if
start<0 || start>end || chrom.isEmpty()
.java.lang.NullPointerException
- if chrom==null
.public static ChromInterval parse(java.lang.String str)
Returns a ChromInterval
instance corresponding to the
specified string, or returns null
if the specified
string does not represent a valid chromosome interval or if the
specified string is null
.
[chrom]:[start]-[end] [chrom] [chrom]: [chrom]:[start]- [chrom]:-endwhere
[chrom]
is a chromosome identifier, and
[start]
and [end]
are non-negative
integers satisfying [start]<=[end]
. If the specified
string does not contain a start position, the start()
method of the returned ChromInterval
instance returns 0.
If no end position is specified, the end()
method of the
returned ChromInterval
instance returns
Integer.MAX_VALUE
.str
- a chromosome interval.ChromInterval
instance corresponding to the
specified string, or returns null
if the specified
string does not represent a valid chromosome interval or if the
specified string is null
.public int chromIndex()
ChromIds.indexOf(this.chrom())
.public java.lang.String chrom()
public int start()
start
in interface IntInterval
public int end()
end
in interface IntInterval
public int compareTo(ChromInterval o)
Compares this ChromInteval
with the specified
ChromInterval
instance for order, and
returns -1, 0, or 1 depending on whether this
is less than, equal or greater than the specified instance.
ChromInterval
objects are ordered first by
this.chromIndex()
, then by
this.start()
, and finally by this.end()
.
All fields are ordered in ascending order.compareTo
in interface java.lang.Comparable<ChromInterval>
o
- the ChromInterval
to be compared with this
.this
is less than, equal or greater than the specified instance.public int hashCode()
Returns a hash code value for the object.
The hash code is defined by the following calculation:
int hash = 7; hash = 67 * hash + this.chromIndex(); hash = 67 * hash + this.start(); hash = 67 * hash + this.end();
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
true
if the specified object is a
ChromInterval
instance representing the same
interval of genome coordinates as this
, and
returns false
otherwise.equals
in class java.lang.Object
obj
- the object to be compared with this
for
equality.true
if the specified object is a
ChromInterval
instance representing the same
interval of genome coordinates as this
, and
returns false
otherwise.public java.lang.String toString()
this.chrom() + ":" + this.start() + "-" + this.end()
toString
in class java.lang.Object
this.chrom() + ":" + this.start() + "-" + this.end()
public static boolean overlap(ChromInterval a, ChromInterval b)
true
if the specified chromosome intervals
have non-empty intersection and returns false
otherwise.a
- a chromosome interval.b
- a chromosome interval.true
if the specified chromosome intervals
have non-empty intersection and returns false
otherwise.public static ChromInterval merge(ChromInterval a, ChromInterval b)
a
- a chromosome interval.b
- a chromosome interval.java.lang.IllegalArgumentException
- if
ChromInterval.overlap(a, b)==false
.