Class: Bio::Graphics::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/graphics/track.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Track

Returns a new instance of Track.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bio/graphics/track.rb', line 7

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]
  

end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def args
  @args
end

#feature_heightObject

Returns the value of attribute feature_height.



6
7
8
# File 'lib/bio/graphics/track.rb', line 6

def feature_height
  @feature_height
end

#feature_rowsObject

Returns the value of attribute feature_rows.



6
7
8
# File 'lib/bio/graphics/track.rb', line 6

def feature_rows
  @feature_rows
end

#featuresObject

Returns the value of attribute features.



6
7
8
# File 'lib/bio/graphics/track.rb', line 6

def features
  @features
end

#glyphObject (readonly)

Returns the value of attribute glyph.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def glyph
  @glyph
end

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def label
  @label
end

#max_yObject (readonly)

Returns the value of attribute max_y.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def max_y
  @max_y
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def name
  @name
end

#number_rowsObject

Returns the value of attribute number_rows.



6
7
8
# File 'lib/bio/graphics/track.rb', line 6

def number_rows
  @number_rows
end

#scaleObject (readonly)

Returns the value of attribute scale.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def scale
  @scale
end

#track_heightObject (readonly)

Returns the value of attribute track_height.



5
6
7
# File 'lib/bio/graphics/track.rb', line 5

def track_height
  @track_height
end

Instance Method Details

#add(feature) ⇒ Object



28
29
30
# File 'lib/bio/graphics/track.rb', line 28

def add(feature)
  @features << feature
end

#get_rowsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bio/graphics/track.rb', line 32

def get_rows
  #works out how many rows are needed per track for overlapping features
  #and which row each feature should be in
  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) ⇒ Object



48
49
50
# File 'lib/bio/graphics/track.rb', line 48

def overlaps(f1, f2)
  (f1.start >= f2.start and f1.start <= f2.end) or (f1.end >= f2.start and f1.end <= f2.end)
end