Class: Bio::Graphics::Track

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

Overview

The Bio::Graphics::Track object acts as a container for Bio::Graphics::MiniFeature objects. The Bio::Graphics::Track takes style information on instantiation. Style information is applied to each feature in the track by the track

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Track

Creates a new Bio::Graphics::Track

args

  • :glyph = one of Bio::Graphics::Glyphs#glyphs currently

:generic, :directed, :transcript, :scale, :label, :histogram, :circle, :down_triangle, :up_triangle, :span
  • :stroke_color = the outline colour of the glyphs in the track (default = “black”), can be any SVG colour eg rgb(256,0,0) or #FF0000

  • :fill_color = the fill colour of the glyphs in the track (default = ‘red’), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients

:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial

or a custom definition of a gradient {:type => :radial, :id => :custom, :cx => 5, :cy => 5, :r => 50, :fx => 50, :fy => 50,

:stops => [ {
     :offset => 0, 
     :color => 'rgb(255,255,255)', 
     :opacity => 0
     },  {
     :offset => 100, 
     :color => 'rgb(0,127,200)', 
     :opacity => 1
     }, ]

}

  • :track_height = minimum height for the track, will be modified automatically if more space is needed e.g for overlapping features (default = auto),

  • :name = a displayed name for the track (default = ‘feature_track’)

  • :label = display the name given to the track (default = true),

  • :stroke_width = width in pixels of the outline of the glyphs (default=1)

  • :x_round = x radius of the ellipse used to round off the corners of rectangles (default = 1)

  • :y_round = y radius of the ellipse used to round off the corners of rectangles (default = 1)

:utr_fill_color = the fill colour of the utr part of the glyph (default = ‘black’), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients

:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial

or a custom definition of a gradient {:type => :radial, :id => :custom, :cx => 5, :cy => 5, :r => 50, :fx => 50, :fy => 50,

:stops => [ {
     :offset => 0, 
     :color => 'rgb(255,255,255)', 
     :opacity => 0
     },  {
     :offset => 100, 
     :color => 'rgb(0,127,200)', 
     :opacity => 1
     }, ]

}

  • :utr_stroke = the outline colour of the utr part of the glyph (default = “black”), can be any SVG colour eg rgb(256,0,0) or #FF0000

  • :utr_stroke_width = The width of the outline stroke for the utr part of the glyph (default = 1)

  • :exon_fill_color = the fill colour of the utr part of the glyph (default = ‘red’), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients or a custom definition of a gradient

:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial

or a custom definition of a gradient {:type => :radial, :id => :custom, :cx => 5, :cy => 5, :r => 50, :fx => 50, :fy => 50,

:stops => [ {
     :offset => 0, 
     :color => 'rgb(255,255,255)', 
     :opacity => 0
     },  {
     :offset => 100, 
     :color => 'rgb(0,127,200)', 
     :opacity => 1
     }, ]
  • :exon_stroke = the outline colour of the exon part of the glyph (default = “black”) can be any SVG colour eg rgb(256,0,0) or #FF0000

  • :exon_stroke_width = The width of the outline stroke for the exon part of the glyph (default = 1)

  • :line_color = the colour for the line part that joins the blocks (default = ‘black’) can be any SVG colour eg rgb(256,0,0) or #FF0000

  • :line_width = the width ffor the line part that joins the blocks (default = 1)

  • :exon_style = an arbitrary SVG compliant style string eg “fill-opacity:0.4;”

  • :utr_style = an arbitrary SVG compliant style string eg “fill-opacity:0.4;”

  • :line_style = an arbitrary SVG compliant style string eg “fill-opacity:0.4;”

  • :gap_marker = style of the line between blocks - either angled or straight



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/bio/graphics/track.rb', line 93

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#feature_heightObject

Returns the value of attribute feature_height.



8
9
10
# File 'lib/bio/graphics/track.rb', line 8

def feature_height
  @feature_height
end

#feature_rowsObject

Returns the value of attribute feature_rows.



8
9
10
# File 'lib/bio/graphics/track.rb', line 8

def feature_rows
  @feature_rows
end

#featuresObject

Returns the value of attribute features.



8
9
10
# File 'lib/bio/graphics/track.rb', line 8

def features
  @features
end

#glyphObject (readonly)

Returns the value of attribute glyph.



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

def glyph
  @glyph
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#max_yObject (readonly)

Returns the value of attribute max_y.



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

def max_y
  @max_y
end

#min_widthObject (readonly)

Returns the value of attribute min_width.



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

def min_width
  @min_width
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#number_rowsObject

Returns the value of attribute number_rows.



8
9
10
# File 'lib/bio/graphics/track.rb', line 8

def number_rows
  @number_rows
end

#scaleObject (readonly)

Returns the value of attribute scale.



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

def scale
  @scale
end

#track_heightObject (readonly)

Returns the value of attribute track_height.



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

def track_height
  @track_height
end

Instance Method Details

#add(feature) ⇒ Object

Adds a new Bio::Graphics::MiniFeature object to the current Bio::Graphics::Track



115
116
117
# File 'lib/bio/graphics/track.rb', line 115

def add(feature)
  @features << feature
end

#get_rowsObject

Calculates how many rows are needed per track for overlapping features and which row each feature should be in. Usually only called by the enclosing Bio::Graphics::Page object.



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/bio/graphics/track.rb', line 121

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) ⇒ Object

Calculates whether two Bio::Graphics::MiniFeature objects overlap by examining their start and end positions.

args

  • f1 - a Bio::Graphics::MiniFeature object

  • f2 - a Bio::Graphics::MiniFeature object



140
141
142
# File 'lib/bio/graphics/track.rb', line 140

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