[BioRuby-cvs] bioruby/lib/bio/appl clustalw.rb, 1.18, 1.19 mafft.rb, 1.17, 1.18

Naohisa Goto ngoto at dev.open-bio.org
Mon Jul 16 12:27:31 UTC 2007


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

Modified Files:
	clustalw.rb mafft.rb 
Log Message:
Interfaces of Bio::ClustalW and Bio::MAFFT are added/modified
to follow Bio::Alignment::FactoryTemplate (but not yet changed to use it).


Index: clustalw.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/clustalw.rb,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** clustalw.rb	5 Apr 2007 23:35:39 -0000	1.18
--- clustalw.rb	16 Jul 2007 12:27:29 -0000	1.19
***************
*** 8,12 ****
  #
  # Bio::ClustalW is a CLUSTAL W execution wrapper class.
! # Its object is also called an alignment factory.
  # CLUSTAL W is a very popular software for multiple sequence alignment.
  #
--- 8,12 ----
  #
  # Bio::ClustalW is a CLUSTAL W execution wrapper class.
! # It can also be called as an alignment factory.
  # CLUSTAL W is a very popular software for multiple sequence alignment.
  #
***************
*** 45,49 ****
        @output = nil
        @report = nil
!       @log = nil
      end
  
--- 45,51 ----
        @output = nil
        @report = nil
!       @data_stdout = nil
!       @exit_status = nil
!       @output_dnd = nil
      end
  
***************
*** 56,60 ****
      # option is deprecated. Instead, please use options.
      def option
!       warn "option is deprecated. Please use options."
        options
      end
--- 58,62 ----
      # option is deprecated. Instead, please use options.
      def option
!       warn "Bio::ClustalW#option is deprecated. Please use options."
        options
      end
***************
*** 66,73 ****
      attr_reader :command
  
      # Returns last messages of CLUSTAL W execution.
!     attr_reader :log
  
!     # Returns last raw alignment result (String).
      attr_reader :output
  
--- 68,80 ----
      attr_reader :command
  
+     # This method will be deprecated.
+     #
      # Returns last messages of CLUSTAL W execution.
!     def log
!       #warn 'Bio::ClustalW#log will be deprecated.'
!       @data_stdout
!     end
  
!     # Returns last raw alignment result (String or nil).
      attr_reader :output
  
***************
*** 76,82 ****
--- 83,109 ----
      attr_reader :report
  
+     # Last exit status
+     attr_reader :exit_status
+ 
+     # Last output to the stdout.
+     attr_accessor :data_stdout
+     
+     # Clear the internal data and status, except program and options.
+     def reset
+       @command = nil
+       @output = nil
+       @report = nil
+       @exit_status = nil
+       @data_stdout = nil
+       @output_dnd = nil
+     end
+ 
      # Executes the program(clustalw).
      # If +seqs+ is not nil, perform alignment for seqs.
      # If +seqs+ is nil, simply executes CLUSTAL W.
+     #
+     # Compatibility note: When seqs is nil,
+     # returns true if the program exits normally, and
+     # returns false if the program exits abnormally.
      def query(seqs)
        if seqs then
***************
*** 84,112 ****
        else
          exec_local(@options)
        end
      end
  
      # Performs alignment for +seqs+.
      # +seqs+ should be Bio::Alignment or Array of sequences or nil.
      def query_align(seqs)
-       seqtype = nil
        unless seqs.is_a?(Bio::Alignment)
          seqs = Bio::Alignment.new(seqs)
        end
-       seqs.each do |s|
-         if    s.is_a?(Bio::Sequence::AA) then
-           seqtype = 'PROTEIN'
-         elsif s.is_a?(Bio::Sequence::NA) then
-           seqtype = 'DNA'
-         end
-         break if seqtype
-       end
        query_string(seqs.output_fasta(:width => 70,
!                                      :avoid_same_name => true), seqtype)
      end
  
      # Performs alignment for +str+.
      # +str+ should be a string that can be recognized by CLUSTAL W.
      def query_string(str, *arg)
        begin
          tf_in = Tempfile.open('align')
--- 111,146 ----
        else
          exec_local(@options)
+         @exit_status.exitstatus == 0 ? true : false
        end
      end
  
+     # Note that this method will be renamed to query_alignment.
+     #
      # Performs alignment for +seqs+.
      # +seqs+ should be Bio::Alignment or Array of sequences or nil.
+     #
+     # Compatibility Note: Nucleic or amino is not determined by this method.
      def query_align(seqs)
        unless seqs.is_a?(Bio::Alignment)
          seqs = Bio::Alignment.new(seqs)
        end
        query_string(seqs.output_fasta(:width => 70,
!                                      :avoid_same_name => true))
!     end
! 
!     # Performs alignment for +seqs+.
!     # +seqs+ should be Bio::Alignment or Array of sequences or nil.
!     def query_alignment(seqs)
!       query_align(seqs)
      end
  
      # Performs alignment for +str+.
      # +str+ should be a string that can be recognized by CLUSTAL W.
+     #
+     # Compatibility Note: 2nd argument is deprecated and ignored.
      def query_string(str, *arg)
+       if arg.size > 0 then
+         warn '2nd argument of Bio::ClustalW#query_string is ignored'
+       end
        begin
          tf_in = Tempfile.open('align')
***************
*** 115,119 ****
          tf_in.close(false)
        end
!       r = query_by_filename(tf_in.path, *arg)
        tf_in.close(true)
        r
--- 149,153 ----
          tf_in.close(false)
        end
!       r = query_by_filename(tf_in.path)
        tf_in.close(true)
        r
***************
*** 121,126 ****
  
      # Performs alignment of sequences in the file named +path+.
!     def query_by_filename(path, seqtype = nil)
!       require 'bio/appl/clustalw/report'
  
        tf_out = Tempfile.open('clustalout')
--- 155,164 ----
  
      # Performs alignment of sequences in the file named +path+.
!     #
!     # Compatibility Note: 2nd argument (seqtype) is deprecated and ignored.
!     def query_by_filename(path, *arg)
!       if arg.size > 0 then
!         warn '2nd argument of Bio::ClustalW#query_by_filename is ignored'
!       end
  
        tf_out = Tempfile.open('clustalout')
***************
*** 135,139 ****
          "-outorder=input"
        ]
!       opt << "-type=#{seqtype}" if seqtype
        opt.concat(@options)
        exec_local(opt)
--- 173,177 ----
          "-outorder=input"
        ]
!       #opt << "-type=#{seqtype}" if seqtype
        opt.concat(@options)
        exec_local(opt)
***************
*** 144,148 ****
        @output_dnd = tf_dnd.read
        tf_dnd.close(true)
!       @report = Report.new(@output, seqtype)
        @report
      end
--- 182,186 ----
        @output_dnd = tf_dnd.read
        tf_dnd.close(true)
!       @report = Report.new(@output)
        @report
      end
***************
*** 166,176 ****
        @command = [ @program,  *opt ]
        #STDERR.print "DEBUG: ", @command.join(" "), "\n"
!       @log = nil
  
        Bio::Command.call_command(@command) do |io|
          io.close_write
!         @log = io.read
        end
!       @log
      end
  
--- 204,215 ----
        @command = [ @program,  *opt ]
        #STDERR.print "DEBUG: ", @command.join(" "), "\n"
!       @data_stdout = nil
!       @exit_status = nil
  
        Bio::Command.call_command(@command) do |io|
          io.close_write
!         @data_stdout = io.read
        end
!       @exit_status = $?
      end
  

Index: mafft.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/mafft.rb,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** mafft.rb	5 Apr 2007 23:35:39 -0000	1.17
--- mafft.rb	16 Jul 2007 12:27:29 -0000	1.18
***************
*** 106,110 ****
      # +program+ is the name of the program.
      # +opt+ is options of the program.
!     def initialize(program, opt)
        @program = program
        @options = opt
--- 106,110 ----
      # +program+ is the name of the program.
      # +opt+ is options of the program.
!     def initialize(program = 'mafft', opt = [])
        @program = program
        @options = opt
***************
*** 112,118 ****
        @output = nil
        @report = nil
      end
  
!     # program name
      attr_accessor :program
  
--- 112,120 ----
        @output = nil
        @report = nil
+       @data_stdout = nil
+       @exit_status = nil
      end
  
!     # program name (usually 'mafft' in UNIX)
      attr_accessor :program
  
***************
*** 122,126 ****
      # option is deprecated. Instead, please use options.
      def option
!       warn "option is deprecated. Please use options."
        options
      end
--- 124,128 ----
      # option is deprecated. Instead, please use options.
      def option
!       warn "Bio::MAFFT#option is deprecated. Please use options."
        options
      end
***************
*** 138,142 ****
      #log is deprecated (no replacement) and returns empty string.
      def log
!       warn "log is deprecated (no replacement) and returns empty string."
        ''
      end
--- 140,144 ----
      #log is deprecated (no replacement) and returns empty string.
      def log
!       warn "Bio::MAFFT#log is deprecated (no replacement) and returns empty string."
        ''
      end
***************
*** 153,159 ****
--- 155,180 ----
      attr_reader :report
  
+     # Last exit status
+     attr_reader :exit_status
+ 
+     # Last output to the stdout.
+     attr_accessor :data_stdout
+     
+     # Clear the internal data and status, except program and options.
+     def reset
+       @command = nil
+       @output = nil
+       @report = nil
+       @exit_status = nil
+       @data_stdout = nil
+     end
+ 
      # Executes the program.
      # If +seqs+ is not nil, perform alignment for seqs.
      # If +seqs+ is nil, simply executes the program.
+     #
+     # Compatibility note: When seqs is nil,
+     # returns true if the program exits normally, and
+     # returns false if the program exits abnormally.
      def query(seqs)
        if seqs then
***************
*** 161,179 ****
        else
          exec_local(@options)
        end
      end
  
      # Performs alignment for seqs.
      # +seqs+ should be Bio::Alignment or Array of sequences or nil.
      def query_align(seqs, *arg)
        unless seqs.is_a?(Bio::Alignment)
!         seqs = Bio::Alignment.new(seqs, *arg)
        end
        query_string(seqs.output_fasta(:width => 70))
      end
  
      # Performs alignment for +str+.
      # Str should be a string that can be recognized by the program.
      def query_string(str, *arg)
        begin
          tf_in = Tempfile.open('align')
--- 182,219 ----
        else
          exec_local(@options)
+         @exit_status.exitstatus == 0 ? true : false
        end
      end
  
+     # Note that this method will be renamed to query_alignment.
+     #
      # Performs alignment for seqs.
      # +seqs+ should be Bio::Alignment or Array of sequences or nil.
+     #
+     # Compatibility Note: arg is deprecated and ignored.
      def query_align(seqs, *arg)
+       if arg.size > 0 then
+         warn '2nd and other arguments of Bio::MAFFT#query_align is ignored'
+       end
        unless seqs.is_a?(Bio::Alignment)
!         seqs = Bio::Alignment.new(seqs)
        end
        query_string(seqs.output_fasta(:width => 70))
      end
  
+     # Performs alignment for seqs.
+     # +seqs+ should be Bio::Alignment or Array of sequences or nil.
+     def query_alignment(seqs)
+       query_align(seqs)
+     end
+ 
      # Performs alignment for +str+.
      # Str should be a string that can be recognized by the program.
+     #
+     # Compatibility Note: arg is deprecated and ignored.
      def query_string(str, *arg)
+       if arg.size > 0 then
+         warn '2nd and other arguments of Bio::MAFFT#query_string is ignored'
+       end
        begin
          tf_in = Tempfile.open('align')
***************
*** 188,195 ****
  
      # Performs alignment of sequences in the file named +fn+.
!     def query_by_filename(fn, seqtype = nil)
        opt = @options + [ fn ]
        exec_local(opt)
!       @report = Report.new(@output, seqtype)
        @report
      end
--- 228,240 ----
  
      # Performs alignment of sequences in the file named +fn+.
!     #
!     # Compatibility Note: 2nd argument (seqtype) is deprecated and ignored.
!     def query_by_filename(fn, *arg)
!       if arg.size > 0 then
!         warn '2nd argument of Bio::MAFFT#query_filename is ignored'
!       end
        opt = @options + [ fn ]
        exec_local(opt)
!       @report = Report.new(@output)
        @report
      end
***************
*** 200,208 ****
        @command = [ @program, *opt ]
        #STDERR.print "DEBUG: ", @command.join(" "), "\n"
!       @output = nil
        Bio::Command.call_command(@command) do |io|
          io.close_write
!         @output = io.read
        end
      end
  
--- 245,256 ----
        @command = [ @program, *opt ]
        #STDERR.print "DEBUG: ", @command.join(" "), "\n"
!       @data_stdout = nil
!       @exit_status = nil
        Bio::Command.call_command(@command) do |io|
          io.close_write
!         @data_stdout = io.read
        end
+       @output = @data_stdout
+       @exit_status = $?
      end
  




More information about the bioruby-cvs mailing list