class Bio::Graphics::Track

The Track class holds and organises the features, ordering them into different rows if they overlap

Attributes

args[R]
feature_height[RW]
feature_rows[RW]
features[RW]
glyph[R]
label[R]
max_y[R]
min_width[R]
name[RW]
number_rows[RW]
scale[R]
track_height[R]

Public Instance Methods

add(feature) click to toggle source

Adds a new MiniFeature to the the @features array

# File lib/bio/graphics/track.rb, line 31
def add(feature)
  @features << feature
end
get_rows() click to toggle source

Calculates how many rows are needed per track for overlapping features and which row each feature should be in

# File lib/bio/graphics/track.rb, line 38
def get_rows
  current_row = 1
  @feature_rows = Array.new(@features.length,1)
  @features.each_with_index  do |f1, i|
    @features.each_with_index do |f2, j|
      next if i == j or j <= i
      if overlaps(f1,f2)
        @feature_rows[i] += 1
      end
    end
    @number_rows = @feature_rows.max
  end
end
overlaps(f1, f2) click to toggle source

Calculates if two MiniFeature objects overlap by examining their start and end positions. If two features overlap then then will be placed on separate rows of the track

args

# File lib/bio/graphics/track.rb, line 58
def overlaps(f1, f2)
  (f1.start >= f2.start and f1.start <= f2.end) or (f1.end >= f2.start and f1.end <= f2.end)
end

Public Class Methods

new(args) click to toggle source

Creates a new Track

# File lib/bio/graphics/track.rb, line 9
def initialize(args)
  @args = {:glyph => :generic, 
           :name => "feature_track", 
           :label => true, 
           :feature_height => 10,
           :track_height => nil }.merge!(args)
  @glyph = @args[:glyph]
  @name = @args[:name]
  @label = @args[:label]
  @track_height = @args[:track_height]
  @features = []
  @feature_rows = []
  @scale = @args[:scale]
  @feature_height = @args[:feature_height]
  @number_of_rows = 1
  @max_y = args[:max_y]
  @min_width = args[:min_width]
  

end