Module: Bio::Protparam::Remote

Defined in:
lib/bio/util/protparam.rb

Constant Summary collapse

PROTPARAM_URL =
'http://web.expasy.org/cgi-bin/protparam/protparam'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject

Returns the value of attribute result.



376
377
378
# File 'lib/bio/util/protparam.rb', line 376

def result
  @result
end

Class Method Details

.cast_method(type) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/bio/util/protparam.rb', line 378

def self.cast_method(type)
  case type.to_s
  when "Fixnum"
    ".to_i"
  when "Float"
    ".to_f"
  when "String"
    ""
  else
    ""
  end
end

.extract_options(*args) ⇒ Object



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/bio/util/protparam.rb', line 391

def self.extract_options(*args)
  # label, class, regex
  # label, class, regex, lambda
  # label, lambda
  label, type, regex, block = [nil, nil, nil, nil]
  if args.size > 2
    label = args.shift
    type  = args.shift
    if args.size > 1
      regex, block = args
    elsif args.size > 0
      regex, block = if args.first.kind_of?(Regexp)
                       [args.first, nil]
                     elsif args.first.respond_to?(:call)
                       [nil, args.first]
                     end
    end
  end
  [label, type, regex, block]
end

.rule(*args) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/bio/util/protparam.rb', line 412

def self.rule(*args)
  (label, type, regex, block) = extract_options(*args)
  if regex && block
    self.class_eval "    METHOD\n  elsif regex && !block\n    self.class_eval <<-METHOD\n        def \#{label}\n          response = self.request\n          matched  = %r/\#{regex}/.match(response)\n          if matched.size > 1\n            matched[1]\#{cast_method(type)}\n          else\n            nil\n          end\n        end\n            METHOD\n  elsif !regex && block\n    wrapped_block = Proc.new {|*method_args|\n      response = self.request\n      method_args.unshift response\n      block.call(method_args)\n    }\n    self.send(:define_method, label, &wrapped_block)\n  else\n    raise ArgumentError,\n      \"Invalid arguments.rule(:label, :type, :regex) or rule(:label, :type, :lambda)\"\n  end\nend\n"

Instance Method Details

#fallback!Object



500
501
502
503
504
# File 'lib/bio/util/protparam.rb', line 500

def fallback!
  self.class.class_eval do
    include Local
  end
end

#requestObject



492
493
494
495
496
497
498
# File 'lib/bio/util/protparam.rb', line 492

def request
  @result ||= begin
                res = Net::HTTP.post_form(URI(PROTPARAM_URL),
                                          {'sequence' => @seq.to_s})
                res.body
              end
end

#stable?Boolean

Returns:

  • (Boolean)


488
489
490
# File 'lib/bio/util/protparam.rb', line 488

def stable?
  (stablity == 'stable')
end