[BioRuby-cvs] bioruby/lib/bio/appl blast.rb, 1.20, 1.21 fasta.rb,
1.16, 1.17 hmmer.rb, 1.1, 1.2
Naohisa Goto
ngoto at pub.open-bio.org
Tue Aug 16 06:26:03 EDT 2005
Update of /home/repository/bioruby/bioruby/lib/bio/appl
In directory pub.open-bio.org:/tmp/cvs-serv9033/lib/bio/appl
Modified Files:
blast.rb fasta.rb hmmer.rb
Log Message:
* lib/bio/command.rb
Newly added Bio::Command::Tools module.
Bio::Command::Tools is a collection of useful methods
for execution of external commands.
* lib/bio/appl/blast.rb, lib/bio/appl/fasta.rb,
lib/bio/appl/hmmer.rb, lib/bio/io/fastacmd.rb
For security reason, shell special characters are escaped.
* lib/bio/appl/blast.rb, lib/bio/appl/fasta.rb, lib/bio/appl/hmmer.rb
Options are stored with an array (@options).
#options and #opions= methods are added.
* lib/bio/appl/blast.rb, lib/bio/appl/fasta.rb
Bio::Blast.remote and Bio::Fasta.remote did not work
due to the change of the GenomeNet.
Index: blast.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blast.rb,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** blast.rb 23 Aug 2004 23:48:02 -0000 1.20
--- blast.rb 16 Aug 2005 09:38:34 -0000 1.21
***************
*** 25,28 ****
--- 25,30 ----
require 'cgi' unless defined?(CGI)
require 'bio/appl/blast/report'
+ require 'bio/command'
+ require 'shellwords'
module Bio
***************
*** 30,34 ****
class Blast
! def initialize(program, db, option = '', server = 'local')
if defined?(XMLParser) or defined?(REXML)
@format = 7
--- 32,38 ----
class Blast
! include Bio::Command::Tools
!
! def initialize(program, db, opt = [], server = 'local')
if defined?(XMLParser) or defined?(REXML)
@format = 7
***************
*** 39,43 ****
@program = program
@db = db
- @option = "-m #{@format} #{option}"
@server = server
--- 43,46 ----
***************
*** 48,53 ****
@output = ''
@parser = nil
end
! attr_accessor :program, :db, :option, :server, :blastall, :matrix, :filter
attr_reader :output, :format
attr_writer :parser # to change :xmlparser, :rexml, :tab
--- 51,64 ----
@output = ''
@parser = nil
+
+ begin
+ a = opt.to_ary
+ rescue NameError #NoMethodError
+ # backward compatibility
+ a = Shellwords.shellwords(opt)
+ end
+ @options = [ "-m", @format, *a ]
end
! attr_accessor :program, :db, :options, :server, :blastall, :matrix, :filter
attr_reader :output, :format
attr_writer :parser # to change :xmlparser, :rexml, :tab
***************
*** 65,68 ****
--- 76,89 ----
end
+ def option
+ # backward compatibility
+ make_command_line(@options)
+ end
+
+ def option=(str)
+ # backward compatibility
+ @options = Shellwords.shellwords(str)
+ end
+
private
***************
*** 75,96 ****
def exec_local(query)
! cmd = "#{@blastall} -p #{@program} -d #{@db} #{@option}"
! cmd += " -M #{@matrix}" if @matrix
! cmd += " -F #{@filter}" if @filter
report = nil
! begin
! io = IO.popen(cmd, "w+")
! io.sync = true
! io.puts(query)
! io.close_write
! @output = io.read
! report = parse_result(@output)
! rescue
! raise "[Error] command execution failed : #{cmd}"
! ensure
! io.close
! end
return report
--- 96,107 ----
def exec_local(query)
! cmd = [ @blastall, '-p', @program, '-d', @db, *@options ]
! cmd.concat([ '-M', @matrix ]) if @matrix
! cmd.concat([ '-F', @filter ]) if @filter
report = nil
! @output = call_command_local(cmd, query)
! report = parse_result(@output)
return report
***************
*** 100,104 ****
def exec_genomenet(query)
host = "blast.genome.jp"
! path = "/sit-bin/nph-blast"
matrix = @matrix ? @matrix : 'blosum62'
--- 111,116 ----
def exec_genomenet(query)
host = "blast.genome.jp"
! #path = "/sit-bin/nph-blast"
! path = "/sit-bin/blast" #2005.08.12
matrix = @matrix ? @matrix : 'blosum62'
***************
*** 110,114 ****
'dbname' => @db,
'sequence' => CGI.escape(query),
! 'other_param' => CGI.escape(@option),
'matrix' => matrix,
'filter' => filter,
--- 122,126 ----
'dbname' => @db,
'sequence' => CGI.escape(query),
! 'other_param' => CGI.escape(make_command_line_unix(@options)),
'matrix' => matrix,
'filter' => filter,
***************
*** 127,133 ****
begin
! result, = Net::HTTP.new(host).post(path, data.join('&'))
! @output = result.body
! report = parse_result(@output)
end
--- 139,160 ----
begin
! http = Net::HTTP.new(host)
! http.open_timeout = 300
! http.read_timeout = 600
! result, = http.post(path, data.join('&'))
! @output = result.body
! # workaround 2005.08.12
! if /\<A +HREF=\"(http\:\/\/blast\.genome\.jp(\/tmp\/[^\"]+))\"\>Show all result\<\/A\>/i =~ @output.to_s then
! result, = http.get($2)
! @output = result.body
! txt = @output.to_s.split(/\<pre\>/)[1]
! raise 'cannot understand response' unless txt
! txt.sub!(/\<\/pre\>.*\z/m, '')
! txt.sub!(/.*^ \-{20,}\s*/m, '')
! @output = txt.gsub(/\<\;/, '<')
! report = parse_result(@output)
! else
! raise 'cannot understand response'
! end
end
***************
*** 183,187 ****
--- Bio::Blast#program
--- Bio::Blast#db
! --- Bio::Blast#option
--- Bio::Blast#server
--- Bio::Blast#blastall
--- 210,214 ----
--- Bio::Blast#program
--- Bio::Blast#db
! --- Bio::Blast#options
--- Bio::Blast#server
--- Bio::Blast#blastall
***************
*** 189,192 ****
--- 216,224 ----
Accessors for the factory parameters.
+
+ --- Bio::Blast#option
+ --- Bio::Blast#option=(str)
+
+ Get/set options by string.
== Available databases for Blast.remote(@program, @db, option, 'genomenet')
Index: fasta.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/fasta.rb,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** fasta.rb 25 Aug 2004 06:29:10 -0000 1.16
--- fasta.rb 16 Aug 2005 09:38:34 -0000 1.17
***************
*** 23,26 ****
--- 23,28 ----
require 'net/http'
require 'cgi' unless defined?(CGI)
+ require 'bio/command'
+ require 'shellwords'
module Bio
***************
*** 28,37 ****
class Fasta
! def initialize(program, db, option = '', server = 'local')
@format = 10
@program = program
@db = db
- @option = "-Q -H -m #{@format} #{option}" # need -a ?
@server = server
--- 30,40 ----
class Fasta
! include Bio::Command::Tools
!
! def initialize(program, db, opt = [], server = 'local')
@format = 10
@program = program
@db = db
@server = server
***************
*** 40,51 ****
@output = ''
end
! attr_accessor :program, :db, :option, :server, :ktup, :matrix
attr_reader :output
def format=(num)
@format = num.to_i
! @option.gsub!(/\s*-m\s+\d+/, '')
! @option += " -m #{num} "
end
attr_reader :format
--- 43,75 ----
@output = ''
+
+ begin
+ a = opt.to_ary
+ rescue NameError #NoMethodError
+ # backward compatibility
+ a = Shellwords.shellwords(opt)
+ end
+ @options = [ '-Q', '-H', '-m', @format.to_s, *a ] # need -a ?
end
! attr_accessor :program, :db, :options, :server, :ktup, :matrix
attr_reader :output
+ def option
+ # backward compatibility
+ make_command_line(@options)
+ end
+
+ def option=(str)
+ # backward compatibility
+ @options = Shellwords.shellwords(str)
+ end
+
def format=(num)
@format = num.to_i
! if i = @options.index('-m') then
! @options[i+1, 1] = @format.to_s
! else
! @options << '-m' << @format.to_s
! end
end
attr_reader :format
***************
*** 83,102 ****
def exec_local(query)
! cmd = "#{@program} #{@option} @ #{@db} #{@ktup}"
report = nil
! begin
! io = IO.popen(cmd, "w+")
! io.sync = true
! io.puts(query)
! io.close_write
! @output = io.read
! report = parse_result(@output)
! rescue
! raise "[Error] command execution failed : #{cmd}"
! ensure
! io.close
! end
return report
--- 107,117 ----
def exec_local(query)
! cmd = [ @program, *@options ]
! cmd.concat([ '@', @db, @ktup ])
report = nil
! @output = call_command_local(cmd, query)
! report = parse_result(@output)
return report
***************
*** 106,110 ****
def exec_genomenet(query)
host = "fasta.genome.jp"
! path = "/sit-bin/nph-fasta"
form = {
--- 121,126 ----
def exec_genomenet(query)
host = "fasta.genome.jp"
! #path = "/sit-bin/nph-fasta"
! path = "/sit-bin/fasta" #2005.08.12
form = {
***************
*** 113,117 ****
'dbname' => @db,
'sequence' => CGI.escape(query),
! 'other_param' => CGI.escape(@option),
'ktup_value' => @ktup,
'matrix' => @matrix,
--- 129,133 ----
'dbname' => @db,
'sequence' => CGI.escape(query),
! 'other_param' => CGI.escape(make_command_line_unix(@options)),
'ktup_value' => @ktup,
'matrix' => @matrix,
***************
*** 127,133 ****
begin
! result, = Net::HTTP.new(host).post(path, data.join('&'))
! @output = result.body
! report = parse_result(@output)
end
--- 143,168 ----
begin
! http = Net::HTTP.new(host)
! http.open_timeout = 300
! http.read_timeout = 600
! result, = http.post(path, data.join('&'))
! @output = result.body
! # workaround 2005.08.12
! if /\<A +HREF=\"(http\:\/\/fasta\.genome\.jp(\/tmp\/[^\"]+))\"\>Show all result\<\/A\>/i =~ @output.to_s then
! result, = http.get($2)
! @output = result.body
! txt = @output.to_s.split(/\<pre\>/)[1]
! raise 'cannot understand response' unless txt
! txt.sub!(/\<\/pre\>.*\z/m, '')
! txt.sub!(/.*^((T?FASTA|SSEARCH) (searches|compares))/m, '\1')
! txt.sub!(/^\<form method\=\"POST\" name\=\"clust_check\"\>.*\n/, '')
! txt.gsub!(/\<input[^\>]+value\=\"[^\"]*\"[^\>]*\>/i, '')
! txt.gsub!(/\<(a|form|select|input|option|img)\s+[^\>]+\>/i, '')
! txt.gsub!(/\<\/(a|form|select|input|option|img)\>/i, '')
! @output = txt.gsub(/\<\;/, '<')
! report = parse_result(@output.dup)
! else
! raise 'cannot understand response'
! end
end
***************
*** 178,186 ****
--- Bio::Fasta#program
--- Bio::Fasta#db
! --- Bio::Fasta#option
--- Bio::Fasta#server
--- Bio::Fasta#ktup
Accessors for the factory parameters.
--- Bio::Fasta#format
--- 213,226 ----
--- Bio::Fasta#program
--- Bio::Fasta#db
! --- Bio::Fasta#options
--- Bio::Fasta#server
--- Bio::Fasta#ktup
Accessors for the factory parameters.
+
+ --- Bio::Fasta#option
+ --- Bio::Fasta#option=(str)
+
+ Get/set options by string.
--- Bio::Fasta#format
Index: hmmer.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/hmmer.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** hmmer.rb 22 Nov 2002 23:17:55 -0000 1.1
--- hmmer.rb 16 Aug 2005 09:38:34 -0000 1.2
***************
*** 22,25 ****
--- 22,27 ----
require 'bio/appl/hmmer/report'
+ require 'bio/command'
+ require 'shellwords'
module Bio
***************
*** 27,55 ****
class HMMER
! def initialize(program, hmmfile, seqfile, option = '')
@program = program
@hmmfile = hmmfile
@seqfile = seqfile
- @option = option
@output = ''
end
! attr_accessor :program, :hmmfile, :seqfile, :option
attr_reader :output
def query
! cmd = "#{@program} #{@option} #{@hmmfile} #{@seqfile}"
report = nil
! begin
! io = IO.popen(cmd, 'r')
! io.sync = true
! @output = io.read
! report = parse_result(@output)
! rescue
! raise "[Error] command execution failed : #{cmd}"
! ensure
! io.close
! end
return report
--- 29,68 ----
class HMMER
! include Bio::Command::Tools
!
! def initialize(program, hmmfile, seqfile, opt = [])
@program = program
@hmmfile = hmmfile
@seqfile = seqfile
@output = ''
+
+ begin
+ @options = opt.to_ary
+ rescue NameError #NoMethodError
+ # backward compatibility
+ @options = Shellwords.shellwords(opt)
+ end
end
! attr_accessor :program, :hmmfile, :seqfile, :options
attr_reader :output
+ def option
+ # backward compatibility
+ make_command_line(@options)
+ end
+
+ def option=(str)
+ # backward compatibility
+ @options = Shellwords.shellwords(str)
+ end
+
def query
! cmd = [ @program, *@options ]
! cmd.concat([ @hmmfile, @seqfile ])
report = nil
! @output = call_command_local(cmd, nil)
! report = parse_result(@output)
return report
***************
*** 94,100 ****
--- Bio::HMMER#hmmfile
--- Bio::HMMER#seqfile
! --- Bio::HMMER#option
Accessors for the factory.
--- Bio::HMMER#query
--- 107,118 ----
--- Bio::HMMER#hmmfile
--- Bio::HMMER#seqfile
! --- Bio::HMMER#options
Accessors for the factory.
+
+ --- Bio::HMMER#option
+ --- Bio::HMMER#option=(str)
+
+ Get/set options by string.
--- Bio::HMMER#query
More information about the bioruby-cvs
mailing list