summaryrefslogtreecommitdiff
path: root/lib/model.rb
blob: 50d6bea7c30dc64ddce3e22a787cba29c20cde61 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module OpenTox
	module Model
		class Lazar
			include Owl
			
			# Create a new prediction model from a dataset
			def initialize
				super
			end

			def read_yaml(id,yaml)
				@lazar = YAML.load yaml
				self.identifier = File.join(@@config[:services]["opentox-model"],'lazar',id)
				self.title = "lazar model for #{@lazar[:endpoint]}"
				self.source = "http://github.com/helma/opentox-model"
				self.parameters = {
					"Dataset URI" => { :scope => "mandatory", :value => "dataset_uri=#{@lazar[:activity_dataset]}" },
					"Feature URI for dependent variable" => { :scope => "mandatory", :value => "feature_uri=#{@lazar[:endpoint]}" },
					"Feature generation URI" => { :scope => "mandatory", :value => "feature_generation_uri=" } #TODO write to yaml
				}
				self.algorithm = File.join(@@config[:services]["opentox-model"],"lazar")
				self.trainingDataset = @lazar[:activity_dataset]
				self.dependentVariables = @lazar[:endpoint]
				self.predictedVariables = @lazar[:endpoint] + " lazar prediction"
			end

			def self.find(uri)
				begin
					YAML.load(RestClient.get uri)
					Lazar.new uri
				rescue
					halt 404, "Model #{uri} not found."
				end
			end

			def self.find_all
				RestClient.get(@@config[:services]["opentox-model"]).split("\n")
			end
			
			# Predict a compound
			def predict(compound)
				RestClient.post(@uri, :compound_uri => compound.uri)
			end

			def self.base_uri
				@@config[:services]["opentox-model"]
			end

			def self.create(data)
				RestClient.post(@@config[:services]["opentox-model"], data, :content_type => "application/x-yaml").to_s
			end

			def endpoint
				YAML.load(RestClient.get uri)[:endpoint]
			end

		end
	end


=begin
	module Model 

		class LazarClassification < OpenTox


		end

	end

	module Prediction

		module Classification

			class Lazar < OpenTox

				def initialize(params)
					super(params[:uri])
				end

				def classification
					YAML.load(RestClient.get(@uri))[:classification]
				end

				def confidence
					YAML.load(RestClient.get(@uri))[:confidence]
				end

				def neighbors
					RestClient.get @uri + '/neighbors' 
				end

				def features
					RestClient.get @uri + '/features' 
				end

			end

		end

	end
=end
end