summaryrefslogtreecommitdiff
path: root/lib/algorithm.rb
blob: c5d162aaf4e66ed8cb36f6b2a4d27446aee5a602 (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
module OpenTox
	module Algorithm 

		class Fminer 
			include Owl

			def initialize
				super
				self.uri = File.join(@@config[:services]["opentox-algorithm"],'fminer')
				self.title = "fminer"
				self.source = "http://github.com/amaunz/libfminer"
				self.parameters = {
					"Dataset URI" => { :scope => "mandatory", :value => "dataset_uri" },
					"Feature URI for dependent variable" => { :scope => "mandatory", :value => "feature_uri" }
				}
			end

			def self.create_feature_dataset(params)
				RestClient.post params[:feature_generation_uri], :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri] 
			end
		end

		class Lazar 
			include Owl

			def initialize
				super
				self.uri = File.join(@@config[:services]["opentox-algorithm"],'lazar')
				self.title = "lazar"
				self.source = "http://github.com/helma/opentox-algorithm"
				self.parameters = {
					"Dataset URI" =>
						{ :scope => "mandatory", :value => "dataset_uri" },
					"Feature URI for dependent variable" =>
						{ :scope => "mandatory", :value => "feature_uri" },
					"Feature generation URI" =>
						{ :scope => "mandatory", :value => "feature_generation_uri" }
				}
			end
			
			def self.create_model(params)
				@uri = RestClient.post File.join(@@config[:services]["opentox-algorithm"], "lazar"), :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")
			end

		end

		class Similarity
			def self.weighted_tanimoto(fp_a,fp_b,p)
				common_features = fp_a & fp_b
				all_features = fp_a + fp_b
				common_p_sum = 0.0
				if common_features.size > 0
					common_features.each{|f| common_p_sum += p[f]}
					all_p_sum = 0.0
					all_features.each{|f| all_p_sum += p[f]}
					common_p_sum/all_p_sum
				else
					0.0
				end
			end
		end

	end
end