From 6a2c3f2100d030c30b7d8ac8c95dcece7edb040c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 8 Sep 2009 16:04:23 +0200 Subject: api separated into individual components, adapted for new webservice versions --- lib/feature.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/feature.rb (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb new file mode 100644 index 0000000..0cad7c0 --- /dev/null +++ b/lib/feature.rb @@ -0,0 +1,45 @@ +module OpenTox + + # uri: /feature/:name/:property_name/:property_value/... + class Feature < OpenTox + + attr_accessor :name, :values + + def initialize(params) + if params[:uri] + @uri = params[:uri] + items = URI.split(@uri)[5].split(/\//) + @name = items[1] + @values = {} + i = 3 + while i < items.size + @values[items[i]] = items[i+1] + i += 2 + end + else + @name = URI.encode(URI.decode(params[:name])) + @values = params[:values] + @uri = File.join(@@config[:services]["opentox-dataset"],"feature",path) + end + end + + def values_path + path = '' + @values.each do |k,v| + path += '/' + URI.encode(k.to_s) + '/' + URI.encode(v.to_s) + end + path + end + + def path + File.join(@name,values_path) + end + + def value(property) + items = @uri.split(/\//) + i = items.index(property) + items[i+1] + end + + end +end -- cgit v1.2.3 From 59249a0febc2f90cd1643ddb7e3baa68e3f49065 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 10 Sep 2009 15:21:09 +0200 Subject: initial wrapper for new webservices --- lib/feature.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 0cad7c0..8b0839f 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -9,15 +9,16 @@ module OpenTox if params[:uri] @uri = params[:uri] items = URI.split(@uri)[5].split(/\//) - @name = items[1] + @name = items[2] @values = {} - i = 3 + i = 4 while i < items.size @values[items[i]] = items[i+1] i += 2 end else - @name = URI.encode(URI.decode(params[:name])) + @name = params[:name] + #@name = URI.encode(URI.decode(params[:name])) @values = params[:values] @uri = File.join(@@config[:services]["opentox-dataset"],"feature",path) end -- cgit v1.2.3 From 5d5688fbe43806af8523e5481715b5969feeab60 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 6 Oct 2009 10:39:43 +0200 Subject: Passes tests in opentox-test --- lib/feature.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 8b0839f..a3ba333 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -9,31 +9,33 @@ module OpenTox if params[:uri] @uri = params[:uri] items = URI.split(@uri)[5].split(/\//) - @name = items[2] + @name = items[1] @values = {} - i = 4 + i = 2 while i < items.size @values[items[i]] = items[i+1] i += 2 end else @name = params[:name] - #@name = URI.encode(URI.decode(params[:name])) - @values = params[:values] - @uri = File.join(@@config[:services]["opentox-dataset"],"feature",path) + @values = {} + params.each do |k,v| + @values[k] = v unless k.to_s == 'name' + end + @uri = File.join(@@config[:services]["opentox-feature"],path) end end def values_path path = '' @values.each do |k,v| - path += '/' + URI.encode(k.to_s) + '/' + URI.encode(v.to_s) + path = File.join path, URI.encode(k.to_s), URI.encode(v.to_s) end path end def path - File.join(@name,values_path) + File.join(URI.encode(@name),values_path) end def value(property) -- cgit v1.2.3 From adfcc9d572a2122b1b030dc04b3abf46007fb3f7 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 23 Nov 2009 18:17:37 +0100 Subject: RDF support added --- lib/feature.rb | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 lib/feature.rb (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb deleted file mode 100644 index a3ba333..0000000 --- a/lib/feature.rb +++ /dev/null @@ -1,48 +0,0 @@ -module OpenTox - - # uri: /feature/:name/:property_name/:property_value/... - class Feature < OpenTox - - attr_accessor :name, :values - - def initialize(params) - if params[:uri] - @uri = params[:uri] - items = URI.split(@uri)[5].split(/\//) - @name = items[1] - @values = {} - i = 2 - while i < items.size - @values[items[i]] = items[i+1] - i += 2 - end - else - @name = params[:name] - @values = {} - params.each do |k,v| - @values[k] = v unless k.to_s == 'name' - end - @uri = File.join(@@config[:services]["opentox-feature"],path) - end - end - - def values_path - path = '' - @values.each do |k,v| - path = File.join path, URI.encode(k.to_s), URI.encode(v.to_s) - end - path - end - - def path - File.join(URI.encode(@name),values_path) - end - - def value(property) - items = @uri.split(/\//) - i = items.index(property) - items[i+1] - end - - end -end -- cgit v1.2.3 From d6811507c1c1339cc4fe7cdb429b9b34b97dc422 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 22 Oct 2010 17:45:19 +0200 Subject: new API with support for external services (initial version) --- lib/feature.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/feature.rb (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb new file mode 100644 index 0000000..9616135 --- /dev/null +++ b/lib/feature.rb @@ -0,0 +1,7 @@ +module OpenTox + + class Feature + include OtObject + end + +end -- cgit v1.2.3 From b93002b4ea50ff7e357da08abd10577347ce2d5f Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 11 Nov 2010 09:31:27 +0100 Subject: first steps towards version 2.0, yard documentation started, passes compound, dataset, feature, algorithm, fminer tests --- lib/feature.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 9616135..13d97a2 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,7 +1,5 @@ module OpenTox - class Feature - include OtObject + include OpenTox end - end -- cgit v1.2.3 From f8552611c2dbe25d76474f51e4e895bf9c2b5c5e Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 19 Nov 2010 16:53:21 +0100 Subject: lazar predictions for toxcreate working --- lib/feature.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 13d97a2..9e28077 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,5 +1,15 @@ module OpenTox class Feature include OpenTox + + def self.find(uri) + feature = Feature.new uri + if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) + feature.add_metadata YAML.load(RestClientWrapper.get(uri,:accept => "application/x-yaml")) + else + feature.add_metadata Parser::Owl::Dataset.new(uri).load_metadata + end + feature + end end end -- cgit v1.2.3 From 4c089275d34ba42014e1add97a41ccf351790260 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 5 Jan 2011 10:30:54 +0100 Subject: Authorization for GET requests --- lib/feature.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 9e28077..349f8ae 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -2,10 +2,10 @@ module OpenTox class Feature include OpenTox - def self.find(uri) + def self.find(uri, subjectid=nil) feature = Feature.new uri if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) - feature.add_metadata YAML.load(RestClientWrapper.get(uri,:accept => "application/x-yaml")) + feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => subjectid})) else feature.add_metadata Parser::Owl::Dataset.new(uri).load_metadata end -- cgit v1.2.3 From f2ca545448ab8a6f654309f23cfce9416b2e9856 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 13 Jan 2011 14:02:58 +0100 Subject: find methods for algorithm and model, split method for dataset, feature_type method for model and feature, perform single predicitons in resuce block, add to-html.rb, fix handling of rest-client-wrapper --- lib/feature.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 9e28077..de7c757 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,7 +1,7 @@ module OpenTox class Feature include OpenTox - + def self.find(uri) feature = Feature.new uri if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) @@ -11,5 +11,26 @@ module OpenTox end feature end + + # provides domain (possible target values) of classification feature + # @return [Array] list with possible target values + def domain + #TODO derieve from metadata / ontology + return [true, false] + end + + # provides feature type, possible types are "regression" or "classification" + # @return [String] feature type, unknown if OT.isA property is unknown/ not set + def feature_type + case metadata[OT.isA] + when /NominalFeature/ + "classification" + when /NumericFeature/ + "regression" + else + "unknown" + end + end + end end -- cgit v1.2.3 From e1a067953dd9139b01aaebe42ff158a944240540 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 28 Jan 2011 12:20:08 +0100 Subject: extend whitelisting, get feature_type from algorithm --- lib/feature.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 28ac0c5..be063dd 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -3,7 +3,8 @@ module OpenTox include OpenTox def self.find(uri, subjectid=nil) - feature = Feature.new uri + return nil unless uri + feature = Feature.new uri if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => subjectid})) else -- cgit v1.2.3 From d4eb231a35c23a5fdb36fd6220b5ab706e7528ba Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 14 Feb 2011 17:48:26 +0100 Subject: read from subjectcookie, fix read feature_type --- lib/feature.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index be063dd..c0729a7 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -16,8 +16,14 @@ module OpenTox # provides domain (possible target values) of classification feature # @return [Array] list with possible target values def domain - #TODO derieve from metadata / ontology - return [true, false] + if metadata[OT.acceptValue] + raise "accept value found, remove hack and implement correctly" + else + if @uri=~/feature\/26221/ || @uri=~/feature\/221726/ + return ["mutagen" , "nonmutagen"] + end + return [true, false] + end end # provides feature type, possible types are "regression" or "classification" -- cgit v1.2.3 From c802bfd6c899d4d37e3bd2ee274c1bc3ffb7cd94 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 16 Mar 2011 14:11:37 +0100 Subject: doc for Feature.find, load_features in feature_type --- lib/feature.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index c0729a7..e768f7b 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -2,6 +2,9 @@ module OpenTox class Feature include OpenTox + # Find a feature + # @param [String] uri Feature URI + # @return [OpenTox::Task] Feature object def self.find(uri, subjectid=nil) return nil unless uri feature = Feature.new uri -- cgit v1.2.3 From 1daec5badcff31c591377017b32055aac775dbb7 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 4 Apr 2011 18:46:22 +0200 Subject: OT.isA substituted by RDF.type, identification of feature_types by RDF.type --- lib/feature.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index e768f7b..f6e2dfd 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -32,7 +32,16 @@ module OpenTox # provides feature type, possible types are "regression" or "classification" # @return [String] feature type, unknown if OT.isA property is unknown/ not set def feature_type - case metadata[OT.isA] + if metadata[RDF.type].flatten.include?(OT.NominalFeature) + "classification" + elsif metadata[RDF.type].flatten.include?(OT.NumericFeature) + "regression" + else + #"unknown" + metadata[RDF.type].inspect + end +=begin + case metadata[RDF.type] when /NominalFeature/ "classification" when /NumericFeature/ @@ -40,6 +49,7 @@ module OpenTox else "unknown" end +=end end end -- cgit v1.2.3 From 0f1e80c3dcbbbc0d8b2f916de68d6d0c86b53ec2 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 6 May 2011 19:29:55 +0200 Subject: read acceptValue from ambit datasets, set acceptValue when create dataset from csv/excel --- lib/feature.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index f6e2dfd..b631e46 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -16,19 +16,6 @@ module OpenTox feature end - # provides domain (possible target values) of classification feature - # @return [Array] list with possible target values - def domain - if metadata[OT.acceptValue] - raise "accept value found, remove hack and implement correctly" - else - if @uri=~/feature\/26221/ || @uri=~/feature\/221726/ - return ["mutagen" , "nonmutagen"] - end - return [true, false] - end - end - # provides feature type, possible types are "regression" or "classification" # @return [String] feature type, unknown if OT.isA property is unknown/ not set def feature_type -- cgit v1.2.3 From 03a87a832162ccf17b6f0ebfda126e3622530ca3 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Wed, 11 May 2011 15:56:55 +0200 Subject: Further Martin patch --- lib/feature.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index f6e2dfd..eb0b869 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -19,14 +19,7 @@ module OpenTox # provides domain (possible target values) of classification feature # @return [Array] list with possible target values def domain - if metadata[OT.acceptValue] - raise "accept value found, remove hack and implement correctly" - else - if @uri=~/feature\/26221/ || @uri=~/feature\/221726/ - return ["mutagen" , "nonmutagen"] - end - return [true, false] - end + return [true, false] end # provides feature type, possible types are "regression" or "classification" -- cgit v1.2.3 From af426336f15e1f4b58c87bf09571721bb42a388f Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 27 May 2011 10:06:12 +0200 Subject: predicted variable and confidence can now be derieved from model, adjust feature_type accordingly --- lib/feature.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 2f1ab6c..f3bec5c 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -2,6 +2,8 @@ module OpenTox class Feature include OpenTox + attr_accessor :subjectid + # Find a feature # @param [String] uri Feature URI # @return [OpenTox::Task] Feature object @@ -13,9 +15,9 @@ module OpenTox else feature.add_metadata Parser::Owl::Dataset.new(uri).load_metadata end + feature.subjectid = subjectid feature end - # provides feature type, possible types are "regression" or "classification" # @return [String] feature type, unknown if OT.isA property is unknown/ not set @@ -24,21 +26,19 @@ module OpenTox "classification" elsif metadata[RDF.type].flatten.include?(OT.NumericFeature) "regression" - else - #"unknown" - metadata[RDF.type].inspect - end -=begin - case metadata[RDF.type] - when /NominalFeature/ - "classification" - when /NumericFeature/ - "regression" + elsif metadata[OWL.sameAs] + metadata[OWL.sameAs].each do |f| + begin + type = Feature.find(f, subjectid).feature_type + return type unless type=="unknown" + rescue => ex + LOGGER.warn "could not load same-as-feature '"+f.to_s+"' for feature '"+uri.to_s+"' : "+ex.message.to_s + end + end + "unknown" else "unknown" end -=end end - end end -- cgit v1.2.3 From 64354959e04fcac11bcf70e75099691b74573033 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 16 Aug 2011 14:46:31 +0200 Subject: initial minimal version --- lib/feature.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index f3bec5c..84a85b9 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -6,12 +6,12 @@ module OpenTox # Find a feature # @param [String] uri Feature URI - # @return [OpenTox::Task] Feature object + # @return [OpenTox::Feature] Feature object def self.find(uri, subjectid=nil) return nil unless uri - feature = Feature.new uri + feature = Feature.new uri, subjectid if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) - feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => subjectid})) + feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => @subjectid})) else feature.add_metadata Parser::Owl::Dataset.new(uri).load_metadata end -- cgit v1.2.3 From 354aaa649e9eeed5d81793e09d9714b45063c147 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 8 Feb 2012 13:14:11 +0100 Subject: toxbank-investigation compatible version --- lib/feature.rb | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 lib/feature.rb (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb deleted file mode 100644 index 84a85b9..0000000 --- a/lib/feature.rb +++ /dev/null @@ -1,44 +0,0 @@ -module OpenTox - class Feature - include OpenTox - - attr_accessor :subjectid - - # Find a feature - # @param [String] uri Feature URI - # @return [OpenTox::Feature] Feature object - def self.find(uri, subjectid=nil) - return nil unless uri - feature = Feature.new uri, subjectid - if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) - feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => @subjectid})) - else - feature.add_metadata Parser::Owl::Dataset.new(uri).load_metadata - end - feature.subjectid = subjectid - feature - end - - # provides feature type, possible types are "regression" or "classification" - # @return [String] feature type, unknown if OT.isA property is unknown/ not set - def feature_type - if metadata[RDF.type].flatten.include?(OT.NominalFeature) - "classification" - elsif metadata[RDF.type].flatten.include?(OT.NumericFeature) - "regression" - elsif metadata[OWL.sameAs] - metadata[OWL.sameAs].each do |f| - begin - type = Feature.find(f, subjectid).feature_type - return type unless type=="unknown" - rescue => ex - LOGGER.warn "could not load same-as-feature '"+f.to_s+"' for feature '"+uri.to_s+"' : "+ex.message.to_s - end - end - "unknown" - else - "unknown" - end - end - end -end -- cgit v1.2.3 From a54db46684680d98311631804eca367cc949a715 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 26 Mar 2013 10:56:04 +0100 Subject: code cleanup and refactoring. --- lib/feature.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/feature.rb (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb new file mode 100644 index 0000000..5d3d962 --- /dev/null +++ b/lib/feature.rb @@ -0,0 +1,37 @@ +module OpenTox + + class Feature + + # Find out feature type + # Classification takes precedence + # @return [String] Feature type + def feature_type + if self[RDF.type].include?(RDF::OT.NominalFeature) + "classification" + elsif self[RDF.type].include?(RDF::OT.NumericFeature) + "regression" + else + "unknown" + end + end + + # Get accept values + # + # @return[Array] Accept values + def accept_values + self[RDF::OT.acceptValue] ? self[RDF::OT.acceptValue].sort : nil + end + + # Create value map + # @param [OpenTox::Feature] Feature + # @return [Hash] A hash with keys 1...feature.training_classes.size and values training classes + def value_map + unless defined? @value_map + accept_values ? @value_map = accept_values.each_index.inject({}) { |h,idx| h[idx+1]=accept_values[idx]; h } : @value_map = nil + end + @value_map + end + + end + +end -- cgit v1.2.3 From 1c74a684b8b2992d7e6fce5f1a4677d397ec4dd6 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sat, 18 Jul 2015 08:52:39 +0200 Subject: dataset tests pass --- lib/feature.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 5d3d962..43cf7e9 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -2,13 +2,18 @@ module OpenTox class Feature + field :string, type: Boolean, default: false + field :nominal, type: Boolean, default: false + field :numeric, type: Boolean, default: false + field :accept_values, type: Array + # Find out feature type # Classification takes precedence # @return [String] Feature type def feature_type - if self[RDF.type].include?(RDF::OT.NominalFeature) + if nominal "classification" - elsif self[RDF.type].include?(RDF::OT.NumericFeature) + elsif numeric "regression" else "unknown" @@ -18,9 +23,9 @@ module OpenTox # Get accept values # # @return[Array] Accept values - def accept_values - self[RDF::OT.acceptValue] ? self[RDF::OT.acceptValue].sort : nil - end + #def accept_values + #self[RDF::OT.acceptValue] ? self[RDF::OT.acceptValue].sort : nil + #end # Create value map # @param [OpenTox::Feature] Feature -- cgit v1.2.3 From 51e7a29c8aac568ff8ef04de5b15d2f6db8f66da Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sun, 19 Jul 2015 21:26:03 +0200 Subject: lazar predictions working in principle --- lib/feature.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 43cf7e9..b2ddce4 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,10 +1,16 @@ module OpenTox + # TODO subclass features class Feature field :string, type: Boolean, default: false field :nominal, type: Boolean, default: false field :numeric, type: Boolean, default: false + field :substructure, type: Boolean, default: false + field :prediction, type: Boolean + field :smarts, type: String + field :pValue, type: Float + field :effect, type: String field :accept_values, type: Array # Find out feature type -- cgit v1.2.3 From cd1cba67830505cd2d23ec83e64c0beed42a9f28 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 22 Jul 2015 20:08:12 +0200 Subject: mongo batch import workaround --- lib/feature.rb | 86 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index b2ddce4..b2f9a93 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,48 +1,62 @@ module OpenTox - # TODO subclass features class Feature + field :name, as: :title, type: String + field :nominal, type: Boolean + field :numeric, type: Boolean + field :measured, type: Boolean + field :calculated, type: Boolean + field :supervised, type: Boolean + field :source, as: :title, type: String + end - field :string, type: Boolean, default: false - field :nominal, type: Boolean, default: false - field :numeric, type: Boolean, default: false - field :substructure, type: Boolean, default: false - field :prediction, type: Boolean - field :smarts, type: String - field :pValue, type: Float - field :effect, type: String + class NominalFeature < Feature field :accept_values, type: Array - - # Find out feature type - # Classification takes precedence - # @return [String] Feature type - def feature_type - if nominal - "classification" - elsif numeric - "regression" - else - "unknown" - end + def initialize params + super params + nominal = true end + end - # Get accept values - # - # @return[Array] Accept values - #def accept_values - #self[RDF::OT.acceptValue] ? self[RDF::OT.acceptValue].sort : nil - #end - - # Create value map - # @param [OpenTox::Feature] Feature - # @return [Hash] A hash with keys 1...feature.training_classes.size and values training classes - def value_map - unless defined? @value_map - accept_values ? @value_map = accept_values.each_index.inject({}) { |h,idx| h[idx+1]=accept_values[idx]; h } : @value_map = nil - end - @value_map + class NumericFeature < Feature + def initialize params + super params + numeric = true end + end + + class Smarts < NominalFeature + field :name, as: :smarts, type: String # causes warnings + field :algorithm, type: String, default: "OpenTox::Algorithm::Descriptors.smarts_match" + field :parameters, type: Hash, default: {:count => false} + def initialize params + super params + nominal = true + end + end + + class FminerSmarts < Smarts + field :training_algorithm, type: String + field :training_compound_ids, type: Array + field :training_feature_id, type: BSON::ObjectId + field :training_parameters, type: Hash + def initialize params + super params + supervised = true + end + end + + class NominalBioAssay < NominalFeature + field :description, type: String + end + + class NumericBioAssay < NumericFeature + field :description, type: String + end + class PhysChemDescriptor < NumericFeature + field :algorithm, type: String + field :parameters, type: Hash end end -- cgit v1.2.3 From 3cea6abe3606ea586b733e943737f77d58f215f9 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 27 Jul 2015 20:51:25 +0200 Subject: reasonable query performace for data_entries --- lib/feature.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index b2f9a93..de8e4c9 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -8,6 +8,8 @@ module OpenTox field :calculated, type: Boolean field :supervised, type: Boolean field :source, as: :title, type: String + #belongs_to :dataset + #belongs_to :data_entry end class NominalFeature < Feature @@ -36,10 +38,9 @@ module OpenTox end class FminerSmarts < Smarts - field :training_algorithm, type: String - field :training_compound_ids, type: Array - field :training_feature_id, type: BSON::ObjectId - field :training_parameters, type: Hash + field :pValue, type: Float + field :effect, type: String + field :dataset_id def initialize params super params supervised = true -- cgit v1.2.3 From e68c69f90036bb7c47c57acb1ee3652b73c835c1 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 31 Jul 2015 10:59:53 +0200 Subject: descriptor tests working --- lib/feature.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index de8e4c9..e565875 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -56,8 +56,9 @@ module OpenTox end class PhysChemDescriptor < NumericFeature - field :algorithm, type: String + field :algorithm, type: String, default: "OpenTox::Algorithm::Descriptor.physchem" field :parameters, type: Hash + field :creator, type: String end end -- cgit v1.2.3 From 2d02fabfafccb164093062a962f392bb7d13647a Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sat, 1 Aug 2015 18:03:09 +0200 Subject: 50 times faster bbrc setup by eliminating @fminer.add_fminer_data --- lib/feature.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index e565875..0801a47 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -9,7 +9,6 @@ module OpenTox field :supervised, type: Boolean field :source, as: :title, type: String #belongs_to :dataset - #belongs_to :data_entry end class NominalFeature < Feature -- cgit v1.2.3 From 04af01b8135ea147e9ce253e5526e3ee3adcc675 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 7 Aug 2015 19:50:09 +0200 Subject: initial k-nn weighted average implementation --- lib/feature.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 0801a47..005d78f 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -27,7 +27,8 @@ module OpenTox end class Smarts < NominalFeature - field :name, as: :smarts, type: String # causes warnings + field :smarts, type: String + #field :name, as: :smarts, type: String # causes warnings field :algorithm, type: String, default: "OpenTox::Algorithm::Descriptors.smarts_match" field :parameters, type: Hash, default: {:count => false} def initialize params @@ -46,6 +47,10 @@ module OpenTox end end + class FingerprintSmarts < Smarts + field :count, type: Integer + end + class NominalBioAssay < NominalFeature field :description, type: String end -- cgit v1.2.3 From 23ecfc6fa5ae4913e5cd17b7d58432d1f88d780c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 10 Aug 2015 09:48:57 +0200 Subject: transfer to new git project started --- lib/feature.rb | 70 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 005d78f..9deb199 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,17 +1,16 @@ module OpenTox + # Basic feature class class Feature field :name, as: :title, type: String field :nominal, type: Boolean field :numeric, type: Boolean field :measured, type: Boolean - field :calculated, type: Boolean - field :supervised, type: Boolean - field :source, as: :title, type: String - #belongs_to :dataset end + # Feature for categorical variables class NominalFeature < Feature + # TODO check if accept_values are still needed field :accept_values, type: Array def initialize params super params @@ -19,6 +18,7 @@ module OpenTox end end + # Feature for quantitative variables class NumericFeature < Feature def initialize params super params @@ -26,43 +26,69 @@ module OpenTox end end + # Feature for SMARTS fragments class Smarts < NominalFeature field :smarts, type: String - #field :name, as: :smarts, type: String # causes warnings - field :algorithm, type: String, default: "OpenTox::Algorithm::Descriptors.smarts_match" - field :parameters, type: Hash, default: {:count => false} - def initialize params - super params - nominal = true - end end + # Feature for supervised fragments from Fminer algorithm class FminerSmarts < Smarts - field :pValue, type: Float + field :p_value, type: Float + # TODO check if effect is used field :effect, type: String field :dataset_id - def initialize params - super params - supervised = true - end end + # Feature for database fingerprints + # needs count for efficient retrieval (see compound.rb) class FingerprintSmarts < Smarts field :count, type: Integer + def self.fingerprint + @@fp4 ||= OpenTox::FingerprintSmarts.all + unless @@fp4.size == 306 + @@fp4 = [] + # OpenBabel FP4 fingerprints + # OpenBabel http://open-babel.readthedocs.org/en/latest/Fingerprints/intro.html + # TODO investigate other types of fingerprints (MACCS) + # OpenBabel http://open-babel.readthedocs.org/en/latest/Fingerprints/intro.html + # http://www.dalkescientific.com/writings/diary/archive/2008/06/26/fingerprint_background.html + # OpenBabel MNA http://openbabel.org/docs/dev/FileFormats/Multilevel_Neighborhoods_of_Atoms_(MNA).html#multilevel-neighborhoods-of-atoms-mna + # Morgan ECFP, FCFP + # http://cdk.github.io/cdk/1.5/docs/api/org/openscience/cdk/fingerprint/CircularFingerprinter.html + # http://www.rdkit.org/docs/GettingStartedInPython.html + # Chemfp + # https://chemfp.readthedocs.org/en/latest/using-tools.html + # CACTVS/PubChem + + File.open(File.join(File.dirname(__FILE__),"SMARTS_InteLigand.txt")).each do |l| + l.strip! + unless l.empty? or l.match /^#/ + name,smarts = l.split(': ') + @@fp4 << OpenTox::FingerprintSmarts.find_or_create_by(:name => name, :smarts => smarts) unless smarts.nil? + end + end + end + @@fp4 + end end + # Feature for physico-chemical descriptors + class PhysChemDescriptor < NumericFeature + field :algorithm, type: String, default: "OpenTox::Algorithm::Descriptor.physchem" + field :parameters, type: Hash + field :creator, type: String + end + + # Feature for categorical bioassay results class NominalBioAssay < NominalFeature + # TODO: needed? move to dataset? field :description, type: String end + # Feature for quantitative bioassay results class NumericBioAssay < NumericFeature + # TODO: needed? move to dataset? field :description, type: String end - class PhysChemDescriptor < NumericFeature - field :algorithm, type: String, default: "OpenTox::Algorithm::Descriptor.physchem" - field :parameters, type: Hash - field :creator, type: String - end - end -- cgit v1.2.3 From b7cd3ebbb858a8891c35c45896f1bdd525f3534e Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 10 Aug 2015 13:26:06 +0200 Subject: algorithm libraries added, fminer tests pass --- lib/feature.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 9deb199..b2bc1f5 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -29,6 +29,9 @@ module OpenTox # Feature for SMARTS fragments class Smarts < NominalFeature field :smarts, type: String + def self.from_smarts smarts + self.find_or_create_by :smarts => smarts + end end # Feature for supervised fragments from Fminer algorithm -- cgit v1.2.3 From 8c6c59980bc82dc2177147f2fe34adf8bfbc1539 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 24 Aug 2015 12:17:07 +0200 Subject: Model::Prediction with tests, initial indexes --- lib/feature.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index b2bc1f5..22b2846 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -29,6 +29,7 @@ module OpenTox # Feature for SMARTS fragments class Smarts < NominalFeature field :smarts, type: String + index "smarts" => 1 def self.from_smarts smarts self.find_or_create_by :smarts => smarts end -- cgit v1.2.3 From f8faf510b4574df1a00fa61a9f0a1681fc2f4857 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 25 Aug 2015 17:20:55 +0200 Subject: Experiments added --- lib/feature.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 22b2846..9521597 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -2,7 +2,7 @@ module OpenTox # Basic feature class class Feature - field :name, as: :title, type: String + field :name, type: String field :nominal, type: Boolean field :numeric, type: Boolean field :measured, type: Boolean -- cgit v1.2.3 From 66c34e4682965272060a121b6e362af67ed4be5f Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 27 Aug 2015 20:28:25 +0200 Subject: Initial GUI for Nestec models --- lib/feature.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 9521597..6fc2c06 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -2,7 +2,6 @@ module OpenTox # Basic feature class class Feature - field :name, type: String field :nominal, type: Boolean field :numeric, type: Boolean field :measured, type: Boolean @@ -85,14 +84,10 @@ module OpenTox # Feature for categorical bioassay results class NominalBioAssay < NominalFeature - # TODO: needed? move to dataset? - field :description, type: String end # Feature for quantitative bioassay results class NumericBioAssay < NumericFeature - # TODO: needed? move to dataset? - field :description, type: String end end -- cgit v1.2.3 From 8d2f1c8a0f6cc9f7a481d1117bf8b3351130b1ea Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 7 Oct 2015 12:34:02 +0200 Subject: generalised fingerprints --- lib/feature.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/feature.rb') diff --git a/lib/feature.rb b/lib/feature.rb index 6fc2c06..13fa6d1 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -47,6 +47,7 @@ module OpenTox class FingerprintSmarts < Smarts field :count, type: Integer def self.fingerprint +=begin @@fp4 ||= OpenTox::FingerprintSmarts.all unless @@fp4.size == 306 @@fp4 = [] @@ -72,6 +73,7 @@ module OpenTox end end @@fp4 +=end end end -- cgit v1.2.3