def draw_features(track)
if [:histogram, "histogram"].include?(track.glyph)
y = @track_top + (track.track_height)
max = track.max_y ? track.max_y : track.features.sort { |a, b| a.segment_height <=> b.segment_height }.last.segment_height
min = 0
if track.label
draw_label(:text => track.name, :y => @track_top += 30, :x => 3)
end
draw_label(:text => max, :x => to_px(@scale_stop - @scale_start) + 5, :y => @track_top + 5)
draw_label(:text => min, :x => to_px(@scale_stop - @scale_start) + 5, :y => @track_top + track.track_height + 5)
data_interval = max - min
data_per_px = track.track_height.to_f / data_interval.to_f
track.features.each do |f|
x = to_px(f.start - @scale_start)
width = to_px((f.end - @scale_start) - (f.start - @scale_start))
height = f.segment_height.to_f * data_per_px
y = @track_top + track.track_height - height + 5
self.send("draw_#{track.glyph}", {:x => x,
:y => y,
:width => width,
:height => height}.merge!(track.args))
end
@track_top += (track.track_height) + 20
else
if track.label
draw_label(:text => track.name, :y => @track_top += 30, :x => 3)
end
track.get_rows
track.features.each_with_index do |f, index|
x = to_px(f.start - @scale_start)
all_sub_blocks = []
exons = []
if f.exons
f.exons.each_slice(2).each do |exon|
all_sub_blocks << exon
next if exon.nil?
exons << [to_px(exon[0] - @scale_start), to_px((exon[1] - @scale_start) - (exon[0] - @scale_start))]
end
end
f.exons = exons
utrs = []
if f.utrs
f.utrs.each_slice(2).each do |utr|
all_sub_blocks << utr
next if utr.nil?
utrs << [to_px(utr[0] - @scale_start), to_px((utr[1] - @scale_start) - (utr[0] - @scale_start))]
end
end
f.utrs = utrs
if not all_sub_blocks.empty?
all_sub_blocks = all_sub_blocks.sort { |a, b| a.first <=> b.first }
all_sub_blocks.each_index do |i|
next if i + 1 == all_sub_blocks.length or all_sub_blocks[i].last >= all_sub_blocks[i + 1].first
f.block_gaps << [to_px(all_sub_blocks[i].last - @scale_start), to_px((all_sub_blocks[i + 1].first - @scale_start) - (all_sub_blocks[i].last - @scale_start))]
end
end
width = to_px((f.end - @scale_start) - (f.start - @scale_start))
if track.min_width and width < track.min_width
width = track.min_width
end
y = @track_top + (track.feature_rows[index] * 2 * track.feature_height)
self.send("draw_#{track.glyph}", {:x => x,
:y => y,
:width => width,
:strand => f.strand,
:exons => f.exons,
:utrs => f.utrs,
:block_gaps => f.block_gaps,
:height => track.feature_height
}.merge!(track.args))
if f.id
draw_label(:y => y, :x => x + width +2, :text => f.id)
end
end
@track_top += (track.feature_height * track.number_rows * 2) + 20
end
@height = @track_top + 100
@svg.update_height(@height)
end