From c0bef2dc83d2ce1fea6434ca73586d49865bb810 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 31 Mar 2011 13:44:02 +0200 Subject: ohm-contrib added --- Rakefile | 3 +-- lib/environment.rb | 2 +- lib/ontology.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/ontology_service.rb | 43 -------------------------------------- lib/opentox-ruby.rb | 2 +- 5 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 lib/ontology.rb delete mode 100644 lib/ontology_service.rb diff --git a/Rakefile b/Rakefile index b496cc2..215aeb2 100644 --- a/Rakefile +++ b/Rakefile @@ -28,6 +28,7 @@ begin "tmail", "rinruby", "ohm", + "ohm-contrib", "SystemTimer", "rjb" ].each { |dep| gem.add_dependency dep } @@ -44,8 +45,6 @@ begin gem.add_dependency "haml", ">=3" ['jeweler'].each { |dep| gem.add_development_dependency dep } gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] - #gem.files.include %w(lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/model.rb, lib/validation.rb, lib/templates/*) - # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings end Jeweler::GemcutterTasks.new rescue LoadError diff --git a/lib/environment.rb b/lib/environment.rb index 59578c1..57ae014 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -74,7 +74,7 @@ CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorizatio CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] -RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' +#RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' OWL = OwlNamespace.new 'http://www.w3.org/2002/07/owl#' DC = OwlNamespace.new 'http://purl.org/dc/elements/1.1/' OT = OwlNamespace.new 'http://www.opentox.org/api/1.1#' diff --git a/lib/ontology.rb b/lib/ontology.rb new file mode 100644 index 0000000..c3952c3 --- /dev/null +++ b/lib/ontology.rb @@ -0,0 +1,55 @@ +module OpenTox + module Ontology + module Echa + require 'sparql/client' + @sparql = SPARQL::Client.new("http://apps.ideaconsult.net:8080/ontology") + def self.qs(classname="Endpoints") + return "PREFIX ot: + PREFIX ota: + PREFIX owl: + PREFIX dc: + PREFIX rdfs: + PREFIX rdf: + PREFIX otee: + PREFIX toxcast: + select * + where { + ?endpoint rdfs:subClassOf otee:#{classname}. + ?endpoint dc:title ?title. + }" + end + + def self.make_option_list(endpoint="Endpoints", level=1) + out = "" + results = @sparql.query(qs(endpoint)) rescue results = [] + results.each do |result| + endpointname = result.Endpoints.to_s.split('#').last + title = result.bound?(:title) ? result.title : endpointname + out += "\n" + out += make_option_list(endpointname, level + 1) + end + return out + end + + def self.get_endpoint_selectlist(include_blank=true) + out = "\n" + return out + end + + def self.endpoints#(endpoint="Endpoints") + endpoint_datasets = {} + RestClientWrapper.get("http://apps.ideaconsult.net:8080/ambit2/query/ndatasets_endpoint",:accept => "text/csv").each do |line| + if line.match(/^http/) + e = line.split(',') + endpoint_datasets["#{e.first} (#{e[1]})"] = RestClientWrapper.get(e.last, :accept => "text/uri-list").split("\n")#[0..e[1].to_i-1] # hack to get only the first count entries + end + end + endpoint_datasets + end + end + + end +end diff --git a/lib/ontology_service.rb b/lib/ontology_service.rb deleted file mode 100644 index 4ff688f..0000000 --- a/lib/ontology_service.rb +++ /dev/null @@ -1,43 +0,0 @@ -module OpenTox - module OntologyService - module Endpoints - require 'sparql/client' - @sparql = SPARQL::Client.new("http://apps.ideaconsult.net:8080/ontology") - def self.qs(classname="Endpoints") - return "PREFIX ot: - PREFIX ota: - PREFIX owl: - PREFIX dc: - PREFIX rdfs: - PREFIX rdf: - PREFIX otee: - PREFIX toxcast: - select ?Endpoints ?title ?id - where {?Endpoints rdfs:subClassOf otee:#{classname}. - OPTIONAL {?Endpoints dc:title ?title}. - OPTIONAL {?Endpoints dc:identifier ?id}.} - ORDER BY ?title" - end - - def self.make_option_list(endpoint="Endpoints", level=1) - out = "" - results = @sparql.query(qs(endpoint)) rescue results = [] - results.each do |result| - endpointname = result.Endpoints.to_s.split('#').last - title = result.bound?(:title) ? result.title : endpointname - out += "\n" - out += make_option_list(endpointname, level + 1) - end - return out - end - - def self.get_endpoint_selectlist(include_blank=true) - out = "\n" - return out - end - end - end -end \ No newline at end of file diff --git a/lib/opentox-ruby.rb b/lib/opentox-ruby.rb index ab8d824..ae05cb2 100644 --- a/lib/opentox-ruby.rb +++ b/lib/opentox-ruby.rb @@ -9,6 +9,6 @@ rescue LoadError end ['opentox', 'compound','dataset', 'parser','serializer', 'algorithm','model','task','validation','feature', - 'rest_client_wrapper', 'authorization', 'policy', 'helper', 'to-html' ].each do |lib| + 'rest_client_wrapper', 'authorization', 'policy', 'helper', 'to-html', 'ontology' ].each do |lib| require lib end -- 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/dataset.rb | 31 +++++++++++------ lib/environment.rb | 2 +- lib/error.rb | 4 +-- lib/feature.rb | 12 ++++++- lib/model.rb | 15 ++++----- lib/ontology.rb | 18 +++++----- lib/opentox.rb | 9 ++++- lib/parser.rb | 11 ++++-- lib/serializer.rb | 2 +- lib/templates/config.yaml | 86 ----------------------------------------------- 10 files changed, 68 insertions(+), 122 deletions(-) delete mode 100644 lib/templates/config.yaml diff --git a/lib/dataset.rb b/lib/dataset.rb index c61d86f..93fce18 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -163,24 +163,33 @@ module OpenTox @features end + def feature_classes(feature) + if Feature.find(feature).feature_type == "classification" + classes = [] + @data_entries.each do |c,e| + e[feature].each { |v| classes << v.to_s } + end + classes.uniq.sort + else + nil + end + end + +=begin # Detect feature type(s) in the dataset # @return [String] `classification", "regression", "mixed" or unknown` def feature_type(subjectid=nil) load_features(subjectid) - feature_types = @features.collect{|f,metadata| metadata[OT.isA]}.uniq - if feature_types.size > 1 - "mixed" + feature_types = @features.collect{|f,metadata| metadata[RDF.type]}.flatten.uniq + if feature_types.include?(OT.NominalFeature) + "classification" + elsif feature_types.include?(OT.NumericFeature) + "regression" else - case feature_types.first - when /NominalFeature/ - "classification" - when /NumericFeature/ - "regression" - else - "unknown" - end + "unknown" end end +=end # Get Spreadsheet representation # @return [Spreadsheet::Workbook] Workbook which can be written with the spreadsheet gem (data_entries only, metadata will will be discarded)) diff --git a/lib/environment.rb b/lib/environment.rb index 57ae014..59578c1 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -74,7 +74,7 @@ CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorizatio CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] -#RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' +RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' OWL = OwlNamespace.new 'http://www.w3.org/2002/07/owl#' DC = OwlNamespace.new 'http://purl.org/dc/elements/1.1/' OT = OwlNamespace.new 'http://www.opentox.org/api/1.1#' diff --git a/lib/error.rb b/lib/error.rb index 7ca9767..b92f2a4 100644 --- a/lib/error.rb +++ b/lib/error.rb @@ -69,7 +69,7 @@ module OpenTox def rdf_content() c = { - RDF.type => OT.ErrorReport, + RDF.type => [OT.ErrorReport], OT.statusCode => @http_code, OT.message => @message, OT.actor => @actor, @@ -96,4 +96,4 @@ class Array end short.join("\n") end -end \ No newline at end of file +end 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 diff --git a/lib/model.rb b/lib/model.rb index 74408d8..422acd2 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -44,11 +44,10 @@ module OpenTox load_metadata(subjectid) if @metadata==nil or @metadata.size==0 or (@metadata.size==1 && @metadata.values[0]==@uri) algorithm = OpenTox::Algorithm::Generic.find(@metadata[OT.algorithm], subjectid) algorithm_title = algorithm ? algorithm.metadata[DC.title] : nil - algorithm_type = algorithm ? algorithm.metadata[OT.isA] : nil + algorithm_type = algorithm ? algorithm.metadata[RDF.type] : nil dependent_variable = OpenTox::Feature.find( @metadata[OT.dependentVariables],subjectid ) dependent_variable_type = dependent_variable ? dependent_variable.feature_type : nil - type_indicators = [dependent_variable_type, @metadata[OT.isA], @metadata[DC.title], - @uri, algorithm_type, algorithm_title] + type_indicators = [dependent_variable_type, @metadata[RDF.type], @metadata[DC.title], @uri, algorithm_type, algorithm_title].flatten type_indicators.each do |type| case type when /(?i)classification/ @@ -187,7 +186,7 @@ module OpenTox if @neighbors.size == 0 @prediction_dataset.add_feature(prediction_feature_uri, { - OT.isA => OT.MeasuredFeature, + RDF.type => [OT.MeasuredFeature], OT.hasSource => @uri, DC.creator => @uri, DC.title => URI.decode(File.basename( @metadata[OT.dependentVariables] )), @@ -198,7 +197,7 @@ module OpenTox else @prediction_dataset.add_feature(prediction_feature_uri, { - OT.isA => OT.ModelPrediction, + RDF.type => [OT.ModelPrediction], OT.hasSource => @uri, DC.creator => @uri, DC.title => URI.decode(File.basename( @metadata[OT.dependentVariables] )), @@ -215,7 +214,7 @@ module OpenTox feature_uri = File.join( @prediction_dataset.uri, "feature", "descriptor", f.to_s) features[feature] = feature_uri @prediction_dataset.add_feature(feature_uri, { - OT.isA => OT.Substructure, + RDF.type => [OT.Substructure], OT.smarts => feature, OT.pValue => @p_values[feature], OT.effect => @effects[feature] @@ -236,7 +235,7 @@ module OpenTox OT.compound => neighbor[:compound], OT.similarity => neighbor[:similarity], OT.measuredActivity => neighbor[:activity], - OT.isA => OT.Neighbor + RDF.type => [OT.Neighbor] }) @prediction_dataset.add @compound.uri, neighbor_uri, true f = 0 unless f @@ -250,7 +249,7 @@ module OpenTox unless features.has_key? feature features[feature] = feature_uri @prediction_dataset.add_feature(feature_uri, { - OT.isA => OT.Substructure, + RDF.type => [OT.Substructure], OT.smarts => feature, OT.pValue => @p_values[feature], OT.effect => @effects[feature] diff --git a/lib/ontology.rb b/lib/ontology.rb index c3952c3..fa4ea6f 100644 --- a/lib/ontology.rb +++ b/lib/ontology.rb @@ -1,6 +1,7 @@ module OpenTox module Ontology module Echa +=begin require 'sparql/client' @sparql = SPARQL::Client.new("http://apps.ideaconsult.net:8080/ontology") def self.qs(classname="Endpoints") @@ -38,17 +39,16 @@ module OpenTox out += "\n" return out end +=end - def self.endpoints#(endpoint="Endpoints") - endpoint_datasets = {} - RestClientWrapper.get("http://apps.ideaconsult.net:8080/ambit2/query/ndatasets_endpoint",:accept => "text/csv").each do |line| - if line.match(/^http/) - e = line.split(',') - endpoint_datasets["#{e.first} (#{e[1]})"] = RestClientWrapper.get(e.last, :accept => "text/uri-list").split("\n")#[0..e[1].to_i-1] # hack to get only the first count entries - end - end - endpoint_datasets + def self.endpoints + RestClientWrapper.get("http://apps.ideaconsult.net:8080/ambit2/query/ndatasets_endpoint",:accept => "text/csv").collect { |line| line.split(',').first if line.match(/^http/) }.compact + end + + def self.datasets(endpoint) + RestClientWrapper.get("http://apps.ideaconsult.net:8080/ambit2/dataset?feature_sameas=#{URI.encode endpoint}", :accept => "text/uri-list").split("\n") end + end end diff --git a/lib/opentox.rb b/lib/opentox.rb index 1992896..c76e21a 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -31,7 +31,14 @@ module OpenTox end def add_metadata(metadata) - metadata.each { |k,v| @metadata[k] = v } + metadata.each do |k,v| + if v.is_a? Array + @metadata[k] = [] unless @metadata[k] + @metadata[k] << v + else + @metadata[k] = v + end + end end # Get OWL-DL representation in RDF/XML format diff --git a/lib/parser.rb b/lib/parser.rb index f33017d..cc5f1c8 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -55,7 +55,14 @@ module OpenTox parameter_ids = [] `rapper -i rdfxml -o ntriples #{file.path} 2>/dev/null`.each_line do |line| triple = line.to_triple - @metadata[triple[1]] = triple[2].split('^^').first if triple[0] == @uri and triple[1] != RDF['type'] + if triple[0] == @uri + if triple[1] == RDF.type # allow multiple types + @metadata[triple[1]] = [] unless @metadata[triple[1]] + @metadata[triple[1]] << triple[2].split('^^').first + else + @metadata[triple[1]] = triple[2].split('^^').first + end + end statements << triple parameter_ids << triple[2] if triple[1] == OT.parameters end @@ -289,7 +296,7 @@ module OpenTox else type = types.first end - @dataset.add_feature_metadata(feature,{OT.isA => type}) + @dataset.add_feature_metadata(feature,{RDF.type => [type]}) info += "\"#{@dataset.feature_name(feature)}\" detected as #{type.split('#').last}." # TODO: rewrite feature values diff --git a/lib/serializer.rb b/lib/serializer.rb index 44b4414..644a09f 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -67,7 +67,7 @@ module OpenTox DC.creator => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , DC.description => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , DC.date => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , - OT.isA => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , + #OT.isA => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , OT.Warnings => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , XSD.anyURI => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , OT.hasStatus => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , diff --git a/lib/templates/config.yaml b/lib/templates/config.yaml deleted file mode 100644 index 8a5e460..0000000 --- a/lib/templates/config.yaml +++ /dev/null @@ -1,86 +0,0 @@ -# Example configuration for OpenTox, please adjust to your settings -# -# Database setup: -# -# Example MySql: -# -:database: - :adapter: mysql - :database: production - :username: root - :password: opentox - :host: localhost -# -# Example 1: Using external test services -# -# :services: -# opentox-compound: "http://webservices.in-silico.ch/compound/" -# opentox-dataset: "http://webservices.in-silico.ch/dataset/" -# opentox-algorithm: "http://webservices.in-silico.ch/algorithm/" -# opentox-model: "http://webservices.in-silico.ch/model/" -# opentox-task: "http://webservices.in-silico.ch/task/" -# opentox-validation: "http://opentox.informatik.uni-freiburg.de/validation/" -# -# Example 2: Using local services -:base_dir: /home/ist/webservices -:webserver: passenger -:services: - opentox-compound: "http://localhost/compound/" - opentox-dataset: "http://localhost/dataset/" - opentox-algorithm: "http://localhost/algorithm/" - opentox-model: "http://localhost/model/" - opentox-task: "http://localhost/task/" - opentox-validation: "http://localhost/validation/" -# -# Yaml capable hosts (faster than OWL-DL) -# -:yaml_hosts: - - "localhost" - -# Uncomment for verbose logging -# :logger: debug -# :backtrace: 1 - - -# OpenSSO Authorization -# set ":server: " to disable A&A -:authorization: - :server: "https://opensso.in-silico.ch" - :free_request: #request-method not controlled by A&A - - "GET" - :authenticate_request: #only for authenticated user - - "POST" - :authorize_request: #only for authenticated and authorizeduser - - "DELETE" - - "PUT" - # Exceptions: - :free_uris: #request-method for uri not controlled by A&A - ? - :GET - : - !ruby/regexp /localhost\/algorithm/ - - "http://localhost/dataset" - - "http://localhost/model" - - "http://localhost/validation" - - "http://localhost/validation/crossvalidation" - - "http://localhost/validation/reach_report" - - "http://localhost/validation/reach_report/crossvalidation" - - "http://localhost/validation/report" - - "http://localhost/validation/report/crossvalidation" - - "http://localhost/validation/reach_report/qmrf" - ? - :GET - - :POST - : - !ruby/regexp /localhost\/toxcreate/ - - !ruby/regexp /localhost\/task/ - - !ruby/regexp /localhost\/compound/ - ? - :PUT - : - !ruby/regexp /localhost\/task/ - - :authorize_exceptions: #request-method for uri only authenticated, no authorization - ? - :POST - : - !ruby/regexp /localhost\/algorithm/ - - "http://localhost/dataset" - - "http://localhost/model" - - "http://localhost/validation" - - !ruby/regexp /localhost\/validation\/[a-z,A-Z,\/,_\-]*$/ - - - \ No newline at end of file -- cgit v1.2.3 From 80c2562c0f84f65b0e3ed02c3293c530d0dc4ce2 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 5 Apr 2011 19:12:04 +0200 Subject: Parser.load_features fixed for Substructures --- lib/parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parser.rb b/lib/parser.rb index cc5f1c8..db746c1 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -230,7 +230,7 @@ module OpenTox `rapper -i rdfxml -o ntriples #{file.path} 2>/dev/null`.each_line do |line| triple = line.chomp.split('> ').collect{|i| i.sub(/\s+.$/,'').gsub(/[<>"]/,'')}[0..2] statements << triple - features << triple[0] if triple[1] == RDF['type'] and (triple[2] == OT.Feature || triple[2] == OT.NumericFeature) + features << triple[0] if triple[1] == RDF.type and (triple[2] =~ /Feature|Substructure/) end File.delete(to_delete) if to_delete statements.each do |triple| -- cgit v1.2.3 From a12f491fc42b058168fb43b32e8769694e821658 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 6 Apr 2011 09:59:04 +0200 Subject: A&A fixes, code cleaning --- lib/algorithm.rb | 2 +- lib/helper.rb | 57 +++++++++++++++++++++++++++++--------------------------- lib/model.rb | 3 ++- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index c8cb116..167c964 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -246,7 +246,7 @@ module OpenTox # Gauss kernel # @return [Float] def self.gauss(x, sigma = 0.3) - d = 1.0 - x + d = 1.0 - x.to_f Math.exp(-(d*d)/(2*sigma*sigma)) end diff --git a/lib/helper.rb b/lib/helper.rb index 3031b74..af92419 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -55,10 +55,7 @@ helpers do end end -end - -before do - unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD']) + def get_subjectid begin subjectid = nil subjectid = session[:subjectid] if session[:subjectid] @@ -69,31 +66,37 @@ before do subjectid = CGI.unescape(subjectid) if subjectid.include?("%23") @subjectid = subjectid rescue - #LOGGER.debug "OpenTox ruby api wrapper: helper before filter: NO subjectid for URI: #{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}" - subjectid = "" + subjectid = nil end - @subjectid = subjectid - protected!(subjectid) - - extension = File.extname(request.path_info) # params[:id] is not yet available + end + def get_extension + extension = File.extname(request.path_info) unless extension.empty? - #request.path_info.sub!(/\.#{extension}$/,'') - case extension - when "html" - @accept = 'text/html' - when "yaml" - @accept = 'application/x-yaml' - when "csv" - @accept = 'text/csv' - when "rdfxml" - @accept = 'application/rdf+xml' - when "xls" - @accept = 'application/ms-excel' - else - halt 404, "File format #{extension} not supported." - end - end - + case extension.gsub(".","") + when "html" + @accept = 'text/html' + when "yaml" + @accept = 'application/x-yaml' + when "csv" + @accept = 'text/csv' + when "rdfxml" + @accept = 'application/rdf+xml' + when "xls" + @accept = 'application/ms-excel' + when "css" + @accept = 'text/css' + else + # halt 404, "File format #{extension} not supported." + end + end + end +end + +before do + @subjectid = get_subjectid() + @accept = get_extension() + unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD']) + protected!(@subjectid) end end diff --git a/lib/model.rb b/lib/model.rb index 74408d8..c46f2a0 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -113,9 +113,10 @@ module OpenTox # @param [optional,Hash] params Parameters for the lazar algorithm (OpenTox::Algorithm::Lazar) # @return [OpenTox::Model::Lazar] lazar model def self.create(params) + subjectid = params[:subjectid] lazar_algorithm = OpenTox::Algorithm::Generic.new File.join( CONFIG[:services]["opentox-algorithm"],"lazar") model_uri = lazar_algorithm.run(params) - OpenTox::Model::Lazar.find(model_uri, params[:subjectid]) + OpenTox::Model::Lazar.find(model_uri, subjectid) end # Get a parameter value -- cgit v1.2.3 From d0a2babc27dd0545c0a8a9465dd03ae247151aa4 Mon Sep 17 00:00:00 2001 From: mr Date: Fri, 8 Apr 2011 15:37:01 +0200 Subject: A&A fixes --- lib/dataset.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index 93fce18..0a2f770 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -163,8 +163,8 @@ module OpenTox @features end - def feature_classes(feature) - if Feature.find(feature).feature_type == "classification" + def feature_classes(feature, subjectid=nil) + if Feature.find(feature, subjectid).feature_type == "classification" classes = [] @data_entries.each do |c,e| e[feature].each { |v| classes << v.to_s } -- cgit v1.2.3 From 796614bf4431d3560d6aae69de4793bdfa5a7b51 Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 21 Apr 2011 13:27:53 +0200 Subject: subjectids for load_metadata in algorithm.rb and list_policies_uris changes in A&A --- lib/algorithm.rb | 12 ++++++------ lib/authorization.rb | 15 +++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 167c964..54ca064 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -52,9 +52,9 @@ module OpenTox class BBRC include Fminer # Initialize bbrc algorithm - def initialize + def initialize(subjectid=nil) super File.join(CONFIG[:services]["opentox-algorithm"], "fminer/bbrc") - load_metadata + load_metadata(subjectid) end end @@ -62,9 +62,9 @@ module OpenTox class LAST include Fminer # Initialize last algorithm - def initialize + def initialize(subjectid=nil) super File.join(CONFIG[:services]["opentox-algorithm"], "fminer/last") - load_metadata + load_metadata(subjectid) end end @@ -74,9 +74,9 @@ module OpenTox class Lazar include Algorithm # Initialize lazar algorithm - def initialize + def initialize(subjectid=nil) super File.join(CONFIG[:services]["opentox-algorithm"], "lazar") - load_metadata + load_metadata(subjectid) end end diff --git a/lib/authorization.rb b/lib/authorization.rb index eab20df..d9f900b 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -137,16 +137,23 @@ module OpenTox # Lists policies alongside with affected uris # @param [String] subjectid # @return [Hash] keys: all policies of the subjectid owner, values: uris affected by those policies - def self.list_policy_uris( subjectid ) + def self.list_policies_uris( subjectid ) names = list_policies(subjectid) policies = {} names.each do |n| - p = OpenTox::Policies.new - p.load_xml( list_policy(n, subjectid) ) - policies[n] = p.uris + policies[n] = list_policy_uris( n, subjectid ) end policies end + + # Lists policies alongside with affected uris + # @param [String] subjectid + # @return [Hash] keys: all policies of the subjectid owner, values: uris affected by those policies + def self.list_policy_uris( policy, subjectid ) + p = OpenTox::Policies.new + p.load_xml( list_policy(policy, subjectid) ) + p.uris + end #Returns the owner (who created the first policy) of an URI # @param [String, String]uri,subjectid -- cgit v1.2.3 From 60d48b6a31fdc9aa80243d2e1e072f069bdc2799 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Thu, 28 Apr 2011 03:55:53 -0700 Subject: Removed redis-server start call. --- lib/environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/environment.rb b/lib/environment.rb index 59578c1..ffc4f60 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -23,7 +23,7 @@ else end # database -`redis-server /opt/redis/redis.conf` unless File.exists? "/var/run/redis.pid" +#`redis-server /opt/redis/redis.conf` unless File.exists? "/var/run/redis.pid" # removed by AM Ohm.connect :thread_safe => true # load mail settings for error messages -- cgit v1.2.3 From 5f62bb414dc8345c416623c9435779c16c21c189 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 3 May 2011 14:34:03 +0200 Subject: add validation gems to opentox-ruby --- Rakefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 215aeb2..3d8f2d5 100644 --- a/Rakefile +++ b/Rakefile @@ -30,7 +30,16 @@ begin "ohm", "ohm-contrib", "SystemTimer", - "rjb" + "rjb", + #valiation-gems + "dm-core", + "dm-serializer", + "dm-timestamps", + "dm-types", + "dm-migrations", + "dm-validations", + "dm-sqlite-adapter", + "benchmark" ].each { |dep| gem.add_dependency dep } =begin [ "dm-core", @@ -42,7 +51,10 @@ begin "dm-validations", ].each {|dep| gem.add_dependency dep, ">= 1" } =end + #valiation-gem gem.add_dependency "haml", ">=3" + # validation-gems + gem.add_dependency "ruby-plot", "=0.0.2" ['jeweler'].each { |dep| gem.add_development_dependency dep } gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] end -- cgit v1.2.3 From c4d63fc2430caaed39e230e14db7e043642fbd50 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 3 May 2011 15:26:52 +0200 Subject: remove not-existing gem benchmark --- Rakefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 3d8f2d5..d238a5b 100644 --- a/Rakefile +++ b/Rakefile @@ -38,8 +38,7 @@ begin "dm-types", "dm-migrations", "dm-validations", - "dm-sqlite-adapter", - "benchmark" + "dm-sqlite-adapter" ].each { |dep| gem.add_dependency dep } =begin [ "dm-core", -- cgit v1.2.3 From 612db56ce522a632414158917c2462fe40c242dc Mon Sep 17 00:00:00 2001 From: mguetlein Date: Wed, 4 May 2011 15:27:01 +0200 Subject: use task-status-code from task-service (to fix inconsistent task status codes) --- lib/overwrite.rb | 14 +++++++++----- lib/task.rb | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/overwrite.rb b/lib/overwrite.rb index fbe775d..fffcb14 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -39,20 +39,24 @@ end class Sinatra::Base def return_task( task ) - code = task.running? ? 202 : 200 + raise "http_code == nil" unless task.http_code!=nil case request.env['HTTP_ACCEPT'] when /rdf/ response['Content-Type'] = "application/rdf+xml" - halt code,task.to_rdfxml + halt task.http_code,task.to_rdfxml when /yaml/ response['Content-Type'] = "application/x-yaml" - halt code,task.to_yaml # PENDING differs from task-webservice + halt task.http_code,task.to_yaml # PENDING differs from task-webservice when /html/ response['Content-Type'] = "text/html" - halt code,OpenTox.text_to_html(task.to_yaml, @subjectid) + halt task.http_code,OpenTox.text_to_html(task.to_yaml, @subjectid) else # default /uri-list/ response['Content-Type'] = "text/uri-list" - halt code,task.uri+"\n" + if task.completed? + halt task.http_code,task.resultURI+"\n" + else + halt task.http_code,task.uri+"\n" + end end end end diff --git a/lib/task.rb b/lib/task.rb index 0ee3a11..19f42d6 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -8,6 +8,7 @@ module OpenTox def initialize(uri=nil) super uri + @http_code = 202 @metadata = { DC.title => "", DC.date => "", @@ -154,6 +155,7 @@ module OpenTox # not stored just for to_rdf def add_error_report( error_report ) + raise "not an error report: "+error_report.class.to_s unless error_report.is_a?(ErrorReport) @error_report = error_report end -- cgit v1.2.3 From 435540f4be8787e0c34a64a2d2d7ed3118be9de9 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Thu, 5 May 2011 07:17:04 +0200 Subject: Fixed activity output --- lib/algorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 54ca064..008e7fe 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -215,7 +215,7 @@ module OpenTox LOGGER.debug "Predicting ..." @r.eval "p<-predict(model,sims)[1,1]" prediction = 10**(@r.p.to_f) - LOGGER.debug "Prediction is: '" + @prediction.to_s + "'." + LOGGER.debug "Prediction is: '" + prediction.to_s + "'." @r.quit # free R end confidence = conf/neighbors.size if neighbors.size > 0 -- cgit v1.2.3 From 0edca0616624ab9711b3791bbb7697a676e0b141 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 6 May 2011 17:01:27 +0200 Subject: fix specificity (was 1-specificity) in cv-summary, (added training-test-split to validation object) --- lib/validation.rb | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/validation.rb b/lib/validation.rb index a47a554..8fa95bb 100644 --- a/lib/validation.rb +++ b/lib/validation.rb @@ -12,6 +12,29 @@ module OpenTox val end + # creates a training test split validation, waits until it finishes, may take some time + # @param [Hash] params (required:algorithm_uri,dataset_uri,prediction_feature, optional:algorithm_params,split_ratio(0.67),random_seed(1)) + # @param [String,optional] subjectid + # @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly + # @return [OpenTox::Validation] + def self.create_training_test_split( params, subjectid=nil, waiting_task=nil ) + params[:subjectid] = subjectid if subjectid + uri = OpenTox::RestClientWrapper.post( File.join(CONFIG[:services]["opentox-validation"],"training_test_split"), + params,{:content_type => "text/uri-list"},waiting_task ) + Validation.new(uri) + end + + # looks for report for this validation, creates a report if no report is found + # @param [String,optional] subjectid + # @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly + # @return [String] report uri + def find_or_create_report( subjectid=nil, waiting_task=nil ) + @report = ValidationReport.find_for_validation(@uri, subjectid) unless @report + @report = ValidationReport.create(@uri, subjectid, waiting_task) unless @report + @report.uri + end + + # creates a validation object from crossvaldiation statistics, raise error if not found # (as crossvaldiation statistics are returned as an average valdidation over all folds) # @param [String] crossvalidation uri @@ -42,7 +65,7 @@ module OpenTox res[:true_negatives] = s[OT.numTrueNegatives] res[:false_negatives] = s[OT.numFalseNegatives] res[:sensitivity] = s[OT.truePositiveRate] - res[:specificity] = s[OT.falsePositiveRate] + res[:specificity] = s[OT.trueNegativeRate] break end end @@ -110,6 +133,16 @@ module OpenTox class ValidationReport include OpenTox + # finds ValidationReport via uri, raises error if not found + # @param [String] uri + # @param [String,optional] subjectid + # @return [OpenTox::ValidationReport] + def self.find( uri, subjectid=nil ) + # PENDING load report data? + OpenTox::RestClientWrapper.get(uri,{:subjectid => subjectid}) + ValidationReport.new(uri) + end + # finds ValidationReport for a particular validation # @param [String] crossvalidation uri # @param [String,optional] subjectid @@ -120,6 +153,17 @@ module OpenTox uris.size==0 ? nil : ValidationReport.new(uris[-1]) end + # creates a validation report via validation + # @param [String] validation uri + # @param [String,optional] subjectid + # @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly + # @return [OpenTox::ValidationReport] + def self.create( validation_uri, subjectid=nil, waiting_task=nil ) + uri = RestClientWrapper.post(File.join(CONFIG[:services]["opentox-validation"],"/report/validation"), + { :validation_uris => validation_uri, :subjectid => subjectid }, {}, waiting_task ) + ValidationReport.new(uri) + end + end class CrossvalidationReport -- cgit v1.2.3 From b893941bc58260e2dd88d6d78433b65ba1dbe45b Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 6 May 2011 19:28:20 +0200 Subject: minor fixes: missing-values when splitting datasets, timeout handled in rest-client-wrapper --- lib/dataset.rb | 2 +- lib/rest_client_wrapper.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index 0a2f770..2b5759e 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -293,7 +293,7 @@ module OpenTox else compounds.each do |c| features.each do |f| - unless @data_entries[c][f] + if @data_entries[c]==nil or @data_entries[c][f]==nil dataset.add(c,f,nil) else @data_entries[c][f].each do |v| diff --git a/lib/rest_client_wrapper.rb b/lib/rest_client_wrapper.rb index dac24dc..747a353 100644 --- a/lib/rest_client_wrapper.rb +++ b/lib/rest_client_wrapper.rb @@ -98,6 +98,8 @@ module OpenTox rescue RestClient::RequestTimeout => ex received_error ex.message, 408, nil, {:rest_uri => uri, :headers => headers, :payload => payload} + rescue Errno::ETIMEDOUT => ex + received_error ex.message, 408, nil, {:rest_uri => uri, :headers => headers, :payload => payload} rescue Errno::ECONNREFUSED => ex received_error ex.message, 500, nil, {:rest_uri => uri, :headers => headers, :payload => payload} rescue RestClient::ExceptionWithResponse => ex -- 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 ------------- lib/parser.rb | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 25 deletions(-) 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 diff --git a/lib/parser.rb b/lib/parser.rb index db746c1..7bdee95 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -163,6 +163,7 @@ module OpenTox data = {} feature_values = {} feature = {} + feature_accept_values = {} other_statements = {} `rapper -i rdfxml -o ntriples #{file.path} 2>/dev/null`.each_line do |line| triple = line.chomp.split(' ',3) @@ -182,6 +183,9 @@ module OpenTox if triple[2]=~/#{OT.Compound}/i and !data[triple[0]] data[triple[0]] = {:compound => triple[0], :values => []} end + when /#{OT.acceptValue}/i # acceptValue in ambit datasets is only provided in dataset/ no in dataset//features + feature_accept_values[triple[0]] = [] unless feature_accept_values[triple[0]] + feature_accept_values[triple[0]] << triple[2] else end end @@ -192,20 +196,25 @@ module OpenTox @dataset.add_compound(entry[:compound]) else entry[:values].each do |value_id| - split = feature_values[value_id].split(/\^\^/) - case split[-1] - when XSD.double, XSD.float - value = split.first.to_f - when XSD.boolean - value = split.first=~/(?i)true/ ? true : false - else - value = split.first + if feature_values[value_id] + split = feature_values[value_id].split(/\^\^/) + case split[-1] + when XSD.double, XSD.float + value = split.first.to_f + when XSD.boolean + value = split.first=~/(?i)true/ ? true : false + else + value = split.first + end end @dataset.add entry[:compound],feature[value_id],value end end end load_features subjectid + feature_accept_values.each do |feature, values| + @dataset.features[feature][OT.acceptValue] = values + end @dataset.metadata = load_metadata(subjectid) @dataset end @@ -348,16 +357,23 @@ module OpenTox when OT.NominalFeature case value.to_s when TRUE_REGEXP - @dataset.add(compound.uri, feature, true ) + val = true when FALSE_REGEXP - @dataset.add(compound.uri, feature, false ) + val = false end when OT.NumericFeature - @dataset.add compound.uri, feature, value.to_f + val = value.to_f when OT.StringFeature - @dataset.add compound.uri, feature, value.to_s + val = value.to_s @activity_errors << smiles+", "+row.join(", ") end + if val!=nil + @dataset.add(compound.uri, feature, val) + if type!=OT.NumericFeature + @dataset.features[feature][OT.acceptValue] = [] unless @dataset.features[feature][OT.acceptValue] + @dataset.features[feature][OT.acceptValue] << val.to_s unless @dataset.features[feature][OT.acceptValue].include?(val.to_s) + end + end end end -- cgit v1.2.3 From 4d8ca4a4d057a197dbfe34e16950ea5433e9819a Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 9 May 2011 14:01:44 +0200 Subject: add list method to validation and crossvalidation objects --- lib/validation.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/validation.rb b/lib/validation.rb index 8fa95bb..08dc4ab 100644 --- a/lib/validation.rb +++ b/lib/validation.rb @@ -12,6 +12,18 @@ module OpenTox val end + # returns a filtered list of validation uris + # @param [Hash,optional] params, validation-params to filter the uris (could be model, training_dataset, ..) + # @return [Array] + def self.list( params={} ) + filter_string = "" + params.each do |k,v| + filter_string = "?" if filter_string.length==0 + filter_string += k.to_s+"="+v + end + (OpenTox::RestClientWrapper.get(CONFIG[:services]["opentox-validation"]+filter_string).split("\n")) + end + # creates a training test split validation, waits until it finishes, may take some time # @param [Hash] params (required:algorithm_uri,dataset_uri,prediction_feature, optional:algorithm_params,split_ratio(0.67),random_seed(1)) # @param [String,optional] subjectid @@ -95,6 +107,18 @@ module OpenTox cv.load_metadata( subjectid ) cv end + + # returns a filtered list of crossvalidation uris + # @param [Hash,optional] params, crossvalidation-params to filter the uris (could be algorithm, dataset, ..) + # @return [Array] + def self.list( params={} ) + filter_string = "" + params.each do |k,v| + filter_string = "?" if filter_string.length==0 + filter_string += k.to_s+"="+v + end + (OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"],"crossvalidation")+filter_string).split("\n")) + end # creates a crossvalidations, waits until it finishes, may take some time # @param [Hash] params (required:algorithm_uri,dataset_uri,prediction_feature, optional:algorithm_params,num_folds(10),random_seed(1),stratified(false)) -- cgit v1.2.3 From 88af0ff8e54406f6bd4322a2d0ea93ade2c5bbbd Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 9 May 2011 05:53:45 -0700 Subject: Hotfix: Gaussian Decay for neighbors --- lib/algorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 008e7fe..abf10d4 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -165,7 +165,7 @@ module OpenTox # @param [Hash] params Keys `:similarity_algorithm,:p_values` are required # @return [Hash] Hash with keys `:prediction, :confidence` def self.local_svm_regression(neighbors,params ) - sims = neighbors.collect{ |n| n[:similarity] } # similarity values between query and neighbors + sims = neighbors.collect{ |n| Algorithm.gauss(n[:similarity]) } # similarity values between query and neighbors conf = sims.inject{|sum,x| sum + x } acts = neighbors.collect do |n| act = n[:activity] -- cgit v1.2.3 From 51cb900375a575208cd210da5093773d9e10cfdd Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 10 May 2011 12:23:19 +0200 Subject: minor fix: load metadata when 'find'ing a report in validation.rb --- lib/validation.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/validation.rb b/lib/validation.rb index 08dc4ab..d58d36e 100644 --- a/lib/validation.rb +++ b/lib/validation.rb @@ -46,7 +46,6 @@ module OpenTox @report.uri end - # creates a validation object from crossvaldiation statistics, raise error if not found # (as crossvaldiation statistics are returned as an average valdidation over all folds) # @param [String] crossvalidation uri @@ -162,9 +161,10 @@ module OpenTox # @param [String,optional] subjectid # @return [OpenTox::ValidationReport] def self.find( uri, subjectid=nil ) - # PENDING load report data? OpenTox::RestClientWrapper.get(uri,{:subjectid => subjectid}) - ValidationReport.new(uri) + rep = ValidationReport.new(uri) + rep.load_metadata( subjectid ) + rep end # finds ValidationReport for a particular validation @@ -200,7 +200,9 @@ module OpenTox def self.find( uri, subjectid=nil ) # PENDING load report data? OpenTox::RestClientWrapper.get(uri,{:subjectid => subjectid}) - CrossvalidationReport.new(uri) + rep = CrossvalidationReport.new(uri) + rep.load_metadata( subjectid ) + rep end # finds CrossvalidationReport for a particular crossvalidation -- cgit v1.2.3 From c6d34021f92610ff7dfcc72473c09ba08586687a Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 12 May 2011 12:39:47 +0200 Subject: set accept-header via html-param ?media=asdf (analogous to ambits services) --- lib/overwrite.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/overwrite.rb b/lib/overwrite.rb index fffcb14..df4e1b7 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -8,6 +8,7 @@ before { $url_provider = self # stupid internet explorer does not ask for text/html, add this manually request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/ + request.env['HTTP_ACCEPT']=request.params["media"] if request.params["media"] } # Error handling -- cgit v1.2.3 From 8dd7fb5b440d02e6c2aea2d63ced2badc9b680f7 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 12 May 2011 12:41:32 +0200 Subject: move to ruby-plot version 0.0.3 --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index d238a5b..eb6504c 100644 --- a/Rakefile +++ b/Rakefile @@ -53,7 +53,7 @@ begin #valiation-gem gem.add_dependency "haml", ">=3" # validation-gems - gem.add_dependency "ruby-plot", "=0.0.2" + gem.add_dependency "ruby-plot", "=0.0.3" ['jeweler'].each { |dep| gem.add_development_dependency dep } gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] end -- cgit v1.2.3 From cb3c1dd486ba0a891c81886c1546553fc17f01b8 Mon Sep 17 00:00:00 2001 From: ch Date: Thu, 12 May 2011 16:58:14 +0000 Subject: RDF serialization of metadata fixed for multiple RDF.types --- lib/serializer.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/serializer.rb b/lib/serializer.rb index 644a09f..e4cb541 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -26,6 +26,8 @@ module OpenTox OT.Algorithm => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.Parameter => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.Task => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , + OTA.PatternMiningSupervised => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , + #classes for validation OT.Validation => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.ClassificationStatistics => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , @@ -40,10 +42,10 @@ module OpenTox OT.compound => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.feature => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.dataEntry => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , - OT.acceptValue => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.values => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.algorithm => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.parameters => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , + #object props for validation# OT.model => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.trainingDataset => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , @@ -73,6 +75,8 @@ module OpenTox OT.hasStatus => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , OT.resultURI => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , OT.percentageCompleted => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , + OT.acceptValue => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , + # annotation props for validation OT.numUnpredicted => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , OT.crossvalidationFold => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , @@ -256,7 +260,8 @@ module OpenTox def add_metadata(uri,metadata) id = 0 metadata.each do |u,v| - if v.is_a? Array and u == OT.parameters + #if v.is_a? Array and (u == OT.parameters or u == RDF.type) + if v.is_a? Array and u == OT.parameters#or u == RDF.type) @object[uri][u] = [] unless @object[uri][u] v.each do |value| id+=1 @@ -267,7 +272,13 @@ module OpenTox @object[genid][name] = [{"type" => type(entry), "value" => entry }] end end - else # v.is_a? String + elsif v.is_a? Array and u == RDF.type + @object[uri] = {} unless @object[uri] + v.each do |value| + @object[uri][u] = [] unless @object[uri][u] + @object[uri][u] << {"type" => type(value), "value" => value } + end + elsif v.is_a? String @object[uri] = {} unless @object[uri] @object[uri][u] = [{"type" => type(v), "value" => v }] end @@ -309,6 +320,7 @@ module OpenTox OT.value => v } @object[feature][RDF["type"]] << { "type" => "uri", "value" => featuretype(value) } + #@object[feature][RDF["type"]] = { "type" => "uri", "value" => featuretype(value) } end # Serializers -- cgit v1.2.3 From 2919ffefd4b762038d0dcb44ea64aa621674fff8 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 13 May 2011 08:58:56 +0200 Subject: reduce ruby-plot dependency to pessimistic version vonstraint (~>) --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index eb6504c..b2298e6 100644 --- a/Rakefile +++ b/Rakefile @@ -53,7 +53,7 @@ begin #valiation-gem gem.add_dependency "haml", ">=3" # validation-gems - gem.add_dependency "ruby-plot", "=0.0.3" + gem.add_dependency "ruby-plot", "~>0.3.0" ['jeweler'].each { |dep| gem.add_development_dependency dep } gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] end -- cgit v1.2.3 From 153a19bc26e1a9dac35d286b90037bfc9d0e9c6b Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 13 May 2011 11:46:08 +0200 Subject: catch nil error if delete with subjectid but without AA_SERVER is called --- lib/authorization.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/authorization.rb b/lib/authorization.rb index d9f900b..b23b92f 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -286,10 +286,12 @@ module OpenTox # @return [Boolean] def self.delete_policies_from_uri(uri, subjectid) policies = list_uri_policies(uri, subjectid) - policies.each do |policy| - ret = delete_policy(policy, subjectid) - LOGGER.debug "OpenTox::Authorization delete policy: #{policy} - with result: #{ret}" - end + if policies + policies.each do |policy| + ret = delete_policy(policy, subjectid) + LOGGER.debug "OpenTox::Authorization delete policy: #{policy} - with result: #{ret}" + end + end return true end -- cgit v1.2.3 From a494bcca5a51466191dcb4b3dd5101f21916a0cb Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 16 May 2011 14:47:37 +0200 Subject: move to ruby-plot 0.4 -> confidence values --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index b2298e6..08959b0 100644 --- a/Rakefile +++ b/Rakefile @@ -53,7 +53,7 @@ begin #valiation-gem gem.add_dependency "haml", ">=3" # validation-gems - gem.add_dependency "ruby-plot", "~>0.3.0" + gem.add_dependency "ruby-plot", "~>0.4.0" ['jeweler'].each { |dep| gem.add_development_dependency dep } gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] end -- cgit v1.2.3 From 5acd3b8cd36a0f5017e4858df3d4516876858324 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 16 May 2011 15:53:03 +0200 Subject: remove internal administrative LDAP groups --- lib/authorization.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/authorization.rb b/lib/authorization.rb index b23b92f..288733a 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -227,7 +227,9 @@ module OpenTox begin resource = RestClient::Resource.new("#{AA_SERVER}/opensso/identity/search") grps = resource.post(:admin => subjectid, :attributes_names => "objecttype", :attributes_values_objecttype => "group") - grps.split("\n").collect{|x| x.sub("string=","")} + grps = grps.split("\n").collect{|x| x.sub("string=","")} + grps.delete_if{|g|g=="MemberManagement"||g=="Webmasters"} + grps rescue [] end -- cgit v1.2.3 From 778df38c0991aef8de53702e8c6229dd6f43d1a2 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 16 May 2011 14:44:30 +0000 Subject: uri_available? fixed in helper.rb --- lib/helper.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/helper.rb b/lib/helper.rb index af92419..3a6126a 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -44,14 +44,8 @@ helpers do def uri_available?(urlStr) url = URI.parse(urlStr) - unless @subjectid - Net::HTTP.start(url.host, url.port) do |http| - return http.head(url.request_uri).code == "200" - end - else - Net::HTTP.start(url.host, url.port) do |http| - return http.post(url.request_uri, "subjectid=#{@subjectid}").code == "202" - end + Net::HTTP.start(url.host, url.port) do |http| + return http.head("#{url.request_uri}?subjectid=#{CGI.escape @subjectid}").code == "200" end end -- cgit v1.2.3 From 5c6cb977db89b12ddeb822eb09370c9ad32ad84b Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 16 May 2011 16:50:13 +0200 Subject: Fixed log taking (for exclusively positive values only) --- lib/algorithm.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index abf10d4..130d305 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -167,9 +167,17 @@ module OpenTox def self.local_svm_regression(neighbors,params ) sims = neighbors.collect{ |n| Algorithm.gauss(n[:similarity]) } # similarity values between query and neighbors conf = sims.inject{|sum,x| sum + x } + + # AM: Control log taking + take_logs=true + neighbors.each do |n| + if (! n[:activity].nil?) && (n[:activity].to_f < 0.0) + take_logs = false + end + end acts = neighbors.collect do |n| act = n[:activity] - Math.log10(act.to_f) + take_logs ? Math.log10(act.to_f) : act.to_f end # activities of neighbors for supervised learning neighbor_matches = neighbors.collect{ |n| n[:features] } # as in classification: URIs of matches -- cgit v1.2.3 From b247527ced213486629add9d8b5b739620a8abff Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 16 May 2011 17:28:59 +0200 Subject: Fixed exp --- lib/algorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 130d305..7fbe0dc 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -222,7 +222,7 @@ module OpenTox @r.eval "sims<-as.kernelMatrix(matrix(sims,1))" LOGGER.debug "Predicting ..." @r.eval "p<-predict(model,sims)[1,1]" - prediction = 10**(@r.p.to_f) + prediction = 10**(@r.p.to_f) if take_logs LOGGER.debug "Prediction is: '" + prediction.to_s + "'." @r.quit # free R end -- cgit v1.2.3 From 0902a4a0b2d83d167277b82fcfd9cc12c0b993a9 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 23 May 2011 13:00:00 +0200 Subject: Version bump to 2.0.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index e6d5cb8..359a5b9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 \ No newline at end of file +2.0.0 \ No newline at end of file -- cgit v1.2.3