summaryrefslogtreecommitdiff
path: root/lib/utils/shims/model.rb
blob: 26a82c408d960001a17c2234c90bb13292ecc274 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40


module OpenTox

  # Shims for the Task class
  class Model

    def feature_type(subjectid=nil)
      unless @feature_type
        get unless metadata[OT.dependentVariables.to_s]
        raise "cannot determine feature type, dependent variable missing" unless metadata[OT.dependentVariables.to_s]
        @feature_type = OpenTox::Feature.find( metadata[OT.dependentVariables.to_s][0], subjectid ).feature_type
      end
      @feature_type
    end
    
    def predicted_variable(subjectid=nil)
      load_predicted_variables(subjectid) unless defined? @predicted_var 
      @predicted_var
    end
    
    def predicted_confidence(subjectid=nil)
      load_predicted_variables(subjectid) unless defined? @predicted_conf 
      @predicted_conf
    end
    
    private
    def load_predicted_variables(subjectid=nil)
      metadata[OT.predictedVariables.to_s].each do |f|
        feat = OpenTox::Feature.find( f, subjectid )
        if feat.title =~ /confidence/
          @predicted_conf = f
        else
          @predicted_var = f unless @predicted_var
        end 
      end
    end
    
  end
end