Sha256: f42759d0d92366d868edf999238c9e21c79ea14c7c14abebe9a77acde68bc018
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
require 'ostruct' require_relative '../support/third_part/active_support/core_ext/object/try' require_relative '../support/parameters' module Bioinform class Motif include Parameters make_parameters :pcm, :pwm, :ppm, :name, :original_data_model # 0)Motif.new() # 1)Motif.new(pcm: ..., pwm: ..., name: ...,threshold: ...) # 2)Motif.new(my_pcm) # 3)Motif.new(pm: my_pcm, threshold: ...) # 2) and 3) cases will automatically choose data model #### What if pm already is a Motif def initialize(parameters = {}) case parameters when PM pm = parameters motif_type = pm.class.name.downcase.sub(/^.+::/,'').to_sym self.original_data_model = motif_type set_parameters(motif_type => pm) when Hash if parameters.has_key?(:pm) && parameters[:pm].is_a?(PM) pm = parameters.delete(:pm) motif_type = pm.class.name.downcase.sub(/^.+::/,'').to_sym self.original_data_model = motif_type set_parameters(motif_type => pm) end set_parameters(parameters) else raise ArgumentError, "Motif::new doesn't accept argument #{parameters} of class #{parameters.class}" end end def pm; ((original_data_model || :pm) == :pm) ? parameters.pm : send(original_data_model); end #def pcm; parameters.pcm; end def pwm; parameters.pwm || pcm.try(:to_pwm); end def ppm; parameters.ppm || pcm.try(:to_ppm); end #def pcm=(pcm); parameters.pcm = pcm; end #def pwm=(pwm); parameters.pwm = pwm; end #def ppm=(ppm); parameters.ppm = ppm; end def name; parameters.name || pm.name; end def method_missing(meth, *args) parameters.__send__(meth, *args) end def ==(other) parameters == other.parameters end def to_s parameters.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bioinform-0.1.12 | lib/bioinform/data_models/motif.rb |