[BioRuby-cvs] bioruby/lib/bio/appl fasta.rb,1.22,1.23
Katayama Toshiaki
k at dev.open-bio.org
Tue Sep 19 06:28:58 UTC 2006
Update of /home/repository/bioruby/bioruby/lib/bio/appl
In directory dev.open-bio.org:/tmp/cvs-serv730/lib/bio/appl
Modified Files:
fasta.rb
Log Message:
* license is changed from LGPL to Ruby's
* document is changed to RDoc
Index: fasta.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/fasta.rb,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** fasta.rb 25 Jul 2006 18:48:41 -0000 1.22
--- fasta.rb 19 Sep 2006 06:28:56 -0000 1.23
***************
*** 1,22 ****
#
! # bio/appl/fasta.rb - FASTA wrapper
! #
! # Copyright (C) 2001,2002 KATAYAMA Toshiaki <k at bioruby.org>
! #
! # This library is free software; you can redistribute it and/or
! # modify it under the terms of the GNU Lesser General Public
! # License as published by the Free Software Foundation; either
! # version 2 of the License, or (at your option) any later version.
! #
! # This library is distributed in the hope that it will be useful,
! # but WITHOUT ANY WARRANTY; without even the implied warranty of
! # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! # Lesser General Public License for more details.
#
! # You should have received a copy of the GNU Lesser General Public
! # License along with this library; if not, write to the Free Software
! # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
! # $Id$
#
--- 1,9 ----
#
! # = bio/appl/fasta.rb - FASTA wrapper
#
! # Copyright:: Copyright (C) 2001, 2002 Toshiaki Katayama <k at bioruby.org>
! # License:: Ruby's
#
! # $Id$
#
***************
*** 28,177 ****
module Bio
! class Fasta
!
! autoload :Report, 'bio/appl/fasta/format10'
! #autoload :?????, 'bio/appl/fasta/format6'
! def initialize(program, db, opt = [], server = 'local')
! @format = 10
! @program = program
! @db = db
! @server = server
! @ktup = nil
! @matrix = nil
! @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
! Bio::Command.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
! def self.parser(parser)
! require "bio/appl/fasta/#{parser}"
! end
! def self.local(program, db, option = '')
! self.new(program, db, option, 'local')
end
! def self.remote(program, db, option = '', server = 'genomenet')
! self.new(program, db, option, server)
! end
! def query(query)
! return self.send("exec_#{@server}", query.to_s)
! end
! private
! def parse_result(data)
! case @format
! when 6
! require 'bio/appl/fasta/format6'
! when 10
! require 'bio/appl/fasta/format10'
! end
! Report.new(data)
end
! def exec_local(query)
! cmd = [ @program, *@options ]
! cmd.concat([ '@', @db, @ktup ])
! report = nil
! @output = Bio::Command.query_command(cmd, query)
! report = parse_result(@output)
! return report
! end
! def exec_genomenet(query)
! host = "fasta.genome.jp"
! #path = "/sit-bin/nph-fasta"
! path = "/sit-bin/fasta" #2005.08.12
! form = {
! 'style' => 'raw',
! 'prog' => @program,
! 'dbname' => @db,
! 'sequence' => CGI.escape(query),
! 'other_param' => CGI.escape(Bio::Command.make_command_line_unix(@options)),
! 'ktup_value' => @ktup,
! 'matrix' => @matrix,
! }
! data = []
! form.each do |k, v|
! data.push("#{k}=#{v}") if v
! end
! report = nil
! begin
! http = Bio::Command.new_http(host)
! http.open_timeout = 300
! http.read_timeout = 600
! result, = http.post(path, data.join('&'))
! @output = result.body
! # workaround 2005.08.12 - realized that this is bloken again (by new batch queuing system) 2006.06.08
! 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
!
! return report
end
end
! end
--- 15,219 ----
module Bio
! class Fasta
! #autoload :Report, 'bio/appl/fasta/format10'
! #autoload :?????, 'bio/appl/fasta/format6'
! # Returns a FASTA factory object (Bio::Fasta).
! def initialize(program, db, opt = [], server = 'local')
! @format = 10
! @program = program
! @db = db
! @server = server
! @ktup = nil
! @matrix = nil
! @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
! # Returns a String containing fasta execution output in as is format.
! attr_reader :output
! def option
! # backward compatibility
! Bio::Command.make_command_line(@options)
! end
! def option=(str)
! # backward compatibility
! @options = Shellwords.shellwords(str)
! end
! # Accessors for the -m option.
! 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
! # Select parser to use ('format6' and 'format10' is acceptable for now)
! #
! # This method will import Bio::Fasta::Report class by requiring specified
! # parser and will be useful when you already have fasta output files and
! # want to use appropriate Report class for parsing.
! #
! def self.parser(parser)
! require "bio/appl/fasta/#{parser}"
! end
! # Returns a FASTA factory object (Bio::Fasta) to run FASTA search on
! # local computer.
! def self.local(program, db, option = '')
! self.new(program, db, option, 'local')
! end
+ # Returns a FASTA factory object (Bio::Fasta) to execute FASTA search on
+ # remote server.
+ #
+ # For the develpper, you can add server 'hoge' by adding
+ # exec_hoge(query) method.
+ #
+ def self.remote(program, db, option = '', server = 'genomenet')
+ self.new(program, db, option, server)
+ end
! # Execute FASTA search and returns Report object (Bio::Fasta::Report).
! def query(query)
! return self.send("exec_#{@server}", query.to_s)
! end
! private
!
!
! def parse_result(data)
! case @format
! when 6
! require 'bio/appl/fasta/format6'
! when 10
! require 'bio/appl/fasta/format10'
end
+ Report.new(data)
+ end
! def exec_local(query)
! cmd = [ @program, *@options ]
! cmd.concat([ '@', @db, @ktup ])
! report = nil
! @output = Bio::Command.query_command(cmd, query)
! report = parse_result(@output)
! return report
! end
! # == Available databases for Fasta.remote(@program, @db, option, 'genomenet')
! #
! # See http://fasta.genome.jp/ideas/ideas.html#fasta for more details.
! #
! # ----------+-------+---------------------------------------------------
! # @program | query | @db (supported in GenomeNet)
! # ----------+-------+---------------------------------------------------
! # fasta | AA | nr-aa, genes, vgenes.pep, swissprot, swissprot-upd,
! # | | pir, prf, pdbstr
! # +-------+---------------------------------------------------
! # | NA | nr-nt, genbank-nonst, gbnonst-upd, dbest, dbgss,
! # | | htgs, dbsts, embl-nonst, embnonst-upd, epd,
! # | | genes-nt, genome, vgenes.nuc
! # ----------+-------+---------------------------------------------------
! # tfasta | AA | nr-nt, genbank-nonst, gbnonst-upd, dbest, dbgss,
! # | | htgs, dbsts, embl-nonst, embnonst-upd,
! # | | genes-nt, genome, vgenes.nuc
! # ----------+-------+---------------------------------------------------
! #
! def exec_genomenet(query)
! host = "fasta.genome.jp"
! #path = "/sit-bin/nph-fasta"
! path = "/sit-bin/fasta" # 2005.08.12
! form = {
! 'style' => 'raw',
! 'prog' => @program,
! 'dbname' => @db,
! 'sequence' => CGI.escape(query),
! 'other_param' => CGI.escape(Bio::Command.make_command_line_unix(@options)),
! 'ktup_value' => @ktup,
! 'matrix' => @matrix,
! }
! data = []
! form.each do |k, v|
! data.push("#{k}=#{v}") if v
! end
! report = nil
! begin
! http = Bio::Command.new_http(host)
! http.open_timeout = 3000
! http.read_timeout = 6000
! result, = http.post(path, data.join('&'))
! # workaround 2006.8.1 - fixed for new batch queuing system
! case result.code
! when "302"
! result_location = result.header['location']
! result_uri = URI.parse(result_location)
! result_path = result_uri.path
! done = false
! until done
! result = http.get(result_path)
! if result.body[/Your job ID is/]
! sleep 15
! else
! done = true
! end
end
end
! @output = result.body.to_s
! # workaround 2005.08.12
! re = %r{<A HREF="http://#{host}(/tmp/[^"]+)">Show all result</A>} # "
! if path = @output[re, 1]
! result, = http.get(path)
! @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
+ return report
end
! end # Fasta
!
! end # Bio
***************
*** 186,189 ****
--- 228,233 ----
# serv = Bio::Fasta.local('fasta34', 'hoge.pep')
# serv = Bio::Fasta.local('ssearch34', 'hoge.pep')
+
+ # This may take 3 minutes or so.
serv = Bio::Fasta.remote('fasta', 'genes')
p serv.query(ARGF.read)
***************
*** 191,260 ****
- =begin
-
- = Bio::Fasta
-
- --- Bio::Fasta.new(program, db, option = '', server = 'local')
- --- Bio::Fasta.local(program, db, option = '')
- --- Bio::Fasta.remote(program, db, option = '', server = 'genomenet')
-
- Returns a fasta factory object (Bio::Fasta).
-
- For the develpper, you can add server 'hoge' by adding
- exec_hoge(query) method.
-
- --- Bio::Fasta#query(query)
-
- Execute fasta search and returns Report object (Bio::Fasta::Report).
-
- --- Bio::Fasta#output
-
- Returns a String containing fasta execution output in as is format.
-
- --- 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
- --- Bio::Fasta#format=(number)
-
- Accessors for the -m option.
-
- --- Bio::Fasta.parser(parser)
-
- Import Bio::Fasta::Report class by requiring specified parser.
-
- This class method will be useful when you already have fasta
- output files and want to use appropriate Report class for parsing.
-
-
- == Available databases for Fasta.remote(@program, @db, option, 'genomenet')
-
- # ----------+-------+---------------------------------------------------
- # @program | query | @db (supported in GenomeNet)
- # ----------+-------+---------------------------------------------------
- # fasta | AA | nr-aa, genes, vgenes.pep, swissprot, swissprot-upd,
- # | | pir, prf, pdbstr
- # +-------+---------------------------------------------------
- # | NA | nr-nt, genbank-nonst, gbnonst-upd, dbest, dbgss,
- # | | htgs, dbsts, embl-nonst, embnonst-upd, epd,
- # | | genes-nt, genome, vgenes.nuc
- # ----------+-------+---------------------------------------------------
- # tfasta | AA | nr-nt, genbank-nonst, gbnonst-upd, dbest, dbgss,
- # | | htgs, dbsts, embl-nonst, embnonst-upd,
- # | | genes-nt, genome, vgenes.nuc
- # ----------+-------+---------------------------------------------------
-
- See http://fasta.genome.jp/ideas/ideas.html#fasta for more details.
-
- =end
-
--- 235,236 ----
More information about the bioruby-cvs
mailing list