[BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, NONE, 1.1 test_double_stranded.rb, NONE, 1.1 test_integer.rb, NONE, 1.1 test_single_strand.rb, NONE, 1.1 test_single_strand_complement.rb, NONE, 1.1 test_string_formatting.rb, NONE, 1.1

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


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

Added Files:
	test_analysis.rb test_double_stranded.rb test_integer.rb 
	test_single_strand.rb test_single_strand_complement.rb 
	test_string_formatting.rb 
Log Message:
Bio::RestrictionEnzyme tests


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

require 'test/unit'
require 'bio/util/restriction_enzyme/integer'

module Bio

class TestCutLocationsInEnzymeNotation < Test::Unit::TestCase

  def test_negative?
    assert_equal(false, 1.negative?)
    assert_equal(false, 0.negative?)
    assert_equal(true, -1.negative?)
  end

end

end

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

require 'test/unit'
require 'bio/util/restriction_enzyme/string_formatting'

module Bio

class TestStringFormatting < Test::Unit::TestCase

  include Bio::RestrictionEnzyme::StringFormatting

  def setup
    @t = String
    @obj_1 = @t.new('gata')
    @obj_2 = @t.new('garraxt')
    @obj_3 = @t.new('gArraXT')
    @obj_4 = @t.new('nnnnnnngarraxtnn')
  end

  def test_strip_padding
    assert_equal('gata', strip_padding(@obj_1))
    assert_equal('garraxt', strip_padding(@obj_2))
    assert_equal('gArraXT', strip_padding(@obj_3))
    assert_equal('garraxt', strip_padding(@obj_4))
  end

  def test_left_padding
    assert_equal('', left_padding(@obj_1))
    assert_equal('', left_padding(@obj_2))
    assert_equal('', left_padding(@obj_3))
    assert_equal('nnnnnnn', left_padding(@obj_4))
  end

  def test_right_padding
    assert_equal('', right_padding(@obj_1))
    assert_equal('', right_padding(@obj_2))
    assert_equal('', right_padding(@obj_3))
    assert_equal('nn', right_padding(@obj_4))
  end

  def test_add_spacing
    assert_equal('n^n g^a t^a', add_spacing('n^ng^at^a') )
    assert_equal('n^n g^a r r a x t^n', add_spacing('n^ng^arraxt^n') )
  end

end

end

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

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

module Bio

class TestAnalysis < Test::Unit::TestCase

  def setup
    @enz = Bio::RestrictionEnzyme
    @t = Bio::RestrictionEnzyme::Analysis
    
    @obj_1 = @t.cut('cagagag', 'ag^ag')
    @obj_2 = @t.cut('agagag', 'ag^ag')
    @obj_3 = @t.cut('cagagagt', 'ag^ag')

    e1 = @enz.new('atgcatgc', [3,3])
    @obj_4 = @t.cut('atgcatgcatgc', e1)

    e2 = @enz.new('atgcatgc', [3,5])
    @obj_5 = @t.cut('atgcatgcatgc', e2)

    e3 = @enz.new('anna', [1,1], [3,3])
    e4 = @enz.new('gg', [1,1])
    @obj_6 = @t.cut('agga', e3, e4)

    @obj_7 = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII')
    @obj_8 = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII', 'HincII')

    @obj_1d = @t.cut_without_permutations('cagagag', 'ag^ag')
    @obj_2d = @t.cut_without_permutations('agagag', 'ag^ag')
    @obj_3d = @t.cut_without_permutations('cagagagt', 'ag^ag')

    e1 = @enz.new('atgcatgc', [3,3])
    @obj_4d = @t.cut_without_permutations('atgcatgcatgc', e1)

    e2 = @enz.new('atgcatgc', [3,5])
    @obj_5d = @t.cut_without_permutations('atgcatgcatgc', e2)

    e3 = @enz.new('anna', [1,1], [3,3])
    e4 = @enz.new('gg', [1,1])
    @obj_6d = @t.cut_without_permutations('agga', e3, e4)

    @obj_7d = @t.cut_without_permutations('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII')
    @obj_8d = @t.cut_without_permutations('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII', 'HincII')

  end

  def test_cut
    assert_equal(["ag", "cag"], @obj_1.primary)
    assert_equal(["gtc", "tc"], @obj_1.complement)
    assert_equal(2, @obj_1.size)
    assert_equal(Bio::RestrictionEnzyme::Analysis::UniqueFragments, @obj_1.class)
    assert_equal(Bio::RestrictionEnzyme::Analysis::UniqueFragment, @obj_1[0].class)

    assert_equal(["ag"], @obj_2.primary)
    assert_equal(["ag", "agt", "cag"], @obj_3.primary)
    assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary)
    assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary)
    assert_equal(["a", "ag", "g", "ga"], @obj_6.primary)
    assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary)
    assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary)
  end

  def test_cut_without_permutations
    assert_equal(["ag", "cag"], @obj_1d.primary)
    assert_equal(["ag"], @obj_2d.primary)
    assert_equal(["ag", "agt", "cag"], @obj_3d.primary)
    assert_equal(["atg", "catg", "catgc"], @obj_4d.primary)
    assert_equal(["atg", "catg", "catgc"], @obj_5d.primary)
    assert_equal(["a", "g"], @obj_6d.primary)
    assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7d.primary)
    assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8d.primary)
  end

  def test_cut_from_bio_sequence_na
    assert_equal(["ag", "cag"], Bio::Sequence::NA.new('cagagag').cut_with_enzyme('ag^ag').primary )
    assert_equal(["ag", "cag"], Bio::Sequence::NA.new('cagagag').cut_with_enzymes('ag^ag').primary )
    assert_equal(["ag", "cag"], Bio::Sequence::NA.new('cagagag').cut_with_enzymes('ag^ag', 'EcoRII').primary )

    # NOTE: investigate where the '' is coming from
    assert_equal(["", "ag", "ag", "cag", "ccagg"], Bio::Sequence::NA.new('cagagagccagg').cut_with_enzymes('ag^ag', 'EcoRII').primary )
  end

end

end

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

require 'test/unit'
require 'bio/util/restriction_enzyme/double_stranded'

module Bio

class TestDoubleStranded < Test::Unit::TestCase

  def setup
    @t = Bio::RestrictionEnzyme::DoubleStranded
    @cl = Bio::RestrictionEnzyme::DoubleStranded::CutLocationPairInEnzymeNotation
    @s = String


    @obj_1 = @t.new(@s.new('gata'), [1,2])
    @obj_2 = @t.new('gata', [1,2])
    @obj_3 = @t.new('garraxt', [1,2])
    @obj_4 = @t.new('nnnnnnngarraxtnn', [1,2])

    @obj_5 = @t.new('garraxt', @cl.new(3,2), @cl.new(-2,-1), @cl.new(9,11))
    @obj_6 = @t.new('garraxt', @cl.new(3,2))
    @obj_7 = @t.new('garraxt', @cl.new(3,2), @cl.new(9,11))

    @obj_8 = @t.new('garraxt', 3..2, 9..11)
    @obj_9 = @t.new('garraxt', [3,2], [9,11])

    @obj_10 = @t.new('garraxt', [3,2], [9,11])

    @obj_11 = @t.new('n^ngar^raxtnn^n')
    @obj_12 = @t.new('nnnn^ngar^raxtnn^nnnn')

    @obj_13 = @t.new(Bio::RestrictionEnzyme.rebase['EcoRII'])
    @obj_14 = @t.new('EcoRII')
    @obj_15 = @t.new('ecorii')
  end

  def test_primary
    assert_equal('nngarraxtnnn', @obj_5.primary)
  end

  def test_primary_with_cut_symbols
    assert_equal('n^ngar^raxtnn^n', @obj_5.primary.with_cut_symbols)
    assert_equal('gar^raxt', @obj_6.primary.with_cut_symbols)
    assert_equal('gar^raxtnn^n', @obj_7.primary.with_cut_symbols)

    assert_equal('gar^raxtnn^n', @obj_8.primary.with_cut_symbols)
    assert_equal('gar^raxtnn^n', @obj_9.primary.with_cut_symbols)

    assert_equal('gar^raxtnn^n', @obj_10.primary.with_cut_symbols)
    
    assert_equal('n^ngar^raxtnn^n', @obj_11.primary.with_cut_symbols)
    assert_equal('n^ngar^raxtnn^n', @obj_12.primary.with_cut_symbols)

    assert_equal('n^ccwgg', @obj_13.primary.with_cut_symbols)
    assert_equal('n^ccwgg', @obj_14.primary.with_cut_symbols)
    assert_equal('n^ccwgg', @obj_15.primary.with_cut_symbols)
  end

  def test_complement_with_cut_symbols
    assert_equal('n^ct^yytxannnn^n', @obj_5.complement.with_cut_symbols)
    assert_equal('ct^yytxa', @obj_6.complement.with_cut_symbols)
    assert_equal('ct^yytxannnn^n', @obj_7.complement.with_cut_symbols)

    assert_equal('ct^yytxannnn^n', @obj_8.complement.with_cut_symbols)
    assert_equal('ct^yytxannnn^n', @obj_9.complement.with_cut_symbols)

    assert_equal('ct^yytxannnn^n', @obj_10.complement.with_cut_symbols)

    assert_equal('n^nnctyy^txan^n', @obj_11.complement.with_cut_symbols)
    assert_equal('n^nnctyy^txan^n', @obj_12.complement.with_cut_symbols)

    assert_equal('ggwcc^n', @obj_13.complement.with_cut_symbols)
    assert_equal('ggwcc^n', @obj_14.complement.with_cut_symbols)
    assert_equal('ggwcc^n', @obj_15.complement.with_cut_symbols)
  end

  def test_complement
    assert_equal('nctyytxannnnn', @obj_5.complement)
  end

  def test_cut_locations
    assert_equal([[4, 3], [0, 1], [10, 12]], @obj_5.cut_locations)
  end

  def test_cut_locations_in_enzyme_notation
    assert_equal([[3, 2], [-2, -1], [9, 11]], @obj_5.cut_locations_in_enzyme_notation)
  end

  def test_argument_error
    assert_raise(ArgumentError) { @t.new('garraxt', [3,2,9,11]) }
    assert_raise(ArgumentError) { @t.new(Bio::RestrictionEnzyme.rebase['ecorii'] )}
    assert_raise(ArgumentError) { @t.new(Bio::RestrictionEnzyme.rebase['EzzRII']) }
  end

  def test_index_error
    assert_raise(IndexError) { @t.new('EzzRII') }
  end

  # NOTE
  def test_to_re
  end

end

end

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

require 'test/unit'
require 'bio/util/restriction_enzyme/single_strand_complement'

module Bio

class TestSingleStrandComplement < Test::Unit::TestCase

  def setup
    @t = Bio::RestrictionEnzyme::SingleStrandComplement
    @cl = Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation
    @s = Bio::Sequence::NA

    @obj_1 = @t.new(@s.new('gata'), @cl.new(-2,1,3))
    @obj_2 = @t.new('gata', -2, 1, 3)
    @obj_3 = @t.new('garraxt', [-2, 1, 7])
    @obj_4 = @t.new('nnnnnnngarraxtnn', [-2, 1, 7])

    @obj_5 = @t.new('ga^rr^axt')
    @obj_6 = @t.new('^ga^rr^axt')
    @obj_7 = @t.new('n^ngar^raxtnn^n')
  end

  def test_pattern_palindromic?
    assert_equal(true, @t.new('atgcat', 1).palindromic?)
    assert_equal(false, @t.new('atgcgta', 1).palindromic?)

    assert_equal(false, @obj_1.palindromic?)
    assert_equal(false, @obj_2.palindromic?)
    assert_equal(false, @obj_3.palindromic?)
    assert_equal(false, @obj_4.palindromic?)
  end

  def test_stripped
    assert_equal('gata', @obj_1.stripped)
    assert_equal('gata', @obj_2.stripped)
    assert_equal('garraxt', @obj_3.stripped)
    assert_equal('garraxt', @obj_4.stripped)
  end

  def test_pattern
    assert_equal('nngata', @obj_1.pattern)
    assert_equal('nngata', @obj_2.pattern)
    assert_equal('nngarraxtn', @obj_3.pattern)
    assert_equal('nngarraxtn', @obj_4.pattern)

    assert_equal('nngata', @obj_1)
    assert_equal('nngata', @obj_2)
    assert_equal('nngarraxtn', @obj_3)
    assert_equal('nngarraxtn', @obj_4)
  end

  def test_with_cut_symbols
    assert_equal('n^ng^at^a', @obj_1.with_cut_symbols)
    assert_equal('n^ng^at^a', @obj_2.with_cut_symbols)
    assert_equal('n^ng^arraxt^n', @obj_3.with_cut_symbols)
    assert_equal('n^ng^arraxt^n', @obj_4.with_cut_symbols)
  end

  def test_with_spaces
    assert_equal('n^n g^a t^a', @obj_1.with_spaces)
    assert_equal('n^n g^a t^a', @obj_2.with_spaces)
    assert_equal('n^n g^a r r a x t^n', @obj_3.with_spaces)
    assert_equal('n^n g^a r r a x t^n', @obj_4.with_spaces)
  end

  def test_cut_locations_in_enzyme_notation
    assert_equal([-2,1,3], @obj_1.cut_locations_in_enzyme_notation)
    assert_equal([-2,1,3], @obj_2.cut_locations_in_enzyme_notation)
    assert_equal([-2,1,7], @obj_3.cut_locations_in_enzyme_notation)
    assert_equal([-2,1,7], @obj_4.cut_locations_in_enzyme_notation)

    assert_equal([2,4], @obj_5.cut_locations_in_enzyme_notation)
    assert_equal([-1,2,4], @obj_6.cut_locations_in_enzyme_notation)
    assert_equal([-2,3,9], @obj_7.cut_locations_in_enzyme_notation)
  end

  def test_cut_locations
    assert_equal([0,2,4], @obj_1.cut_locations)
    assert_equal([0,2,4], @obj_2.cut_locations)
    assert_equal([0,2,8], @obj_3.cut_locations)
    assert_equal([0,2,8], @obj_4.cut_locations)

    assert_equal([1,3], @obj_5.cut_locations)
    assert_equal([0,2,4], @obj_6.cut_locations)
    assert_equal([0,4,10], @obj_7.cut_locations)
  end

  def test_orientation
    assert_equal([3,5], @obj_1.orientation)
    assert_equal([3,5], @obj_2.orientation)
    assert_equal([3,5], @obj_3.orientation)
    assert_equal([3,5], @obj_4.orientation)
  end

  def test_creation_with_no_cuts
    @obj_8 = @t.new('garraxt')
    assert_equal([3,5], @obj_8.orientation)
    assert_equal([], @obj_8.cut_locations)
    assert_equal([], @obj_8.cut_locations_in_enzyme_notation)
    assert_equal('garraxt', @obj_8.pattern)
  end

  # NOTE
  def test_to_re
  end

  def test_argument_error
    assert_raise(ArgumentError) { @t.new('a', [0,1,2]) }
    assert_raise(ArgumentError) { @t.new('a', 0,1,2,0) }

    assert_raise(ArgumentError) { @t.new('a', [nil,1,2]) }
    assert_raise(ArgumentError) { @t.new('a', nil,1,2,nil) }

    assert_raise(ArgumentError) { @t.new('a', [1,1,2]) }
    assert_raise(ArgumentError) { @t.new('a', 1,1,2,2) }

    assert_raise(ArgumentError) { @t.new(1, [1,2,3]) }
    assert_raise(ArgumentError) { @t.new('gaat^aca', [1,2,3]) }
    assert_raise(ArgumentError) { @t.new('gaat^^aca') }
    assert_raise(ArgumentError) { @t.new('z', [1,2,3]) }

    assert_raise(ArgumentError) { @t.new('g', [0,1,2]) }
    assert_raise(ArgumentError) { @t.new('g', 0,1,2,0) }
    assert_raise(ArgumentError) { @t.new('g', [0,1,1,2]) }
    assert_raise(ArgumentError) { @t.new('g', 0,1,1,2,2) }
    assert_raise(ArgumentError) { @t.new(1,2,3) }
    assert_raise(ArgumentError) { @t.new(1,2,'g') }
  end


end

end

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

require 'test/unit'
require 'bio/util/restriction_enzyme/single_strand'

module Bio

class TestSingleStrand < Test::Unit::TestCase

  def setup
    @t = Bio::RestrictionEnzyme::SingleStrand
    @cl = Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation
    @s = Bio::Sequence::NA

    @obj_1 = @t.new(@s.new('gata'), @cl.new(-2,1,3))
    @obj_2 = @t.new('gata', -2, 1, 3)
    @obj_3 = @t.new('garraxt', [-2, 1, 7])
    @obj_4 = @t.new('nnnnnnngarraxtnn', [-2, 1, 7])

    @obj_5 = @t.new('ga^rr^axt')
    @obj_6 = @t.new('^ga^rr^axt')
    @obj_7 = @t.new('n^ngar^raxtnn^n')
  end

  def test_pattern_palindromic?
    assert_equal(true, @t.new('atgcat', 1).palindromic?)
    assert_equal(false, @t.new('atgcgta', 1).palindromic?)

    assert_equal(false, @obj_1.palindromic?)
    assert_equal(false, @obj_2.palindromic?)
    assert_equal(false, @obj_3.palindromic?)
    assert_equal(false, @obj_4.palindromic?)
  end

  def test_stripped
    assert_equal('gata', @obj_1.stripped)
    assert_equal('gata', @obj_2.stripped)
    assert_equal('garraxt', @obj_3.stripped)
    assert_equal('garraxt', @obj_4.stripped)
  end

  def test_pattern
    assert_equal('nngata', @obj_1.pattern)
    assert_equal('nngata', @obj_2.pattern)
    assert_equal('nngarraxtn', @obj_3.pattern)
    assert_equal('nngarraxtn', @obj_4.pattern)

    assert_equal('nngata', @obj_1)
    assert_equal('nngata', @obj_2)
    assert_equal('nngarraxtn', @obj_3)
    assert_equal('nngarraxtn', @obj_4)
  end

  def test_with_cut_symbols
    assert_equal('n^ng^at^a', @obj_1.with_cut_symbols)
    assert_equal('n^ng^at^a', @obj_2.with_cut_symbols)
    assert_equal('n^ng^arraxt^n', @obj_3.with_cut_symbols)
    assert_equal('n^ng^arraxt^n', @obj_4.with_cut_symbols)
  end

  def test_with_spaces
    assert_equal('n^n g^a t^a', @obj_1.with_spaces)
    assert_equal('n^n g^a t^a', @obj_2.with_spaces)
    assert_equal('n^n g^a r r a x t^n', @obj_3.with_spaces)
    assert_equal('n^n g^a r r a x t^n', @obj_4.with_spaces)
  end

  def test_cut_locations_in_enzyme_notation
    assert_equal([-2,1,3], @obj_1.cut_locations_in_enzyme_notation)
    assert_equal([-2,1,3], @obj_2.cut_locations_in_enzyme_notation)
    assert_equal([-2,1,7], @obj_3.cut_locations_in_enzyme_notation)
    assert_equal([-2,1,7], @obj_4.cut_locations_in_enzyme_notation)

    assert_equal([2,4], @obj_5.cut_locations_in_enzyme_notation)
    assert_equal([-1,2,4], @obj_6.cut_locations_in_enzyme_notation)
    assert_equal([-2,3,9], @obj_7.cut_locations_in_enzyme_notation)
  end

  def test_cut_locations
    assert_equal([0,2,4], @obj_1.cut_locations)
    assert_equal([0,2,4], @obj_2.cut_locations)
    assert_equal([0,2,8], @obj_3.cut_locations)
    assert_equal([0,2,8], @obj_4.cut_locations)

    assert_equal([1,3], @obj_5.cut_locations)
    assert_equal([0,2,4], @obj_6.cut_locations)
    assert_equal([0,4,10], @obj_7.cut_locations)
  end

  def test_orientation
    assert_equal([5,3], @obj_1.orientation)
    assert_equal([5,3], @obj_2.orientation)
    assert_equal([5,3], @obj_3.orientation)
    assert_equal([5,3], @obj_4.orientation)
  end

  def test_creation_with_no_cuts
    @obj_8 = @t.new('garraxt')
    assert_equal([5,3], @obj_8.orientation)
    assert_equal([], @obj_8.cut_locations)
    assert_equal([], @obj_8.cut_locations_in_enzyme_notation)
    assert_equal('garraxt', @obj_8.pattern)
  end

  # NOTE
  def test_to_re
  end

  def test_argument_error
    assert_raise(ArgumentError) { @t.new('a', [0,1,2]) }
    assert_raise(ArgumentError) { @t.new('a', 0,1,2,0) }

    assert_raise(ArgumentError) { @t.new('a', [nil,1,2]) }
    assert_raise(ArgumentError) { @t.new('a', nil,1,2,nil) }

    assert_raise(ArgumentError) { @t.new('a', [1,1,2]) }
    assert_raise(ArgumentError) { @t.new('a', 1,1,2,2) }

    assert_raise(ArgumentError) { @t.new(1, [1,2,3]) }
    assert_raise(ArgumentError) { @t.new('gaat^aca', [1,2,3]) }
    assert_raise(ArgumentError) { @t.new('gaat^^aca') }
    assert_raise(ArgumentError) { @t.new('z', [1,2,3]) }

    assert_raise(ArgumentError) { @t.new('g', [0,1,2]) }
    assert_raise(ArgumentError) { @t.new('g', 0,1,2,0) }
    assert_raise(ArgumentError) { @t.new('g', [0,1,1,2]) }
    assert_raise(ArgumentError) { @t.new('g', 0,1,1,2,2) }
    assert_raise(ArgumentError) { @t.new(1,2,3) }
    assert_raise(ArgumentError) { @t.new(1,2,'g') }
  end


end

end




More information about the bioruby-cvs mailing list