htsjdk.samtools.util
Class Interval

java.lang.Object
  extended by htsjdk.samtools.util.Interval
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Interval>

public class Interval
extends java.lang.Object
implements java.lang.Comparable<Interval>, java.lang.Cloneable

Represents a simple interval on a sequence. Coordinates are 1-based closed ended.


Constructor Summary
Interval(java.lang.String sequence, int start, int end)
          Constructs an interval with the supplied sequence and start and end.
Interval(java.lang.String sequence, int start, int end, boolean negative, java.lang.String name)
          Constructs an interval with the supplied sequence and start, end, strand and name.
 
Method Summary
 boolean abuts(Interval other)
          Returns true if this interval overlaps the other interval, otherwise false.
 Interval clone()
           
 int compareTo(Interval that)
          Sort based on sequence.compareTo, then start pos, then end pos with null objects coming lexically last
static long countBases(java.util.Collection<Interval> intervals)
          Counts the total number of bases a collection of intervals.
 boolean equals(java.lang.Object other)
          Equals method that agrees with compareTo(Interval).
 int getEnd()
          Gets the 1-based closed-ended end position of the interval on the sequence.
 int getIntersectionLength(Interval other)
           
 java.lang.String getName()
          Returns the name of the interval, possibly null.
 java.lang.String getSequence()
          Gets the name of the sequence on which the interval resides.
 int getStart()
          Gets the 1-based start position of the interval on the sequence.
 int hashCode()
           
 Interval intersect(Interval that)
          Returns a new Interval that represents the intersection between the two intervals.
 boolean intersects(Interval other)
          Returns true if this interval overlaps the other interval, otherwise false.
 boolean isNegativeStrand()
          Returns true if the interval is on the negative strand, otherwise false.
 boolean isPositiveStrand()
          Returns true if the interval is on the positive strand, otherwise false.
 int length()
          Gets the length of this interval.
 Interval pad(int left, int right)
          Returns a new interval that is padded by the amount of bases specified on either side.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interval

public Interval(java.lang.String sequence,
                int start,
                int end)
Constructs an interval with the supplied sequence and start and end. If the end position is less than the start position an exception is thrown.

Parameters:
sequence - the name of the sequence
start - the start position of the interval on the sequence
end - the end position of the interval on the sequence

Interval

public Interval(java.lang.String sequence,
                int start,
                int end,
                boolean negative,
                java.lang.String name)
Constructs an interval with the supplied sequence and start, end, strand and name. If the end position is less than the start position an exception is thrown.

Parameters:
sequence - the name of the sequence
start - the start position of the interval on the sequence
end - the end position of the interval on the sequence
negative - true to indicate negative strand, false otherwise
name - the name (possibly null) of the interval
Method Detail

getSequence

public java.lang.String getSequence()
Gets the name of the sequence on which the interval resides.


getStart

public int getStart()
Gets the 1-based start position of the interval on the sequence.


getEnd

public int getEnd()
Gets the 1-based closed-ended end position of the interval on the sequence.


isNegativeStrand

public boolean isNegativeStrand()
Returns true if the interval is on the negative strand, otherwise false.


isPositiveStrand

public boolean isPositiveStrand()
Returns true if the interval is on the positive strand, otherwise false.


getName

public java.lang.String getName()
Returns the name of the interval, possibly null.


intersects

public boolean intersects(Interval other)
Returns true if this interval overlaps the other interval, otherwise false.


getIntersectionLength

public int getIntersectionLength(Interval other)

intersect

public Interval intersect(Interval that)
Returns a new Interval that represents the intersection between the two intervals.


abuts

public boolean abuts(Interval other)
Returns true if this interval overlaps the other interval, otherwise false.


length

public int length()
Gets the length of this interval.


pad

public Interval pad(int left,
                    int right)
Returns a new interval that is padded by the amount of bases specified on either side.


countBases

public static long countBases(java.util.Collection<Interval> intervals)
Counts the total number of bases a collection of intervals.


compareTo

public int compareTo(Interval that)
Sort based on sequence.compareTo, then start pos, then end pos with null objects coming lexically last

Specified by:
compareTo in interface java.lang.Comparable<Interval>

equals

public boolean equals(java.lang.Object other)
Equals method that agrees with compareTo(Interval).

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public Interval clone()
Overrides:
clone in class java.lang.Object