Class: Bio::Graphics::Track
- Inherits:
-
Object
- Object
- Bio::Graphics::Track
- Defined in:
- lib/bio/graphics/track.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#feature_height ⇒ Object
Returns the value of attribute feature_height.
-
#feature_rows ⇒ Object
Returns the value of attribute feature_rows.
-
#features ⇒ Object
Returns the value of attribute features.
-
#glyph ⇒ Object
readonly
Returns the value of attribute glyph.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#max_y ⇒ Object
readonly
Returns the value of attribute max_y.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number_rows ⇒ Object
Returns the value of attribute number_rows.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#track_height ⇒ Object
readonly
Returns the value of attribute track_height.
Instance Method Summary collapse
- #add(feature) ⇒ Object
- #get_rows ⇒ Object
-
#initialize(args) ⇒ Track
constructor
A new instance of Track.
- #overlaps(f1, f2) ⇒ Object
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/bio/graphics/track.rb', line 5 def args @args end |
#feature_height ⇒ Object
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_rows ⇒ Object
Returns the value of attribute feature_rows.
6 7 8 |
# File 'lib/bio/graphics/track.rb', line 6 def feature_rows @feature_rows end |
#features ⇒ Object
Returns the value of attribute features.
6 7 8 |
# File 'lib/bio/graphics/track.rb', line 6 def features @features end |
#glyph ⇒ Object (readonly)
Returns the value of attribute glyph.
5 6 7 |
# File 'lib/bio/graphics/track.rb', line 5 def glyph @glyph end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'lib/bio/graphics/track.rb', line 5 def label @label end |
#max_y ⇒ Object (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 |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/bio/graphics/track.rb', line 5 def name @name end |
#number_rows ⇒ Object
Returns the value of attribute number_rows.
6 7 8 |
# File 'lib/bio/graphics/track.rb', line 6 def number_rows @number_rows end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
5 6 7 |
# File 'lib/bio/graphics/track.rb', line 5 def scale @scale end |
#track_height ⇒ Object (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_rows ⇒ Object
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 |