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_feature_rows ⇒ Object
Returns the value of attribute number_of_feature_rows.
-
#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, label = true, 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/bio/graphics/panel.rb', line 103 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_feature_rows = 0 @clickable = clickable @image_map = ( clickable ) ? ImageMap.new : nil @display_start = ( display_start.nil? or display_start < 0 ) ? 0 : display_start @display_stop = ( display_stop.nil? or display_stop > @length ) ? @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.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def clickable @clickable end |
#display_start ⇒ Object
Returns the value of attribute display_start.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def display_start @display_start end |
#display_stop ⇒ Object
Returns the value of attribute display_stop.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def display_stop @display_stop end |
#height ⇒ Object
Returns the value of attribute height.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def height @height end |
#image_map ⇒ Object
Returns the value of attribute image_map.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def image_map @image_map end |
#length ⇒ Object
Returns the value of attribute length.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def length @length end |
#number_of_feature_rows ⇒ Object
Returns the value of attribute number_of_feature_rows.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def number_of_feature_rows @number_of_feature_rows end |
#rescale_factor ⇒ Object
Returns the value of attribute rescale_factor.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def rescale_factor @rescale_factor end |
#tracks ⇒ Object
Returns the value of attribute tracks.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def tracks @tracks end |
#width ⇒ Object
Returns the value of attribute width.
117 118 119 |
# File 'lib/bio/graphics/panel.rb', line 117 def width @width end |
Instance Method Details
#add_track(name, label = true, 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’)
- _label)
-
Whether the feature labels should be displayed or not
- 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
139 140 141 142 |
# File 'lib/bio/graphics/panel.rb', line 139 def add_track(name, label = true, feature_colour = [0,0,1], feature_glyph = 'generic') @tracks.push(Bio::Graphics::Panel::Track.new(self, name, label, 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
++
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 200 201 202 203 |
# File 'lib/bio/graphics/panel.rb', line 151 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.vertical_offset = vertical_offset track.draw(huge_panel_drawing) @number_of_feature_rows += track.number_of_feature_rows vertical_offset += ( track.number_of_feature_rows*(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_feature_rows.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 |