Class: Bio::Graphics::Panel
- Inherits:
-
Object
- Object
- Bio::Graphics::Panel
- Defined in:
- lib/bio/graphics/panel.rb,
lib/bio/graphics/ruler.rb,
lib/bio/graphics/track.rb,
lib/bio/graphics/feature.rb
Overview
The Bio::Graphics::Panel class describes the complete graph and contains all tracks. See Bio::Graphics documentation for explanation of interplay between different classes.
Defined Under Namespace
Instance Attribute Summary collapse
-
#clickable ⇒ Object
Returns the value of attribute clickable.
-
#display_start ⇒ Object
Returns the value of attribute display_start.
-
#display_stop ⇒ Object
Returns the value of attribute display_stop.
-
#height ⇒ Object
Returns the value of attribute height.
-
#image_map ⇒ Object
Returns the value of attribute image_map.
-
#length ⇒ Object
Returns the value of attribute length.
-
#number_of_times_bumped ⇒ Object
Returns the value of attribute number_of_times_bumped.
-
#rescale_factor ⇒ Object
Returns the value of attribute rescale_factor.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#add_track(name, feature_colour = [0,0,1], feature_glyph = 'generic') ⇒ Object
Adds a Bio::Graphics::Track container to this panel.
-
#draw(file_name) ⇒ Object
Create the drawing – The fact that display_start and display_stop can be set has two consequences: 1.
-
#initialize(length, width = DEFAULT_PANEL_WIDTH, clickable = false, display_start = nil, display_stop = nil) ⇒ Panel
constructor
Create a new Bio::Graphics::Panel object.
Constructor Details
#initialize(length, width = DEFAULT_PANEL_WIDTH, clickable = false, display_start = nil, display_stop = nil) ⇒ Panel
Create a new Bio::Graphics::Panel object
g = Bio::Graphics::Panel.new(456)
The height of the image is calculated automatically depending on how many tracks and features it contains. The width of the image defaults to 800 pt but can be set manually by using a second argument:
g = Bio::Graphics::Panel.new(456, 400)
See also: Bio::Graphics::Track, BioExt::Graphics::Feature
Arguments:
- length
-
length of the thing you want to visualize, e.g for
visualizing a sequence that is 3.24 kb long, use 324.
- width
-
width of the resulting image in pt. This should be a string
and not an integer. Default = ‘800’ (Notice the quotes…).
- clickable
-
whether the picture should have clickable glyphs or not
(default: false) If set to true, a html file will be created with the map.
- display_start
-
start coordinate to be displayed (default: 1)
- display_stop
-
stop coordinate to be displayed (default: length of sequence)
- Returns
-
Bio::Graphics::Panel object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bio/graphics/panel.rb', line 101 def initialize(length, width = DEFAULT_PANEL_WIDTH, clickable = false, display_start = nil, display_stop = nil) @length = length.to_i @width = width.to_i @tracks = Array.new @number_of_times_bumped = 0 @clickable = clickable @image_map = ( clickable ) ? ImageMap.new : nil @display_start = ( display_start.nil? ) ? 0 : display_start @display_stop = ( display_stop.nil? ) ? @length : display_stop if @display_stop <= @display_start raise "[ERROR] Start coordinate to be displayed has to be smaller than stop coordinate." end @rescale_factor = (@display_stop - @display_start).to_f / @width end |
Instance Attribute Details
#clickable ⇒ Object
Returns the value of attribute clickable.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def clickable @clickable end |
#display_start ⇒ Object
Returns the value of attribute display_start.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def display_start @display_start end |
#display_stop ⇒ Object
Returns the value of attribute display_stop.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def display_stop @display_stop end |
#height ⇒ Object
Returns the value of attribute height.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def height @height end |
#image_map ⇒ Object
Returns the value of attribute image_map.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def image_map @image_map end |
#length ⇒ Object
Returns the value of attribute length.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def length @length end |
#number_of_times_bumped ⇒ Object
Returns the value of attribute number_of_times_bumped.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def number_of_times_bumped @number_of_times_bumped end |
#rescale_factor ⇒ Object
Returns the value of attribute rescale_factor.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def rescale_factor @rescale_factor end |
#tracks ⇒ Object
Returns the value of attribute tracks.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def tracks @tracks end |
#width ⇒ Object
Returns the value of attribute width.
115 116 117 |
# File 'lib/bio/graphics/panel.rb', line 115 def width @width end |
Instance Method Details
#add_track(name, feature_colour = [0,0,1], feature_glyph = 'generic') ⇒ Object
Adds a Bio::Graphics::Track container to this panel. A panel contains a logical grouping of features, e.g. (for sequence annotation:) genes, polymorphisms, ESTs, etc.
est_track = g.add_track('ESTs')
gene_track = g.add_track('genes')
Arguments:
- name (required)
-
Name of the track to be displayed (e.g. ‘genes’)
- colour
-
Colour to be used to draw the features within the track.
Default = ‘blue’
- glyph
-
Glyph to use for drawing the features. Options are:
‘generic’, ‘directed_generic’, ‘spliced’, ‘directed_spliced’ and ‘triangle’. Triangles can be used for features whose start and stop positions are the same (e.g. SNPs). If you try to draw a feature that is longer with triangles, an error will be shown.
- Returns
-
Bio::Graphics::Track object that has just been created
136 137 138 139 |
# File 'lib/bio/graphics/panel.rb', line 136 def add_track(name, feature_colour = [0,0,1], feature_glyph = 'generic') @tracks.push(Bio::Graphics::Panel::Track.new(self, name, feature_colour, feature_glyph)) return @tracks[-1] end |
#draw(file_name) ⇒ Object
Create the drawing – The fact that display_start and display_stop can be set has two consequences:
1. not all features are drawn
2. the x-coordinate of all glyphs has to be corrected
++
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/bio/graphics/panel.rb', line 148 def draw(file_name) # Create a panel that is huge vertically huge_height = 2000 huge_panel_drawing = nil huge_panel_drawing = Cairo::ImageSurface.new(1, @width, huge_height) background = Cairo::Context.new(huge_panel_drawing) background.set_source_rgb(1,1,1) background.rectangle(0,0,@width,huge_height).fill # Add ruler vertical_offset = 0 ruler = Bio::Graphics::Panel::Ruler.new(self) ruler.draw(huge_panel_drawing, vertical_offset) vertical_offset += ruler.height # Add tracks @tracks.each do |track| track.draw(huge_panel_drawing, vertical_offset) @number_of_times_bumped += track.number_of_times_bumped vertical_offset += ( track.number_of_times_bumped*(FEATURE_HEIGHT+FEATURE_V_DISTANCE+5)) + 10 # '10' is for the header end # And create a smaller version of the panel height = ruler.height @number_of_times_bumped.times do height += 20 end @tracks.length.times do #To correct for the track headers height += 10 end resized_panel_drawing = nil resized_panel_drawing = Cairo::ImageSurface.new(1, @width, height) resizing_context = Cairo::Context.new(resized_panel_drawing) resizing_context.set_source(huge_panel_drawing, 0,0) resizing_context.rectangle(0,0,@width, height).fill # And print to file resized_panel_drawing.write_to_png(file_name) if @clickable # create png and map html_filename = file_name.sub(/\.[^.]+$/, '.html') html = File.open(html_filename,'w') html.puts "<html>" html.puts "<body>" html.puts @image_map.to_s html.puts "<img border='1' src='" + file_name + "' usemap='#image_map' />" html.puts "</body>" html.puts "</html>" end end |