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