Class: Bioroebe::SVG::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/bioroebe/svg/track.rb

Overview

Bioroebe::SVG::Track

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#


131
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
# File 'lib/bioroebe/svg/track.rb', line 131

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]
  @max_y = args[:max_y]
  @min_width = args[:min_width]
  reset
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



20
21
22
# File 'lib/bioroebe/svg/track.rb', line 20

def args
  @args
end

#feature_heightObject

Returns the value of attribute feature_height.



27
28
29
# File 'lib/bioroebe/svg/track.rb', line 27

def feature_height
  @feature_height
end

#feature_rowsObject

Returns the value of attribute feature_rows.



24
25
26
# File 'lib/bioroebe/svg/track.rb', line 24

def feature_rows
  @feature_rows
end

#featuresObject

Returns the value of attribute features.



23
24
25
# File 'lib/bioroebe/svg/track.rb', line 23

def features
  @features
end

#glyphObject (readonly)

Returns the value of attribute glyph.



21
22
23
# File 'lib/bioroebe/svg/track.rb', line 21

def glyph
  @glyph
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/bioroebe/svg/track.rb', line 25

def name
  @name
end

#number_rowsObject

Returns the value of attribute number_rows.



26
27
28
# File 'lib/bioroebe/svg/track.rb', line 26

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.

#


201
202
203
# File 'lib/bioroebe/svg/track.rb', line 201

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.

#


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/bioroebe/svg/track.rb', line 219

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 { |f2, j|
        if overlaps(f1, f2, page)
          found = false
          current_row += 1
          break
        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?

#

Returns:

  • (Boolean)


191
192
193
# File 'lib/bioroebe/svg/track.rb', line 191

def label?
  @label
end

#max_y?Boolean Also known as: max_y

#

max_y?

#

Returns:

  • (Boolean)


177
178
179
# File 'lib/bioroebe/svg/track.rb', line 177

def max_y?
  @max_y
end

#min_width?Boolean Also known as: min_width

#

min_width?

#

Returns:

  • (Boolean)


275
276
277
# File 'lib/bioroebe/svg/track.rb', line 275

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
#


259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/bioroebe/svg/track.rb', line 259

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

#resetObject

#

reset

#


167
168
169
170
171
172
# File 'lib/bioroebe/svg/track.rb', line 167

def reset
  # ======================================================================= #
  # === @number_of_rows
  # ======================================================================= #
  @number_of_rows = 1
end

#scale?Boolean Also known as: scale

#

scale?

#

Returns:

  • (Boolean)


184
185
186
# File 'lib/bioroebe/svg/track.rb', line 184

def scale?
  @scale
end

#track_height?Boolean Also known as: track_height

#

track_height?

#

Returns:

  • (Boolean)


208
209
210
# File 'lib/bioroebe/svg/track.rb', line 208

def track_height?
  @track_height
end