Package htsjdk.samtools.util
Class IntervalTree<V>
java.lang.Object
htsjdk.samtools.util.IntervalTree<V>
- All Implemented Interfaces:
Iterable<IntervalTree.Node<V>>
A Red-Black tree with intervals for keys.
Not thread-safe, and cannot be made so.
7/24/2008: This was copied from the tedUtils package.
IMPORTANT!!! It has been modified to use the Reseq way of
handling coordinates (end-inclusive).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
static class
class
class
static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method is only for debugging.void
clear()
Remove all entries.find
(int start, int end) Find an interval.findByIndex
(int idx) Find the nth interval in the tree.int
getIndex
(int start, int end) Find the rank of the specified interval.Get the special sentinel value that will be used to signal novelty when putting a new interval into the tree, or to signal "not found" when removing an interval.iterator()
Return an iterator over the entire tree.iterator
(int start, int end) Return an iterator over all intervals greater than or equal to the specified interval.max()
Find the greatest interval in the tree.max
(int start, int end) Find the latest interval in the tree less than or equal to the specified interval.If the specified start and end positions are not already associated with a value or are associated with the sentinel ( seegetSentinel()
, associates it with the given (non-sentinel) value.min()
Find the least interval in the tree.min
(int start, int end) Find the earliest interval in the tree greater than or equal to the specified interval.minOverlapper
(int start, int end) Find the earliest interval in the tree that overlaps the specified interval.overlappers
(int start, int end) Return an iterator over all intervals overlapping the specified range.void
This method draws a nested picture of the tree on System.out.Put a new interval into the tree (or update the value associated with an existing interval).remove
(int start, int end) Remove an interval from the tree.Return an iterator over the entire tree that returns intervals in reverse order.reverseIterator
(int start, int end) Return an iterator over all intervals less than or equal to the specified interval, in reverse order.setSentinel
(V sentinel) Set the special sentinel value that will be used to signal novelty when putting a new interval into the tree, or to signal "not found" when removing an interval.int
size()
Return the number of intervals in the tree.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
IntervalTree
public IntervalTree()
-
-
Method Details
-
size
public int size()Return the number of intervals in the tree.- Returns:
- The number of intervals.
-
clear
public void clear()Remove all entries. -
put
Put a new interval into the tree (or update the value associated with an existing interval). If the interval is novel, the special sentinel value is returned.- Parameters:
start
- The interval's start.end
- The interval's end.value
- The associated value.- Returns:
- The old value associated with that interval, or the sentinel.
-
merge
public V merge(int start, int end, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) If the specified start and end positions are not already associated with a value or are associated with the sentinel ( seegetSentinel()
, associates it with the given (non-sentinel) value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is equal to the sentinel value. This method may be of use when combining multiple values that have the same start and end position.- Parameters:
start
- interval start positionend
- interval end positionvalue
- value to merge into the tree, must not be equal to the sentinel valueremappingFunction
- a function that merges the new value with the existing value for the same start and end position, if the function returns the sentinel value then the mapping will be unset- Returns:
- the updated value that is stored in the tree after the completion of this merge operation, this will be the sentinel value if nothing ended up being stored
-
remove
Remove an interval from the tree. If the interval does not exist in the tree the special sentinel value is returned.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- The value associated with that interval, or the sentinel.
-
find
Find an interval.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- The Node that represents that interval, or null.
-
findByIndex
Find the nth interval in the tree.- Parameters:
idx
- The rank of the interval sought (from 0 to size()-1).- Returns:
- The Node that represents the nth interval.
-
getIndex
public int getIndex(int start, int end) Find the rank of the specified interval. If the specified interval is not in the tree, then -1 is returned.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- The rank of that interval, or -1.
-
min
Find the least interval in the tree.- Returns:
- The earliest interval, or null if the tree is empty.
-
min
Find the earliest interval in the tree greater than or equal to the specified interval.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- The earliest >= interval, or null if there is none.
-
minOverlapper
Find the earliest interval in the tree that overlaps the specified interval.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- The earliest overlapping interval, or null if there is none.
-
max
Find the greatest interval in the tree.- Returns:
- The latest interval, or null if the tree is empty.
-
max
Find the latest interval in the tree less than or equal to the specified interval.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- The latest >= interval, or null if there is none.
-
iterator
Return an iterator over the entire tree. -
iterator
Return an iterator over all intervals greater than or equal to the specified interval.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- An iterator.
-
overlappers
Return an iterator over all intervals overlapping the specified range.- Parameters:
start
- The range start.end
- The range end.- Returns:
- An iterator.
-
reverseIterator
Return an iterator over the entire tree that returns intervals in reverse order.- Returns:
- An iterator.
-
reverseIterator
Return an iterator over all intervals less than or equal to the specified interval, in reverse order.- Parameters:
start
- The interval's start.end
- The interval's end.- Returns:
- An iterator.
-
getSentinel
Get the special sentinel value that will be used to signal novelty when putting a new interval into the tree, or to signal "not found" when removing an interval. This is null by default.- Returns:
- The sentinel value.
-
setSentinel
Set the special sentinel value that will be used to signal novelty when putting a new interval into the tree, or to signal "not found" when removing an interval.- Parameters:
sentinel
- The new sentinel value.- Returns:
- The old sentinel value.
-
checkMaxEnds
public void checkMaxEnds()This method is only for debugging. It verifies whether the tree is internally consistent with respect to the mMaxEnd cached on each node.- Throws:
IllegalStateException
- If an inconsistency is detected.
-
printTree
public void printTree()This method draws a nested picture of the tree on System.out. Useful for debugging.
-