summaryrefslogtreecommitdiff
path: root/lib/model.rb
blob: 144c8c3538f40d84623b16b99680d41dfc0c5514 (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
41
42
43
44
45
46
module OpenTox

  class Model

    # Run a model with parameters
    # @param [Hash] params Parameters for OpenTox model
    # @param [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
    # @return [text/uri-list] Task or resource URI
    def run params=nil, wait=true
      uri = RestClientWrapper.post @uri, params, { :content_type => "text/uri-list", :subjectid => @subjectid}
      wait_for_task uri if wait
    end

    def feature_type # CH: subjectid is a object variable, no need to pass it as a parameter
      unless @feature_type
        get unless metadata[OT.dependentVariables.to_s]
        bad_request_error "Cannot determine feature type, dependent variable missing in model #{@uri}" unless metadata[OT.dependentVariables.to_s]
        @feature_type = OpenTox::Feature.new( metadata[OT.dependentVariables.to_s][0], @subjectid ).feature_type
      end
      @feature_type
    end
    
    def predicted_variable
      load_predicted_variables unless defined? @predicted_variable
      @predicted_variable
    end
    
    def predicted_confidence
      load_predicted_variables unless defined? @predicted_confidence
      @predicted_confidence
    end
    
    private
    def load_predicted_variables
      metadata[OT.predictedVariables.to_s].each do |f|
        feat = OpenTox::Feature.find( f, @subjectid )
        if feat.title =~ /confidence/
          @predicted_confidence = f
        else
          @predicted_variable = f unless @predicted_variable
        end 
      end
    end

  end
end