Skip to content

Commit

Permalink
converted Bio::Graphics::Panel.new to use hash arguments for changing
Browse files Browse the repository at this point in the history
default options


git-svn-id: svn+ssh://rubyforge.org/var/svn/bio-graphics@32 a2f46d20-7dc0-45cf-9d05-bfa4e4ff58eb
  • Loading branch information
dgtized committed Nov 24, 2007
1 parent f7d11f3 commit 393dd38
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
31 changes: 16 additions & 15 deletions trunk/lib/bio/graphics/panel.rb
Expand Up @@ -73,9 +73,9 @@ class Bio::Graphics::Panel
#
# 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:
# but can be set manually by using the width argument to the opts hash:
#
# g = Bio::Graphics::Panel.new(456, 1200)
# g = Bio::Graphics::Panel.new(456, :width => 1200)
#
#
# See also: Bio::Graphics::Panel::Track,
Expand All @@ -84,25 +84,26 @@ class Bio::Graphics::Panel
# *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
# * _:width_ :: width of the resulting image in pixels. (default: 800)
# * _: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)
# * _verticle_ :: Boolean: false = horizontal (= default)
# * _:display_start_ :: start coordinate to be displayed (default: 1)
# * _:display_stop_ :: stop coordinate to be displayed (default: length of sequence)
# * _:verticle_ :: Boolean: false = horizontal (= default)
# *Returns*:: Bio::Graphics::Panel object
def initialize(length, width = DEFAULT_PANEL_WIDTH, clickable = false, display_start = nil, display_stop = nil, verticle = false)
def initialize(length, opts = {})
@length = length.to_i
@width = width.to_i
@verticle = verticle
@width = (opts[:width] || DEFAULT_PANEL_WIDTH).to_i
@display_start = [0,opts[:display_start] || 0].max
@display_stop = [@length,opts[:display_stop] || @length].min
@verticle = opts[:verticle] || false
@clickable = opts[:clickable] || false

@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
@image_map = ( @clickable ) ? ImageMap.new : nil

if @display_stop <= @display_start
raise "[ERROR] Start coordinate to be displayed has to be smaller than stop coordinate."
end
Expand Down
5 changes: 4 additions & 1 deletion trunk/samples/arkdb_features.rb
Expand Up @@ -2,7 +2,10 @@

#Initialize graphic for a nucleotide sequence of 4173015 bp, zooming in on the
#region 11111..3333333
my_panel = Bio::Graphics::Panel.new(4173015, 600, true, 11111, 3333333, true)
my_panel = Bio::Graphics::Panel.new(4173015, :width => 600, :clickable => true,
:display_start => 11111,
:display_stop => 3333333,
:verticle => true)
#my_panel = Bio::Graphics::Panel.new(4173015, 800, false, 1, 4173015)

#Create and configure tracks
Expand Down
2 changes: 1 addition & 1 deletion trunk/samples/glyph_showcase.rb
@@ -1,6 +1,6 @@
require '../lib/bio-graphics'

my_panel = Bio::Graphics::Panel.new(500, 1000, true)
my_panel = Bio::Graphics::Panel.new(500, :width => 1000, :clickable => true)

generic_track = my_panel.add_track('generic', false)
line_track = my_panel.add_track('line', false, :line, [0,0,1])
Expand Down
4 changes: 2 additions & 2 deletions trunk/samples/protein_domains.rb
@@ -1,6 +1,6 @@
# Data from http://pfam.sanger.ac.uk/protein?id=Q8C6V9_MOUSE
require '../lib/bio-graphics'
my_panel = Bio::Graphics::Panel.new(700, 600)
my_panel = Bio::Graphics::Panel.new(700, :width => 600)

track = my_panel.add_track('Q8C6V9_MOUSE')
track.glyph = :generic
Expand All @@ -16,4 +16,4 @@
track.add_feature(cimr_2, 'CIMR', nil, track.glyph, [0,1,0])
track.add_feature(cimr_3, 'CIMR', nil, track.glyph, [0,1,0])

my_panel.draw('protein_domains.png')
my_panel.draw('protein_domains.png')
2 changes: 1 addition & 1 deletion trunk/samples/subfeatures.rb
@@ -1,5 +1,5 @@
require '../lib/bio-graphics'
my_panel = Bio::Graphics::Panel.new(700, 600)
my_panel = Bio::Graphics::Panel.new(700, :width => 600)

track = my_panel.add_track('transcripts')
track.glyph = :directed_spliced
Expand Down
13 changes: 8 additions & 5 deletions trunk/test/unit/test_creation.rb
Expand Up @@ -3,7 +3,8 @@

class TestPanel < Test::Unit::TestCase
def test_panel_creation
panel = Bio::Graphics::Panel.new(1000, 500, false, 0, 1000)
panel = Bio::Graphics::Panel.new(1000, :width => 500, :clickable => false,
:display_start => 0, :display_stop => 1000)
assert_equal(1000, panel.length)
assert_equal(500, panel.width)
assert_equal(false, panel.clickable)
Expand All @@ -14,16 +15,18 @@ def test_panel_creation
end

def test_panel_creation_out_of_boundaries
panel = Bio::Graphics::Panel.new(1000, 500, false, -7, 5000)
panel = Bio::Graphics::Panel.new(1000, :width => 500, :clickable => false,
:display_start => -7, :display_stop => 5000)
assert_same(0, panel.display_start)
assert_same(1000, panel.display_stop)
end

end

class TestTrack < Test::Unit::TestCase
def setup
@panel = Bio::Graphics::Panel.new(1000, 500, false, 0, 1000)
def setup
@panel = Bio::Graphics::Panel.new(1000, :width => 500, :clickable => false,
:display_start => 0, :display_stop => 1000)
end

def test_track_creation
Expand All @@ -38,7 +41,7 @@ def test_track_creation

class TestFeature < Test::Unit::TestCase
def setup
@panel = Bio::Graphics::Panel.new(1000, 500, false, 0, 1000)
@panel = Bio::Graphics::Panel.new(1000, :width => 500)
@track = @panel.add_track('test_track', false, :generic, [1,0,0])
end

Expand Down
22 changes: 8 additions & 14 deletions trunk/test/unit/test_draw.rb
Expand Up @@ -3,7 +3,7 @@

class TestPanel < Test::Unit::TestCase
def test_draw_showcase
my_panel = Bio::Graphics::Panel.new(500, 1000, false)
my_panel = Bio::Graphics::Panel.new(500, :width => 1000)

generic_track = my_panel.add_track('generic', false)
line_track = my_panel.add_track('line', false, :line, [0,0,1])
Expand All @@ -30,7 +30,6 @@ def test_draw_showcase
dot_track.add_feature(Bio::Feature.new('marker', '57'), 'thing3')
dot_track.add_feature(Bio::Feature.new('marker', '114'), 'thing2','http://digg.com')


spliced_track.add_feature(Bio::Feature.new('gene','join(34..52,109..183)'), 'gene1','http://news.bbc.co.uk')
spliced_track.add_feature(Bio::Feature.new('gene','complement(join(170..231,264..299,350..360,409..445))'), 'gene2')
spliced_track.add_feature(Bio::Feature.new('gene','join(134..152,209..283)'), 'gene3')
Expand All @@ -43,11 +42,10 @@ def test_draw_showcase
my_panel.draw(output_file)
system("display " + output_file + "& sleep 2 && kill $!")
File.delete(output_file)

end

def test_arkdb_features
my_panel = Bio::Graphics::Panel.new(4173015, 600, false, 1, 4173015, true)
my_panel = Bio::Graphics::Panel.new(4173015, :width => 600, :verticle => true)

#Create and configure tracks
scaffold_track = my_panel.add_track('scaffold', false)
Expand Down Expand Up @@ -82,12 +80,11 @@ def test_arkdb_features
my_panel.draw(output_file)

system("display " + output_file + "& sleep 2 && kill $!")
File.delete(output_file)

File.delete(output_file)
end

def test_subfeatures
my_panel = Bio::Graphics::Panel.new(500, 600, false, 1, 500, false)
my_panel = Bio::Graphics::Panel.new(500, :width => 600)

track = my_panel.add_track('mrna')

Expand All @@ -109,12 +106,11 @@ def test_subfeatures
my_panel.draw(output_file)

system("display " + output_file + "& sleep 2 && kill $!")
File.delete(output_file)

File.delete(output_file)
end

def test_feature_specific_colouring
my_panel = Bio::Graphics::Panel.new(375, 600, false, 1, 375, false)
my_panel = Bio::Graphics::Panel.new(375, :width => 600)

track = my_panel.add_track('mrna')

Expand All @@ -131,8 +127,6 @@ def test_feature_specific_colouring
my_panel.draw(output_file)

system("display " + output_file + "& sleep 2 && kill $!")
File.delete(output_file)

end

File.delete(output_file)
end
end

0 comments on commit 393dd38

Please sign in to comment.