[BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme/analysis test_calculated_cuts.rb, NONE, 1.1 test_sequence_range.rb, NONE, 1.1

Trevor Wennblom trevor at pub.open-bio.org
Wed Feb 1 07:31:24 UTC 2006


Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis
In directory pub.open-bio.org:/tmp/cvs-serv28943/analysis

Added Files:
	test_calculated_cuts.rb test_sequence_range.rb 
Log Message:
Bio::RestrictionEnzyme tests


--- NEW FILE: test_sequence_range.rb ---
require 'pathname'
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s
$:.unshift(libpath) unless $:.include?(libpath)

require 'test/unit'
require 'bio/util/restriction_enzyme/analysis/sequence_range'
require 'bio/util/restriction_enzyme/analysis/fragments'

require 'bio/util/restriction_enzyme/analysis/cut_range'
require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range'
require 'bio/util/restriction_enzyme/analysis/vertical_cut_range'
require 'bio/util/restriction_enzyme/analysis/cut_ranges'

module Bio

class TestAnalysisSequenceRange < Test::Unit::TestCase

  def setup
    @t = Bio::RestrictionEnzyme::Analysis::SequenceRange
    @fs = Bio::RestrictionEnzyme::Analysis::Fragments
    #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right )

    @vcr = Bio::RestrictionEnzyme::Analysis::VerticalCutRange
    @crs = Bio::RestrictionEnzyme::Analysis::CutRanges
    @hcr = Bio::RestrictionEnzyme::Analysis::HorizontalCutRange

    @obj_1 = @t.new(0,5)
    @obj_1.add_cut_range(0,nil,nil,3)
    @obj_1.add_cut_range(nil,2,nil,nil)

    @obj_2 = @t.new(0,5)
    @obj_2.add_cut_ranges( @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil)] ))

    @obj_3 = @t.new(0,5)
    @obj_3.add_cut_ranges( @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil)] ))
    @obj_3.add_cut_ranges( @crs.new( [@hcr.new(0), @hcr.new(5)] ))

    @obj_4 = @t.new(0,5)
    @obj_4.add_cut_ranges( @crs.new( [@vcr.new(0,2,1,3)] ))

    @obj_5 = @t.new(0,5)
    @obj_5.add_cut_ranges( @crs.new( [@vcr.new(0,nil,nil,nil), @vcr.new(nil,4,3,nil), @hcr.new(1,2)] ))

    @obj_6 = @t.new(0,5)
    @obj_6.add_cut_ranges( @crs.new( [@vcr.new(nil,nil,0,nil), @hcr.new(1,2), @vcr.new(nil,4,3,nil)] ))

    @obj_7 = @t.new(0,5)
    @obj_7.add_cut_ranges( @crs.new( [@vcr.new(nil,2,nil,nil), @hcr.new(0,2)] ))

    @obj_8 = @t.new(0,11)
    @obj_8.add_cut_ranges( @crs.new( [@hcr.new(0,1), @vcr.new(nil,nil,nil,5), @hcr.new(7,8), @hcr.new(10), @vcr.new(nil,10,nil,nil)] ))

    @obj_9 = @t.new(0,5)
    @obj_9.add_cut_ranges( @crs.new( [@vcr.new(nil,3,nil,3)] ))

    @obj_10 = @t.new(0,5)
    @obj_10.add_cut_ranges( @crs.new( [@vcr.new(0,nil,nil,3), @vcr.new(nil,2,nil,2)] ))
  end

  def test_fragments
    assert_equal(@fs, @obj_1.fragments.class)
  end

  # '0|1 2|3 4 5'
  # ' +---+-+   '
  # '0 1 2 3|4 5'
  def test_fragments_for_display_1
    x = @obj_1
    assert_equal(3, x.fragments.for_display.size)

    assert_equal('0   ', x.fragments.for_display[0].primary)
    assert_equal('0123', x.fragments.for_display[0].complement)

    assert_equal('12', x.fragments.for_display[1].primary)
    assert_equal('  ', x.fragments.for_display[1].complement)

    assert_equal('345', x.fragments.for_display[2].primary)
    assert_equal(' 45', x.fragments.for_display[2].complement)
  end

  # '0|1 2|3|4 5'
  # ' +---+ +-+ '
  # '0 1 2 3 4|5'
  def test_fragments_for_display_2
    x = @obj_2
    assert_equal(3, x.fragments.for_display.size)

    assert_equal('0  3 ', x.fragments.for_display[0].primary)
    assert_equal('01234', x.fragments.for_display[0].complement)

    assert_equal('12', x.fragments.for_display[1].primary)
    assert_equal('  ', x.fragments.for_display[1].complement)

    assert_equal('45', x.fragments.for_display[2].primary)
    assert_equal(' 5', x.fragments.for_display[2].complement)
  end

  # '0|1 2|3|4 5'
  # '-+---+ +-+-'
  # '0 1 2 3 4|5'
  def test_fragments_for_display_3
    x = @obj_3
    assert_equal(5, x.fragments.for_display.size)

    assert_equal('0', x.fragments.for_display[0].primary)
    assert_equal(' ', x.fragments.for_display[0].complement)

    assert_equal('   3 ', x.fragments.for_display[1].primary)
    assert_equal('01234', x.fragments.for_display[1].complement)

    assert_equal('12', x.fragments.for_display[2].primary)
    assert_equal('  ', x.fragments.for_display[2].complement)

    assert_equal('45', x.fragments.for_display[3].primary)
    assert_equal('  ', x.fragments.for_display[3].complement)

    assert_equal(' ', x.fragments.for_display[4].primary)
    assert_equal('5', x.fragments.for_display[4].complement)
  end

  # '0|1 2|3 4 5'
  # ' +-+-+-+   '
  # '0 1|2 3|4 5'
  def test_fragments_for_display_4
    x = @obj_4
    assert_equal(4, x.fragments.for_display.size)

    assert_equal('0 ', x.fragments.for_display[0].primary)
    assert_equal('01', x.fragments.for_display[0].complement)

    assert_equal('12', x.fragments.for_display[1].primary)
    assert_equal('  ', x.fragments.for_display[1].complement)

    assert_equal('  ', x.fragments.for_display[2].primary)
    assert_equal('23', x.fragments.for_display[2].complement)

    assert_equal('345', x.fragments.for_display[3].primary)
    assert_equal(' 45', x.fragments.for_display[3].complement)
  end

  # '0 1 2 3 4|5'
  # '       +-+ '
  # '0 1 2 3|4 5'
  def test_fragments_for_display_5
    x = @obj_5
    assert_equal(2, x.fragments.for_display.size)

    assert_equal('01234', x.fragments.for_display[0].primary)
    assert_equal('0123 ', x.fragments.for_display[0].complement)

    assert_equal(' 5', x.fragments.for_display[1].primary)
    assert_equal('45', x.fragments.for_display[1].complement)
  end

  # '0 1 2 3 4|5'
  # '       +-+ '
  # '0 1 2 3|4 5'
  def test_fragments_for_display_6
    x = @obj_6
    assert_equal(2, x.fragments.for_display.size)

    assert_equal('01234', x.fragments.for_display[0].primary)
    assert_equal('0123 ', x.fragments.for_display[0].complement)

    assert_equal(' 5', x.fragments.for_display[1].primary)
    assert_equal('45', x.fragments.for_display[1].complement)
  end

  # '0 1 2|3 4 5'
  # '-----+     '
  # '0 1 2 3 4 5'
  def test_fragments_for_display_7
    x = @obj_7
    assert_equal(2, x.fragments.for_display.size)

    assert_equal('012', x.fragments.for_display[0].primary)
    assert_equal('   ', x.fragments.for_display[0].complement)

    assert_equal('   345', x.fragments.for_display[1].primary)
    assert_equal('012345', x.fragments.for_display[1].complement)
  end


  # '0 1 2 3 4 5 6 7 8 9 0 1'
  # '                       '
  # '0 1 2 3 4 5 6 7 8 9 0 1'
  def test_fragments_for_display_8
    x = @obj_8
    assert_equal(1, x.fragments.for_display.size)

    assert_equal('012345678901', x.fragments.for_display[0].primary)
    assert_equal('012345678901', x.fragments.for_display[0].complement)
  end

  # '0 1 2 3|4 5'
  # '       +   '
  # '0 1 2 3|4 5'
  def test_fragments_for_display_9
    x = @obj_9
    assert_equal(2, x.fragments.for_display.size)

    assert_equal('0123', x.fragments.for_display[0].primary)
    assert_equal('0123', x.fragments.for_display[0].complement)

    assert_equal('45', x.fragments.for_display[1].primary)
    assert_equal('45', x.fragments.for_display[1].complement)
  end

  # '0|1 2|3 4 5'
  # ' +---+-+   '
  # '0 1 2|3|4 5'
  def test_fragments_for_display_10
    x = @obj_10
    assert_equal(4, x.fragments.for_display.size)

    assert_equal('0  ', x.fragments.for_display[0].primary)
    assert_equal('012', x.fragments.for_display[0].complement)

    assert_equal('12', x.fragments.for_display[1].primary)
    assert_equal('  ', x.fragments.for_display[1].complement)

    assert_equal('345', x.fragments.for_display[2].primary)
    assert_equal(' 45', x.fragments.for_display[2].complement)

    assert_equal(' ', x.fragments.for_display[3].primary)
    assert_equal('3', x.fragments.for_display[3].complement)
  end

end
end

--- NEW FILE: test_calculated_cuts.rb ---
require 'pathname'
libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s
$:.unshift(libpath) unless $:.include?(libpath)

require 'test/unit'
require 'bio/util/restriction_enzyme/analysis/calculated_cuts'
require 'bio/util/restriction_enzyme/analysis/cut_range'
require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range'
require 'bio/util/restriction_enzyme/analysis/vertical_cut_range'
require 'bio/util/restriction_enzyme/analysis/cut_ranges'

module Bio

class TestAnalysisCalculatedCuts < Test::Unit::TestCase

  def setup
    @t = Bio::RestrictionEnzyme::Analysis::CalculatedCuts
    @vcr = Bio::RestrictionEnzyme::Analysis::VerticalCutRange
    @crs = Bio::RestrictionEnzyme::Analysis::CutRanges
    @hcr = Bio::RestrictionEnzyme::Analysis::HorizontalCutRange

    #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right )

    @obj_1 = @t.new(6)
    @obj_1.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,nil,nil,3), @vcr.new(nil,2,nil,nil)] ))
    @obj_1b = @obj_1.dup
    @obj_1b.remove_incomplete_cuts

    @obj_2 = @t.new(6)
    @obj_2.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil)] ))
    @obj_2b = @obj_2.dup
    @obj_2b.remove_incomplete_cuts

    @obj_3 = @t.new(6)
    @obj_3.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil)] ))
    @obj_3.add_cuts_from_cut_ranges( @crs.new( [@hcr.new(0), @hcr.new(5)] ))
    @obj_3b = @obj_3.dup
    @obj_3b.remove_incomplete_cuts

    @obj_4 = @t.new(6)
    @obj_4.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,2,1,3)] ))
    @obj_4b = @obj_4.dup
    @obj_4b.remove_incomplete_cuts

    # Same thing, declared a different way
    @obj_4_c1 = @t.new(6)
    @obj_4_c1.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(nil,nil,1,3), @vcr.new(0,2,nil,nil)] ))
    @obj_4b_c1 = @obj_4_c1.dup
    @obj_4b_c1.remove_incomplete_cuts

    # Same thing, declared a different way
    @obj_4_c2 = @t.new(6)
    @obj_4_c2.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,nil,nil,3), @vcr.new(nil,2,1,nil)] ))
    @obj_4b_c2 = @obj_4_c2.dup
    @obj_4b_c2.remove_incomplete_cuts

    @obj_5 = @t.new(6)
    @obj_5.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,nil,nil,nil), @vcr.new(nil,4,3,nil), @hcr.new(1,2)] ))
    @obj_5b = @obj_5.dup
    @obj_5b.remove_incomplete_cuts

    @obj_6 = @t.new(6)
    @obj_6.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(nil,nil,0,nil), @hcr.new(1,2), @vcr.new(nil,4,3,nil)] ))
    @obj_6b = @obj_6.dup
    @obj_6b.remove_incomplete_cuts

    @obj_7 = @t.new(6)
    @obj_7.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(nil,2,nil,nil), @hcr.new(0,2)] ))
    @obj_7b = @obj_7.dup
    @obj_7b.remove_incomplete_cuts

    @obj_8 = @t.new(12)
    @obj_8.add_cuts_from_cut_ranges( @crs.new( [@hcr.new(0,1), @vcr.new(nil,nil,nil,5), @hcr.new(7,8), @hcr.new(10), @vcr.new(nil,10,nil,nil)] ))
    @obj_8b = @obj_8.dup
    @obj_8b.remove_incomplete_cuts

    @obj_9 = @t.new(6)
    @obj_9.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(nil,3,nil,3)] ))
    @obj_9b = @obj_9.dup
    @obj_9b.remove_incomplete_cuts

    @obj_10 = @t.new(6)
    @obj_10.add_cuts_from_cut_ranges( @crs.new( [@vcr.new(0,nil,nil,3), @vcr.new(nil,2,nil,2)] ))
    @obj_10b = @obj_10.dup
    @obj_10b.remove_incomplete_cuts


  end

  def test_cuts
    x = @obj_1
    assert_equal([0,2], x.vc_primary)
    assert_equal([3], x.vc_complement)
    assert_equal([1,2,3], x.hc_between_strands)

    x = @obj_2
    assert_equal([0,2,3], x.vc_primary)
    assert_equal([4], x.vc_complement)
    assert_equal([1,2,4], x.hc_between_strands)

    x = @obj_3
    assert_equal([0,2,3], x.vc_primary)
    assert_equal([4], x.vc_complement)
    assert_equal([0,1,2,4,5], x.hc_between_strands)

    x = @obj_4
    assert_equal([0,2], x.vc_primary)
    assert_equal([1,3], x.vc_complement)
    assert_equal([1,2,3], x.hc_between_strands)

    x = @obj_4_c1
    assert_equal([0,2], x.vc_primary)
    assert_equal([1,3], x.vc_complement)
    assert_equal([1,2,3], x.hc_between_strands)

    x = @obj_4_c2
    assert_equal([0,2], x.vc_primary)
    assert_equal([1,3], x.vc_complement)
    assert_equal([1,2,3], x.hc_between_strands)

    x = @obj_5
    assert_equal([0,4], x.vc_primary)
    assert_equal([3], x.vc_complement)
    assert_equal([1,2,4], x.hc_between_strands)

    x = @obj_6
    assert_equal([4], x.vc_primary)
    assert_equal([0,3], x.vc_complement)
    assert_equal([1,2,4], x.hc_between_strands)

    x = @obj_7
    assert_equal([2], x.vc_primary)
    assert_equal([], x.vc_complement)
    assert_equal([0,1,2], x.hc_between_strands)

    x = @obj_8
    assert_equal([10], x.vc_primary)
    assert_equal([5], x.vc_complement)
    assert_equal([0,1,7,8,10], x.hc_between_strands)

    x = @obj_9
    assert_equal([3], x.vc_primary)
    assert_equal([3], x.vc_complement)
    assert_equal([], x.hc_between_strands)

    x = @obj_10
    assert_equal([0,2], x.vc_primary)
    assert_equal([2,3], x.vc_complement)
    assert_equal([1,2,3], x.hc_between_strands)
  end

  def test_cuts_after_remove_incomplete_cuts
    x = @obj_1b
    assert_equal([0,2], x.vc_primary)
    assert_equal([3], x.vc_complement)
    assert_equal([1,2,3], x.hc_between_strands)
  end

  def test_strands_for_display_current
  #check object_id
  end

  def test_strands_for_display
    x = @obj_1
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +---+-+   ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_1b
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +---+-+   ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_2
    assert_equal('0|1 2|3|4 5', x.strands_for_display[0])
    assert_equal(' +---+ +-+ ', x.strands_for_display[1])
    assert_equal('0 1 2 3 4|5', x.strands_for_display[2])

    x = @obj_2b
    assert_equal('0|1 2|3|4 5', x.strands_for_display[0])
    assert_equal(' +---+ +-+ ', x.strands_for_display[1])
    assert_equal('0 1 2 3 4|5', x.strands_for_display[2])

    x = @obj_3
    assert_equal('0|1 2|3|4 5', x.strands_for_display[0])
    assert_equal('-+---+ +-+-', x.strands_for_display[1])
    assert_equal('0 1 2 3 4|5', x.strands_for_display[2])

    x = @obj_3b
    assert_equal('0|1 2|3|4 5', x.strands_for_display[0])
    assert_equal('-+---+ +-+-', x.strands_for_display[1])
    assert_equal('0 1 2 3 4|5', x.strands_for_display[2])

    x = @obj_4
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +-+-+-+   ', x.strands_for_display[1])
    assert_equal('0 1|2 3|4 5', x.strands_for_display[2])

    x = @obj_4b
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +-+-+-+   ', x.strands_for_display[1])
    assert_equal('0 1|2 3|4 5', x.strands_for_display[2])

    x = @obj_4_c1
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +-+-+-+   ', x.strands_for_display[1])
    assert_equal('0 1|2 3|4 5', x.strands_for_display[2])

    x = @obj_4b_c1
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +-+-+-+   ', x.strands_for_display[1])
    assert_equal('0 1|2 3|4 5', x.strands_for_display[2])

    x = @obj_4_c2
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +-+-+-+   ', x.strands_for_display[1])
    assert_equal('0 1|2 3|4 5', x.strands_for_display[2])

    x = @obj_4b_c2
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +-+-+-+   ', x.strands_for_display[1])
    assert_equal('0 1|2 3|4 5', x.strands_for_display[2])

    x = @obj_5
    assert_equal('0|1 2 3 4|5', x.strands_for_display[0])
    assert_equal(' +---  +-+ ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_5b
    assert_equal('0 1 2 3 4|5', x.strands_for_display[0])
    assert_equal('       +-+ ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_6
    assert_equal('0 1 2 3 4|5', x.strands_for_display[0])
    assert_equal(' +---  +-+ ', x.strands_for_display[1])
    assert_equal('0|1 2 3|4 5', x.strands_for_display[2])

    x = @obj_6b
    assert_equal('0 1 2 3 4|5', x.strands_for_display[0])
    assert_equal('       +-+ ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_7
    assert_equal('0 1 2|3 4 5', x.strands_for_display[0])
    assert_equal('-----+     ', x.strands_for_display[1])
    assert_equal('0 1 2 3 4 5', x.strands_for_display[2])

    x = @obj_7b
    assert_equal('0 1 2|3 4 5', x.strands_for_display[0])
    assert_equal('-----+     ', x.strands_for_display[1])
    assert_equal('0 1 2 3 4 5', x.strands_for_display[2])

    x = @obj_8
    assert_equal('0 1 2 3 4 5 6 7 8 9 0|1', x.strands_for_display[0])
    assert_equal('---        +  ---   -+ ', x.strands_for_display[1])
    assert_equal('0 1 2 3 4 5|6 7 8 9 0 1', x.strands_for_display[2])

    x = @obj_8b
    assert_equal('0 1 2 3 4 5 6 7 8 9 0 1', x.strands_for_display[0])
    assert_equal('                       ', x.strands_for_display[1])
    assert_equal('0 1 2 3 4 5 6 7 8 9 0 1', x.strands_for_display[2])

    x = @obj_9
    assert_equal('0 1 2 3|4 5', x.strands_for_display[0])
    assert_equal('       +   ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_9b
    assert_equal('0 1 2 3|4 5', x.strands_for_display[0])
    assert_equal('       +   ', x.strands_for_display[1])
    assert_equal('0 1 2 3|4 5', x.strands_for_display[2])

    x = @obj_10
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +---+-+   ', x.strands_for_display[1])
    assert_equal('0 1 2|3|4 5', x.strands_for_display[2])

    x = @obj_10b
    assert_equal('0|1 2|3 4 5', x.strands_for_display[0])
    assert_equal(' +---+-+   ', x.strands_for_display[1])
    assert_equal('0 1 2|3|4 5', x.strands_for_display[2])

  end


end

end




More information about the bioruby-cvs mailing list