# Class Interval

java.lang.Object
htsjdk.samtools.util.Interval

All Implemented Interfaces:
  `Locatable, Feature, NamedFeature, Cloneable, Comparable<Interval>`

public class Interval extends Object implements Comparable<Interval>, Cloneable, NamedFeature
Represents a simple interval on a sequence. Coordinates are 1-based closed ended.

## Constructor Summary

Constructors
Constructor
Description
`Interval(Locatable locatable)`
Constructs an interval with the supplied `Locatable`.
`Interval(String sequence, int start, int end)`
Constructs an interval with the supplied sequence and start and end.
`Interval(String sequence, int start, int end, boolean negative, String name)`
Constructs an interval with the supplied sequence and start, end, strand and name.

## Method Summary

Modifier and Type
Method
Description
`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(Collection<Interval> intervals)`
Counts the total number of bases a collection of intervals.
`boolean`
`equals(Object other)`
Equals method that agrees with `compareTo(Interval)`.
`boolean`
`equalsWithStrandAndName(Object other)`
Equals method that also checks strand and name
`String`
`getContig()`
Gets the contig name for the contig this is mapped to.
`int`
`getEnd()`
`int`
`getIntersectionLength(Interval other)`
`String`
`getName()`
Returns the name of the interval, possibly null.
`String`
`getSequence()`
Deprecated.
use getContig() instead
`int`
`getStart()`
`Strand`
`getStrand()`
Return the `Strand` this interval is on.
`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.
`String`
`toString()`

### Methods inherited from class Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface Feature

`getChr`

### Methods inherited from interface Locatable

`contains, contigsMatch, getLengthOnReference, overlaps, withinDistanceOf`

## Constructor Details

### Interval

public Interval(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(Locatable locatable)
Constructs an interval with the supplied `Locatable`.

### Interval

public Interval(String sequence, int start, int end, boolean negative, 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 Details

### getSequence

@Deprecated public String getSequence()
Deprecated.
use getContig() instead
Gets the name of the sequence on which the interval resides. This is a simple alias of getContig()

### 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.

### getStrand

public Strand getStrand()
Return the `Strand` this interval is on.

### getName

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

Specified by:
  `getName` in interface `NamedFeature`

### 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(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 `Comparable<Interval>`

### equals

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

Overrides:
  `equals` in class `Object`

### equalsWithStrandAndName

public boolean equalsWithStrandAndName(Object other)
Equals method that also checks strand and name

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### clone

public Interval clone()

Overrides:
  `clone` in class `Object`

### getContig

public String getContig()
Description copied from interface: `Locatable`
Gets the contig name for the contig this is mapped to. May return null if there is no unique mapping.

Specified by:
  `getContig` in interface `Locatable`
Returns:
  name of the contig this is mapped to, potentially null

### getStart

public int getStart()

Specified by:
  `getStart` in interface `Locatable`
Returns:
  1-based start position, undefined if getContig() == null

### getEnd

public int getEnd()

Specified by:
  `getEnd` in interface `Locatable`
Returns:
  1-based closed-ended position, undefined if getContig() == null