Package htsjdk.samtools.util
Class Interval
- java.lang.Object
-
- htsjdk.samtools.util.Interval
-
- All Implemented Interfaces:
Locatable
,Cloneable
,Comparable<Interval>
public class Interval extends Object implements Comparable<Interval>, Cloneable, Locatable
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 suppliedLocatable
.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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 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 laststatic long
countBases(Collection<Interval> intervals)
Counts the total number of bases a collection of intervals.boolean
equals(Object other)
Equals method that agrees withcompareTo(Interval)
.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() insteadint
getStart()
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 java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface htsjdk.samtools.util.Locatable
contains, contigsMatch, getLengthOnReference, overlaps, withinDistanceOf
-
-
-
-
Constructor Detail
-
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 sequencestart
- the start position of the interval on the sequenceend
- the end position of the interval on the sequence
-
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 sequencestart
- the start position of the interval on the sequenceend
- the end position of the interval on the sequencenegative
- true to indicate negative strand, false otherwisename
- the name (possibly null) of the interval
-
-
Method Detail
-
getSequence
@Deprecated public String getSequence()
Deprecated.use getContig() insteadGets 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.
-
getName
public 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(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 interfaceComparable<Interval>
-
equals
public boolean equals(Object other)
Equals method that agrees withcompareTo(Interval)
.
-
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.
-
getStart
public int getStart()
-
-