Module: IntervalList
- Included in:
- GTF, GTF::Gene, SegFile
- Defined in:
- lib/intervals.rb,
lib/intervals.rb,
lib/intervals.rb,
lib/intervals.rb
Overview
Operations that can be defined on a pair of intervals, yielding a new set of intervals
- overlap(b) = intersection between a and b, nil if no overlap
- a.union(b) = union between a and b, nil if no overlap
- a.diff(b) = set of regions of b that do not include a, { b } if no overlap
Operations that can be defined on interval b and set a
- a.overlap(b) - set of intervals in a that overlap b
Operations on a set of intervals a
- flatten - collapses overlapping intervals
-
Defined Under Namespace
Modules: Interval
Classes: Set, Tree, TreeNode
Instance Method Summary
collapse
Instance Method Details
#add_interval(int) ⇒ Object
135
136
137
138
|
# File 'lib/intervals.rb', line 135
def add_interval int
@interval_set << int if @interval_set
end
|
#flatten ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/intervals.rb', line 105
def flatten
current_span = nil
flat = []
each do |interval|
if current_span && current_span.overlaps?(interval)
current_span.stop = interval.stop
else
if current_span
yield current_span if block_given?
flat.push current_span
end
current_span = interval.clone
end
end
if current_span
yield current_span if block_given?
flat.push current_span
end
present flat
end
|
#interval_set ⇒ Object
140
141
142
143
|
# File 'lib/intervals.rb', line 140
def interval_set
@interval_set ||= IntervalList::Set.new self.to_a
end
|
#nearest(interval) ⇒ Object
100
101
102
103
|
# File 'lib/intervals.rb', line 100
def nearest interval
return nil unless interval_set[interval.seqname]
interval_set[interval.seqname].nearest interval
end
|
#overlap(interval) ⇒ Object
95
96
97
98
|
# File 'lib/intervals.rb', line 95
def overlap interval
return present([]) unless interval_set[interval.seqname]
present(interval_set[interval.seqname].overlap interval)
end
|
#present(obj) ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/intervals.rb', line 127
def present obj
if respond_to? :wrap
wrap obj
else
obj
end
end
|