class BisearchEnzimHu::PrimerDesign
Primer Design Form (at bisearch.enzim.hu/?m=search)
Constants
- URL
Attributes
chr[R]
end_pos[R]
form[R]
page[R]
primers[R]
start_pos[R]
url[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 11 def initialize(options={}) @agent = Mechanize.new @options = default_options.merge options @url = @options.delete :url end
Public Instance Methods
prepare()
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 29 def prepare # filling form @page = @agent.get(@url) @form = @page.form @options.each_pair do |field_name, value| case get_type(field_name) when :select # a dropdown @form.field_with(name: field_name.to_s).options.find{|e| e.text.downcase=~Regexp.new(value.downcase)}.select when :checkbox @form.checkbox_with(name: field_name.to_s).send(value ? :check : :uncheck) when :radiobutton @form.radiobutton_with(name: field_name.to_s).send(value ? :check : :uncheck) when :text @form.field_with(name: field_name.to_s).value=value when :text_area @form.field_with(name: field_name.to_s).value=value # same as text end end self end
prune()
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 63 def prune indexes_to_remove = [] puts @primers.inspect puts @primers[:output].inspect @primers[:output].each_pair do |i, h| puts h.inspect indexes_to_remove << i if h[:fpcr][:sense][:results].size>1 indexes_to_remove << i if h[:fpcr][:antisense][:results].size>1 end indexes_to_remove.uniq! puts "results to remove: [#{indexes_to_remove.join(', ')}]" indexes_to_remove.each{|i| @primers[:output].delete(i)} end
search(two_levels=true)
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 50 def search(two_levels=true) @primers = {} puts "---> starting search primers" t = Time.now page = @agent.submit(@form) puts "---> query completed (time: #{Time.now-t}s)" @primers[:input] = {chr: @chr, start_pos: @start_pos, end_pos: @end_pos, seq: @options[:seq]} res_page = BisearchEnzimHu::L1ResultPage.new(page.body) # @primers[:output] = BisearchEnzimHu::L1ResultPage.new(page.body) @primers[:output] = res_page.parse(two_levels) self end
sequence(seq, chr=nil, start_pos=nil)
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 18 def sequence(seq, chr=nil, start_pos=nil) @primers = {} @chr = chr @start_pos = start_pos @end_pos = start_pos + seq.size if start_pos @options[:seq] = seq prepare self end
Private Instance Methods
default_options()
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 79 def default_options { bis: true, optlen: 30, mincpg: 0, db: "homo sapiens", url: URL } end
field_types()
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 93 def field_types # default is :text { bis: :checkbox, db: :select } end
get_type(field_name)
click to toggle source
# File lib/bisearch_enzim_hu/primer_design.rb, line 89 def get_type(field_name) field_types[field_name.to_sym] || :text end