Interval tree is a tree data structure to hold intervals. It allows efficiently search for overlappings. Learn more about Interval tree structure HERE.
AbstractInterval{T}: must have first and last function, and first <= last;
Interval{T} <: AbstractInterval{T}: simple interval, with only first and last methods, Base.convert was dispatched to convert AbstractRange to Interval
IntervalValue <: AbstractInterval: interval with value, first, last, value
IntervalTree{K, V}: dict like structure, stores intervals of type V that have start and end posi of type K, interval K as keys.
IntervalMap{K, V}: typealias of IntervalTrees{K, IntervalValue{K, V}}
# structure
trees::Dict
length::Int64
ordered_trees::Vector
ordered_trees_outdated::Bool
# create
col = IntervalCollection{Nothing}()
## normal push!
for i in 1:10:100
push!(col, Interval("chr1", i, i + 9))
end
## list expansion: which is faster
## should be SORTED vector of Intervals
col = IntervalCollection([Interval("chr1", i, i + 9) for i in 1:10:100])
# filtering
predicate(i) = isodd(leftposition(i))
selected = IntervalCollection(Base,Iterators.filter(predicate, col))
selected = IntervalCollection([x for x in col if predicate(x)])
# overlap query
# isoverlap(interval_a, interval_b)
isoverlapping(Interval("chr1",1,100), Interval("chr1",50, 51))
# eachoverlap()
eachoverlap(a::IntervalCollection{T}, query::Interval; filter)
eachoverlap(a::IntervalCollection, b::IntervalCollection; filter)
eachoverlap(intervals_a, intervals_b, seqname_isless; filter)
# coverage
coverage(ic::IntervalCollection)
coverage(stream, seqname_isless::Function)