Class: Bioroebe::SVG::Track
- Inherits:
-
Object
- Object
- Bioroebe::SVG::Track
- Defined in:
- lib/bioroebe/svg/track.rb
Overview
Bioroebe::SVG::Track
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.
-
#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.
Instance Method Summary collapse
-
#add(feature) ⇒ Object
# === add.
-
#get_rows(page = nil) ⇒ Object
# === get_rows.
-
#initialize(args) ⇒ Track
constructor
# === initialize.
-
#label? ⇒ Boolean
(also: #label)
# === label? ========================================================================= #.
-
#min_width? ⇒ Boolean
(also: #min_width)
# === min_width? ========================================================================= #.
-
#overlaps(f1, f2, page = nil) ⇒ Object
# === overlaps.
-
#scale? ⇒ Boolean
(also: #scale)
# === scale? ========================================================================= #.
-
#track_height? ⇒ Boolean
(also: #track_height)
# === track_height? ========================================================================= #.
Constructor Details
#initialize(args) ⇒ Track
#
initialize
Creates a new Bioroebe::SVG::Track.
Arguments:
:glyph = one of Bioroebe::SVG::Glyphs#glyphs, currently being
[: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 Bioroebe::SVG::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 Bioroebe::SVG::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 Bioroebe::SVG::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
#
-
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/bioroebe/svg/track.rb', line 132 def initialize(args) @args = { :glyph => :generic, :name => 'feature_track', :label => true, :feature_height => 10, :track_height => nil }.merge!(args) # Append in the arguments. @glyph = @args[:glyph] @name = @args[:name] @label = @args[:label] @track_height = @args[:track_height] # ======================================================================= # # === @features # ======================================================================= # @features = [] # ======================================================================= # # === @feature_rows # ======================================================================= # @feature_rows = [] # ======================================================================= # # === @scale # ======================================================================= # @scale = @args[:scale] # ======================================================================= # # === @feature_height # ======================================================================= # @feature_height = @args[:feature_height] @number_of_rows = 1 @max_y = args[:max_y] @min_width = args[:min_width] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
20 21 22 |
# File 'lib/bioroebe/svg/track.rb', line 20 def args @args end |
#feature_height ⇒ Object
Returns the value of attribute feature_height.
28 29 30 |
# File 'lib/bioroebe/svg/track.rb', line 28 def feature_height @feature_height end |
#feature_rows ⇒ Object
Returns the value of attribute feature_rows.
25 26 27 |
# File 'lib/bioroebe/svg/track.rb', line 25 def feature_rows @feature_rows end |
#features ⇒ Object
Returns the value of attribute features.
24 25 26 |
# File 'lib/bioroebe/svg/track.rb', line 24 def features @features end |
#glyph ⇒ Object (readonly)
Returns the value of attribute glyph.
21 22 23 |
# File 'lib/bioroebe/svg/track.rb', line 21 def glyph @glyph end |
#max_y ⇒ Object (readonly)
Returns the value of attribute max_y.
22 23 24 |
# File 'lib/bioroebe/svg/track.rb', line 22 def max_y @max_y end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/bioroebe/svg/track.rb', line 26 def name @name end |
#number_rows ⇒ Object
Returns the value of attribute number_rows.
27 28 29 |
# File 'lib/bioroebe/svg/track.rb', line 27 def number_rows @number_rows end |
Instance Method Details
#add(feature) ⇒ Object
#
add
Adds a new Bioroebe::SVG::MiniFeature object to the current Bioroebe::SVG::Track.
#
185 186 187 |
# File 'lib/bioroebe/svg/track.rb', line 185 def add(feature) @features << feature end |
#get_rows(page = nil) ⇒ Object
#
get_rows
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 Bioroebe::SVG::Page object.
#
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/bioroebe/svg/track.rb', line 203 def get_rows( page = nil ) @feature_rows = Array.new(@features.length, -1) rows = Hash.new { |h, key| h[key] = [] } @features.each_with_index { |f1, i| current_row = 1 begin found = true rows[current_row].each_with_index do |f2, j| if overlaps(f1, f2, page) found = false current_row += 1 break end end end until found @feature_rows[i] = current_row rows[current_row] << f1 } @number_rows = @feature_rows.max end |
#label? ⇒ Boolean Also known as: label
#
label?
#
175 176 177 |
# File 'lib/bioroebe/svg/track.rb', line 175 def label? @label end |
#min_width? ⇒ Boolean Also known as: min_width
#
min_width?
#
259 260 261 |
# File 'lib/bioroebe/svg/track.rb', line 259 def min_width? @min_width end |
#overlaps(f1, f2, page = nil) ⇒ Object
#
overlaps
Calculates whether two Bioroebe::SVG::MiniFeature objects overlap by examining their start and end positions.
If the page where they are placed is given, then the function also considers the features' labels.
Arguments:
f1 - a Bioroebe::SVG::MiniFeature object
f2 - a Bioroebe::SVG::MiniFeature object
page - the optional Bioroebe::SVG::Page object where the features
are placed
#
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/bioroebe/svg/track.rb', line 243 def overlaps( f1, f2, page = nil ) if !page b1 = [f1.start, f1.end] b2 = [f2.start, f2.end] else b1 = page.compute_boundaries(f1) b2 = page.compute_boundaries(f2) end (b2[0] <= b1[1]) and (b1[0] <= b2[1]) end |
#scale? ⇒ Boolean Also known as: scale
#
scale?
#
168 169 170 |
# File 'lib/bioroebe/svg/track.rb', line 168 def scale? @scale end |
#track_height? ⇒ Boolean Also known as: track_height
#
track_height?
#
192 193 194 |
# File 'lib/bioroebe/svg/track.rb', line 192 def track_height? @track_height end |