summaryrefslogtreecommitdiff
path: root/lib/model.rb
blob: c2914eb2e0ff2d93301b2efdb8af72352f424c29 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module OpenTox

  module Model
=begin
    # Run a model with parameters
    # @param params [Hash] Parameters for OpenTox model
    # @param wait [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
=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

    class Generic
      include OpenTox
      include OpenTox::Algorithm
      include Model
    end

    class Lazar
      include OpenTox
      include OpenTox::Algorithm
      include Model
      def self.create params
        Lazar.new(File.join($algorithm[:uri], "lazar")).run params
      end

      def predict params
        run params
      end

    end

  end
end