[BioRuby-cvs] bioruby/test/unit/bio test_alignment.rb,1.5,1.6

Naohisa Goto ngoto at pub.open-bio.org
Fri Dec 2 08:01:51 EST 2005


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

Modified Files:
	test_alignment.rb 
Log Message:
* TestAlignmentSequenceArray are changed to TestAlignmentEnumerableExtension.
* Added more tests


Index: test_alignment.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_alignment.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** test_alignment.rb	2 Dec 2005 07:01:38 -0000	1.5
--- test_alignment.rb	2 Dec 2005 13:01:49 -0000	1.6
***************
*** 242,249 ****
    end #class TestAlignmentSite
  
!   class TestAlignmentSequenceArray < Test::Unit::TestCase
      def test_each_seq
        expected_results = [ 'atg', 'aag', 'acg' ]
!       a = Alignment::SequenceArray[ *expected_results ]
        a.each_seq do |x|
          assert_equal(expected_results.shift, x)
--- 242,254 ----
    end #class TestAlignmentSite
  
!   # This is sample class for testing Bio::Alignment::EnumerableExtension.
!   class A < Array
!     include Alignment::EnumerableExtension
!   end
! 
!   class TestAlignmentEnumerableExtension < Test::Unit::TestCase
      def test_each_seq
        expected_results = [ 'atg', 'aag', 'acg' ]
!       a = A[ *expected_results ]
        a.each_seq do |x|
          assert_equal(expected_results.shift, x)
***************
*** 253,267 ****
  
      def test_seqclass_default
!       a = Alignment::SequenceArray.new
        assert_equal(String, a.seqclass)
      end
  
      def test_seqclass
!       a = Alignment::SequenceArray[ Bio::Sequence::NA.new('atg') ]
        assert_equal(Bio::Sequence::NA, a.seqclass)
      end
  
      def test_seqclass=()
!       a = Alignment::SequenceArray.new
        assert_equal(String, a.seqclass)
        a << Bio::Sequence::NA.new('a')
--- 258,272 ----
  
      def test_seqclass_default
!       a = A.new
        assert_equal(String, a.seqclass)
      end
  
      def test_seqclass
!       a = A[ Bio::Sequence::NA.new('atg') ]
        assert_equal(Bio::Sequence::NA, a.seqclass)
      end
  
      def test_seqclass=()
!       a = A.new
        assert_equal(String, a.seqclass)
        a << Bio::Sequence::NA.new('a')
***************
*** 272,281 ****
  
      def test_alignment_length
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(4, a.alignment_length)
      end
  
      def test_private_alignment_site
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(Alignment::Site[ '-', 't', 't', 't', '-' ],
                     a.instance_eval { _alignment_site(1) })
--- 277,286 ----
  
      def test_alignment_length
!       a = A[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(4, a.alignment_length)
      end
  
      def test_private_alignment_site
!       a = A[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(Alignment::Site[ '-', 't', 't', 't', '-' ],
                     a.instance_eval { _alignment_site(1) })
***************
*** 283,287 ****
  
      def test_alignment_site
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(Alignment::Site[ '-', 't', 't', 't', '-' ],
                     a.__send__(:_alignment_site, 1))
--- 288,292 ----
  
      def test_alignment_site
!       a = A[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(Alignment::Site[ '-', 't', 't', 't', '-' ],
                     a.__send__(:_alignment_site, 1))
***************
*** 295,299 ****
          Alignment::Site[ '-', '-', 'c', '-', '-' ]
        ]
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgc', 'atg', '' ]
        a.each_site do |site|
          assert_equal(expected_results.shift, site)
--- 300,304 ----
          Alignment::Site[ '-', '-', 'c', '-', '-' ]
        ]
!       a = A[ 'a', 'at', 'atgc', 'atg', '' ]
        a.each_site do |site|
          assert_equal(expected_results.shift, site)
***************
*** 307,311 ****
          Alignment::Site[ '-', 'a', 'g', 't', '-' ], # site 3
        ]
!       a = Alignment::SequenceArray[ 'a', 'atgatc', 'atggcc', 'atgtga', '' ]
        a.each_site_step(1, 4, 2) do |site|
          assert_equal(expected_results.shift, site)
--- 312,316 ----
          Alignment::Site[ '-', 'a', 'g', 't', '-' ], # site 3
        ]
!       a = A[ 'a', 'atgatc', 'atggcc', 'atgtga', '' ]
        a.each_site_step(1, 4, 2) do |site|
          assert_equal(expected_results.shift, site)
***************
*** 315,319 ****
  
      def test_alignment_collect
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(Alignment::SequenceArray[ 'a', 'au', 'augc', 'aug', '' ],
                     a.alignment_collect { |x| x.gsub(/t/, 'u') })
--- 320,324 ----
  
      def test_alignment_collect
!       a = A[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(Alignment::SequenceArray[ 'a', 'au', 'augc', 'aug', '' ],
                     a.alignment_collect { |x| x.gsub(/t/, 'u') })
***************
*** 321,325 ****
  
      def test_alignment_window
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgca', 'atg', '' ]
        assert_equal(Alignment::SequenceArray[ '', 't', 'tgc', 'tg', '' ],
                     a.alignment_window(1, 3))
--- 326,330 ----
  
      def test_alignment_window
!       a = A[ 'a', 'at', 'atgca', 'atg', '' ]
        assert_equal(Alignment::SequenceArray[ '', 't', 'tgc', 'tg', '' ],
                     a.alignment_window(1, 3))
***************
*** 333,337 ****
          Alignment::SequenceArray[ 'c', 'a', '' ]      # 7..7
        ]
!       a = Alignment::SequenceArray[ 'atgcatgc', 'tcgatgca', '' ]
        r = a.each_window(3, 2) do |x|
          assert_equal(expected_results.shift, x)
--- 338,342 ----
          Alignment::SequenceArray[ 'c', 'a', '' ]      # 7..7
        ]
!       a = A[ 'atgcatgc', 'tcgatgca', '' ]
        r = a.each_window(3, 2) do |x|
          assert_equal(expected_results.shift, x)
***************
*** 342,346 ****
  
      def test_collect_each_site
!       a = Alignment::SequenceArray[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(["aaaa-", "-ttt-", "--gg-", "--c--" ],
                     a.collect_each_site { |x| x.join('') })
--- 347,351 ----
  
      def test_collect_each_site
!       a = A[ 'a', 'at', 'atgc', 'atg', '' ]
        assert_equal(["aaaa-", "-ttt-", "--gg-", "--c--" ],
                     a.collect_each_site { |x| x.join('') })
***************
*** 353,357 ****
        ]
  
!       a = Alignment::SequenceArray[ 'aa', 'ac', 'ag', 'at', 'a-' ]
        result = a.consensus_each_site do |site|
          assert_equal(expected_results.shift, site)
--- 358,362 ----
        ]
  
!       a = A[ 'aa', 'ac', 'ag', 'at', 'a-' ]
        result = a.consensus_each_site do |site|
          assert_equal(expected_results.shift, site)
***************
*** 367,371 ****
        ]
  
!       a = Alignment::SequenceArray[ 'aa', 'ac', 'ag', 'at', 'a-' ]
        result = a.consensus_each_site(:gap_mode => 1) do |site|
          assert_equal(expected_results.shift, site)
--- 372,376 ----
        ]
  
!       a = A[ 'aa', 'ac', 'ag', 'at', 'a-' ]
        result = a.consensus_each_site(:gap_mode => 1) do |site|
          assert_equal(expected_results.shift, site)
***************
*** 382,386 ****
        ]
  
!       a = Alignment::SequenceArray[ 'aa', 'ac', 'ag', 'at', 'a-' ]
        result = a.consensus_each_site(:gap_mode => -1) do |site|
          assert_equal(expected_results.shift, site)
--- 387,391 ----
        ]
  
!       a = A[ 'aa', 'ac', 'ag', 'at', 'a-' ]
        result = a.consensus_each_site(:gap_mode => -1) do |site|
          assert_equal(expected_results.shift, site)
***************
*** 392,416 ****
  
      def test_consensus_string_default
!       a = Alignment::SequenceArray[ 'ata', 'aac', 'aag', 'aat' ]
        assert_equal('a??', a.consensus_string)
      end
  
      def test_consensus_string_half
!       a = Alignment::SequenceArray[ 'ata', 'aac', 'aag', 'aat' ]
        assert_equal('aa?', a.consensus_string(0.5))
      end
  
      def test_consensus_iupac
!       a = Alignment::SequenceArray[
          'acgtaaaccgaaacaz',
          'acgtaaaccgccggcz',
          'acgtcgtgttgtttgz',
!         'acgtcgtgttaaactz' ]
        assert_equal('acgtmrwsykvhdbn?', a.consensus_iupac)
      end
  
!   end #class TestAlignmentSequenceArray
  
  
  
  
--- 397,568 ----
  
      def test_consensus_string_default
!       a = A[ 'ata', 'aac', 'aag', 'aat' ]
        assert_equal('a??', a.consensus_string)
      end
  
      def test_consensus_string_half
!       a = A[ 'ata', 'aac', 'aag', 'aat' ]
        assert_equal('aa?', a.consensus_string(0.5))
      end
  
      def test_consensus_iupac
!       a = A[
          'acgtaaaccgaaacaz',
          'acgtaaaccgccggcz',
          'acgtcgtgttgtttgz',
!         'acgtcgtgttaaactz'
!       ]
        assert_equal('acgtmrwsykvhdbn?', a.consensus_iupac)
      end
  
!     def test_match_line_amino
!       a = A[
!         'M-SNNNQMMHF-CASSSSSNNFH-AW',
!         'M-TEHDHIIYY-STATTGNDEVF-FW',
!         'M-AQQERLLHW-AVGNPNDEQLY-HW',
!         'M-SKKQKVFYF-CASKADEQHIH-LW',
!         'M-TNNNQMMHY-STASSSQHRMF-QW',
!         'M-AEHDHIIYW-AVGTTGKKKFY-YW'
!         #* ::::::::: ...........  *
!       ]
!       assert_equal('* ::::::::: ...........  *', a.match_line_amino)
!     end
! 
!     def test_match_line_nuc
!       a = A[ 'aaa', 'aa-','aac', 'at-' ]
!       assert_equal('*  ', a.match_line_nuc)
!     end
! 
!     def test_match_line
!       a = A[
!         Sequence::AA.new('MNSA'),
!         Sequence::AA.new('MHTL'),
!         Sequence::AA.new('MQNV'),
!         Sequence::AA.new('MKKW'),
!       ]
!       assert_equal('*:. ', a.match_line)
!       assert_equal('*:. ', a.match_line(:type => :aa))
!       assert_equal('*   ', a.match_line(:type => :na))
!     end
! 
!     def test_convert_match
!       a = A[
!         'aaaa',
!         'accc',
!         'acac',
!         'actc'
!       ]
!       a.convert_match
!       assert_equal(A[ 'aaaa', '.ccc', '.c.c', '.ctc' ], a)
!     end
! 
!     def test_convert_unmatch
!       a = A[ 'aaaa', '.ccc', '.c.c', '.ctc' ]
!       a.convert_unmatch
!       assert_equal(A[ 'aaaa', 'accc', 'acac', 'actc' ], a)
!     end
! 
!     def test_alignment_normalize!
!       a = A[ 'a', 'atg', 'atgc', '' ]
!       a.alignment_normalize!
!       assert_equal(A[ 'a---', 'atg-', 'atgc', '----'], a)
!     end
! 
!     def test_alignment_rstrip!
!       a = A[ '--aaa--', '--t-t--', '---g---', '--t' ]
!       assert(a.alignment_rstrip!)
!       assert_equal(A[ '--aaa', '--t-t', '---g-', '--t' ], a)
!     end
! 
!     def test_alignment_rstrip_nil
!       a = A[ 'aa', '-a', 'a-' ]
!       assert_nil(a.alignment_rstrip!)
!       assert_equal(A[ 'aa', '-a', 'a-' ], a)
!     end
! 
!     def test_alignment_lstrip!
!       a = A[ '--aaa--', '--t-t--', '---g---', '--t' ]
!       assert(a.alignment_lstrip!)
!       assert_equal(A[ 'aaa--', 't-t--', '-g---', 't' ], a)
!     end
! 
!     def test_alignment_lstrip_nil
!       a = A[ 'aa', '-a', 'a-' ]
!       assert_nil(a.alignment_lstrip!)
!       assert_equal(A[ 'aa', '-a', 'a-' ], a)
!     end
! 
!     def test_alignment_strip!
!       a = A[ '--aaa--', '--t-t--', '---g---', '--t' ]
!       assert(a.alignment_strip!)
!       assert_equal(A[ 'aaa', 't-t', '-g-', 't' ], a)
!     end
! 
!     def test_alignment_strip_nil
!       a = A[ 'aa', '-a', 'a-' ]
!       assert_nil(a.alignment_strip!)
!       assert_equal(A[ 'aa', '-a', 'a-' ], a)
!     end
! 
!     def test_remove_all_gaps!
!       a = A[ '--aaa--', '--t-t--', '---g---', '--t' ]
!       assert(a.remove_all_gaps!)
!       assert_equal(A[ 'aaa', 'tt', 'g', 't' ], a)
!     end
! 
!     # test of alignment_slice.
!     # Please also refer alignment_window.
!     def test_alignment_slice
!       a = A[ 'a', 'at', 'atgca', 'atg', '' ]
!       assert_equal(Alignment::SequenceArray[ '', 't', 'tgc', 'tg', nil ],
!                    a.alignment_slice(1, 3))
!     end
  
+     def test_alignment_subseq
+       a = A[ Sequence.new('a'), Sequence.new('at'), Sequence.new('atgca'),
+         Sequence.new('atg'), Sequence.new('') ]
+       assert_equal(Alignment::SequenceArray[ Sequence.new(''),
+                      Sequence.new('t'), Sequence.new('tgc'),
+                      Sequence.new('tg'), nil ],
+                    a.alignment_subseq(2,4))
+     end
  
+     def test_alignment_concat
+       a = A[ 'aaa',  'c', 'gg', 't' ]
+       a.alignment_concat(A[ 'ttt', 'gg', 'aa', 'cc', 'aa' ])
+       assert_equal(A[ 'aaattt', 'cgg', 'ggaa', 'tcc' ], a)
+       a.alignment_concat([ 'c', 't' ])
+       assert_equal(A[ 'aaatttc', 'cggt', 'ggaa', 'tcc' ], a)
+     end
+   end #class TestAlignmentEnumerableExtension
+ 
+   class TestAlignmentClustalWFormatter < Test::Unit::TestCase
+     def setup
+       @obj = Object.new
+       @obj.extend(Alignment::ClustalWFormatter)
+     end
+ 
+     def test_have_same_name_true
+       assert_equal([ 0, 1 ], @obj.instance_eval {
+                      have_same_name?([ 'ATP ATG', 'ATP ATA', 'BBB' ]) })
+     end
+ 
+     def test_have_same_name_false
+       assert_equal(false, @obj.instance_eval {
+                have_same_name?([ 'GTP ATG', 'ATP ATA', 'BBB' ]) })
+     end
+ 
+     def test_avoid_same_name
+       assert_equal([ 'ATP_ATG', 'ATP_ATA', 'BBB' ],
+                    @obj.instance_eval {
+                      avoid_same_name([ 'ATP ATG', 'ATP ATA', 'BBB' ]) })
+     end
+     def test_avoid_same_name_numbering
+       assert_equal([ '0_ATP', '1_ATP', '2_BBB' ],
+                    @obj.instance_eval {
+                      avoid_same_name([ 'ATP', 'ATP', 'BBB' ]) })
+     end
+ 
+   end #class TestAlignmentClustalWFormatter
  
  



More information about the bioruby-cvs mailing list