summaryrefslogtreecommitdiff
path: root/lib/model.rb
blob: a354cfa3fa1f10ea8d346b4e3c259fcf9d77c920 (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
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
        bad_request_error "Cannot determine feature type, dependent variable missing in model #{@uri}" unless metadata[RDF::OT.dependentVariables]
        @feature_type = OpenTox::Feature.new( metadata[RDF::OT.dependentVariables][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[RDF::OT.predictedVariables].each do |f|
        feat = OpenTox::Feature.new( f, @subjectid )
        if feat.title =~ /confidence/
          @predicted_confidence = f
        else
          @predicted_variable = f unless @predicted_variable
        end 
      end
    end

  end
end