[BioRuby-cvs] bioruby/lib/bio alignment.rb,1.19,1.20

Naohisa Goto ngoto at dev.open-bio.org
Thu Dec 14 15:09:01 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv13570/lib/bio

Modified Files:
	alignment.rb 
Log Message:
EnumerableExtension#number_of_sequences are added and some 
methods are modifed to use it.


Index: alignment.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/alignment.rb,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** alignment.rb	14 Dec 2006 14:11:54 -0000	1.19
--- alignment.rb	14 Dec 2006 15:08:59 -0000	1.20
***************
*** 989,993 ****
          mline = (options[:match_line] or seqs.match_line(mopt))
          
!         aseqs = Array.new(seqs.size).clear
          seqs.each_seq do |s|
            aseqs << s.to_s.gsub(seqs.gap_regexp, gchar)
--- 989,993 ----
          mline = (options[:match_line] or seqs.match_line(mopt))
          
!         aseqs = Array.new(seqs.number_of_sequences).clear
          seqs.each_seq do |s|
            aseqs << s.to_s.gsub(seqs.gap_regexp, gchar)
***************
*** 1087,1091 ****
        def __output_phylip_common(options = {})
          len = self.alignment_length
!         aln = [ " #{self.size} #{len}\n" ]
          sn = self.sequence_names.collect { |x| x.to_s.gsub(/[\r\n\x00]/, ' ') }
          if options[:replace_space]
--- 1087,1091 ----
        def __output_phylip_common(options = {})
          len = self.alignment_length
!         aln = [ " #{self.number_of_sequences} #{len}\n" ]
          sn = self.sequence_names.collect { |x| x.to_s.gsub(/[\r\n\x00]/, ' ') }
          if options[:replace_space]
***************
*** 1108,1112 ****
          gchar = (options[:gap_char] or '-')
  
!         aseqs = Array.new(len).clear
          self.each_seq do |s|
            aseqs << s.to_s.gsub(self.gap_regexp, gchar)
--- 1108,1112 ----
          gchar = (options[:gap_char] or '-')
  
!         aseqs = Array.new(self.number_of_sequences).clear
          self.each_seq do |s|
            aseqs << s.to_s.gsub(self.gap_regexp, gchar)
***************
*** 1139,1143 ****
        def output_molphy(options = {})
          len = self.alignment_length
!         header = "#{self.size} #{len}\n"
          sn = self.sequence_names.collect { |x| x.to_s.gsub(/[\r\n\x00]/, ' ') }
          if options[:replace_space]
--- 1139,1143 ----
        def output_molphy(options = {})
          len = self.alignment_length
!         header = "#{self.number_of_sequences} #{len}\n"
          sn = self.sequence_names.collect { |x| x.to_s.gsub(/[\r\n\x00]/, ' ') }
          if options[:replace_space]
***************
*** 1182,1192 ****
        include Output
  
        # Returns an array of sequence names.
        # The order of the names must be the same as
        # the order of <tt>each_seq</tt>.
        def sequence_names
!         i = 0
!         self.each_seq { |s| i += 1 }
!         (0...i).to_a
        end
      end #module EnumerableExtension
--- 1182,1197 ----
        include Output
  
+       # Returns number of sequences in this alignment.
+       def number_of_sequences
+         i = 0
+         self.each_seq { |s| i += 1 }
+         i
+       end
+ 
        # Returns an array of sequence names.
        # The order of the names must be the same as
        # the order of <tt>each_seq</tt>.
        def sequence_names
!         (0...(self.number_of_sequences)).to_a
        end
      end #module EnumerableExtension
***************
*** 1210,1213 ****
--- 1215,1223 ----
          each(&block)
        end
+ 
+       # Returns number of sequences in this alignment.
+       def number_of_sequences
+         self.size
+       end
      end #module ArrayExtension
  
***************
*** 1300,1303 ****
--- 1310,1318 ----
        end
  
+       # Returns number of sequences in this alignment.
+       def number_of_sequences
+         self.size
+       end
+ 
        # Returns an array of sequence names.
        # The order of the names must be the same as
***************
*** 1579,1582 ****
--- 1594,1598 ----
          @seqs.size
        end
+       alias number_of_sequences size
  
        # If the key exists, returns true. Otherwise, returns false.




More information about the bioruby-cvs mailing list