class Bio::Fasta

Attributes

db[RW]
format[R]
ktup[RW]
matrix[RW]
options[RW]
output[R]

Returns a String containing fasta execution output in as is format.

program[RW]
server[RW]

Public Class Methods

local(program, db, option = '') click to toggle source

Returns a FASTA factory object (Bio::Fasta) to run FASTA search on local computer.

   # File lib/bio/appl/fasta.rb
80 def self.local(program, db, option = '')
81   self.new(program, db, option, 'local')
82 end
new(program, db, opt = [], server = 'local') click to toggle source

Returns a FASTA factory object (Bio::Fasta).

   # File lib/bio/appl/fasta.rb
23 def initialize(program, db, opt = [], server = 'local')
24   @format     = 10
25 
26   @program    = program
27   @db = db
28   @server     = server
29 
30   @ktup       = nil
31   @matrix     = nil
32 
33   @output     = ''
34 
35   begin
36     a = opt.to_ary
37   rescue NameError #NoMethodError
38     # backward compatibility
39     a = Shellwords.shellwords(opt)
40   end
41   @options    = [ '-Q', '-H', '-m', @format.to_s, *a ] # need -a ?
42 end
parser(parser) click to toggle source

OBSOLETE. Does nothing and shows warning messages.

Historically, selecting parser to use ('format6' or 'format10' were expected, but only 'format10' was available as a working parser).

   # File lib/bio/appl/fasta.rb
74 def self.parser(parser)
75   warn 'Bio::Fasta.parser is obsoleted and will soon be removed.'
76 end
remote(program, db, option = '', server = 'genomenet') click to toggle source

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.

   # File lib/bio/appl/fasta.rb
90 def self.remote(program, db, option = '', server = 'genomenet')
91   self.new(program, db, option, server)
92 end

Public Instance Methods

format=(num) click to toggle source

Accessors for the -m option.

   # File lib/bio/appl/fasta.rb
59 def format=(num)
60   @format = num.to_i
61   if i = @options.index('-m') then
62     @options[i+1, 1] = @format.to_s
63   else
64     @options << '-m' << @format.to_s
65   end
66 end
option() click to toggle source
   # File lib/bio/appl/fasta.rb
48 def option
49   # backward compatibility
50   Bio::Command.make_command_line(@options)
51 end
option=(str) click to toggle source
   # File lib/bio/appl/fasta.rb
53 def option=(str)
54   # backward compatibility
55   @options = Shellwords.shellwords(str)
56 end
query(query) click to toggle source

Execute FASTA search and returns Report object (Bio::Fasta::Report).

   # File lib/bio/appl/fasta.rb
95 def query(query)
96   return self.send("exec_#{@server}", query.to_s)
97 end

Private Instance Methods

exec_genomenet(query) click to toggle source

Available databases for Fasta.remote(@program, @db, option, 'genomenet')

See 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
----------+-------+---------------------------------------------------
    # File lib/bio/appl/fasta.rb
141 def exec_genomenet(query)
142   host = "fasta.genome.jp"
143   #path = "/sit-bin/nph-fasta"
144   path = "/sit-bin/fasta"  # 2005.08.12
145 
146   form = {
147     'style'        => 'raw',
148     'prog'         => @program,
149     'dbname'       => @db,
150     'sequence'     => query,
151     'other_param'  => Bio::Command.make_command_line_unix(@options),
152     'ktup_value'   => @ktup,
153     'matrix'       => @matrix,
154   }
155 
156   form.keys.each do |k|
157     form.delete(k) unless form[k]
158   end
159 
160   report = nil
161 
162   begin
163     http = Bio::Command.new_http(host)
164     http.open_timeout = 3000
165     http.read_timeout = 6000
166     result = Bio::Command.http_post_form(http, path, form)
167     # workaround 2006.8.1 - fixed for new batch queuing system
168     case result.code
169     when "302"
170       result_location = result.header['location']
171       result_uri = URI.parse(result_location)
172       result_path = result_uri.path
173       done = false
174       until done
175         result = http.get(result_path)
176         if result.body[/Your job ID is/]
177           sleep 15
178         else
179           done = true
180         end
181       end
182     end
183     @output = result.body.to_s
184     # workaround 2005.08.12
185     re = %r{<A HREF="http://#{host}(/tmp/[^"]+)">Show all result</A>}i # "
186     if path = @output[re, 1]
187       result = http.get(path)
188       @output = result.body
189       txt = @output.to_s.split(/\<pre\>/)[1]
190       raise 'cannot understand response' unless txt
191       txt.sub!(/\<\/pre\>.*\z/m, '')
192       txt.sub!(/.*^((T?FASTA|SSEARCH) (searches|compares))/m, '\1')
193       txt.sub!(/^\<form method\=\"POST\" name\=\"clust_check\"\>.*\n/, '')
194       txt.sub!(/^\<select +name\=\"allch\".+\r?\n/i, '') # 2009.11.26
195       txt.gsub!(/\<input[^\>]+value\=\"[^\"]*\"[^\>]*\>/i, '')
196       txt.gsub!(/\<(a|form|select|input|option|img)\s+[^\>]+\>/i, '')
197       txt.gsub!(/\<\/(a|form|select|input|option|img)\>/i, '')
198       txt.gsub!(/\&lt\;/, '<')
199       txt.gsub!(/\&gt\;/, '>') # 2009.11.26
200       @output = txt
201       report = parse_result(@output.dup)
202     else
203       raise 'cannot understand response'
204     end
205   end
206 
207   return report
208 end
exec_local(query) click to toggle source
    # File lib/bio/appl/fasta.rb
108 def exec_local(query)
109   cmd = [ @program, *@options ]
110   cmd.concat([ '@', @db ])
111   cmd.push(@ktup) if @ktup
112 
113   report = nil
114 
115   @output = Bio::Command.query_command(cmd, query)
116   report = parse_result(@output)
117 
118   return report
119 end
parse_result(data) click to toggle source
    # File lib/bio/appl/fasta.rb
103 def parse_result(data)
104   Report.new(data)
105 end