From ca2e240e03a4e458f83281c28b529e44af81d132 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sat, 19 Dec 2009 13:28:55 +0100 Subject: OWL-DL for fminer and datasets fixed --- lib/dataset.rb | 167 +++++------- lib/opentox.owl | 809 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/owl.rb | 8 +- 3 files changed, 885 insertions(+), 99 deletions(-) create mode 100644 lib/opentox.owl diff --git a/lib/dataset.rb b/lib/dataset.rb index b96f3e9..225b900 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -7,17 +7,57 @@ module OpenTox super end - def add(compound_uri,feature_uri,value) - c = self.find_or_create_compound compound_uri - f = self.find_or_create_feature feature_uri - v = self.find_or_create_value value - self.add_data_entry(c,f,v) + # create/add to entry from uris or Redland::Resources + # TODO add tuple + def add(compound,feature,value) + compound = self.find_or_create_compound compound unless compound.class == Redland::Resource + feature = self.find_or_create_feature feature unless feature.class == Redland::Resource + data_entry = @model.subject OT['compound'], compound + if data_entry.nil? + data_entry = @model.create_resource + @model.add data_entry, RDF['type'], OT["DataEntry"] + @model.add data_entry, OT['compound'], compound + end + values = @model.create_resource + @model.add data_entry, OT['values'], values + @model.add values, RDF['type'], OT['FeatureValue'] + @model.add values, OT['feature'], feature + @model.add values, OT['value'], value.to_s + end + + def add_tuple(compound,tuple) + compound = self.find_or_create_compound compound unless compound.class == Redland::Resource + data_entry = @model.subject OT['compound'], compound + if data_entry.nil? + data_entry = @model.create_resource + @model.add data_entry, RDF['type'], OT["DataEntry"] + @model.add data_entry, OT['compound'], compound + end + @model.add data_entry, OT['values'], tuple + end + + def create_tuple(feature,t) + feature = self.find_or_create_feature feature unless feature.class == Redland::Resource + tuple = @model.create_resource + @model.add tuple, RDF['type'], OT["Tuple"] + @model.add tuple, OT['feature'], feature + t.each do |name,value| + f = self.find_or_create_feature name unless name.class == Redland::Resource + complex_value = @model.create_resource + feature = self.find_or_create_feature(name) + @model.add tuple, OT['complexValue'], complex_value + @model.add complex_value, RDF['type'], OT["FeatureValue"] + @model.add complex_value, OT['feature'], f + @model.add complex_value, OT['value'], value.to_s + end + tuple end # find or create a new compound and return the resource def find_or_create_compound(uri) compound = @model.subject(DC["identifier"], uri) if compound.nil? + #puts uri compound = @model.create_resource @model.add compound, RDF['type'], OT["Compound"] @model.add compound, DC["identifier"], uri @@ -32,13 +72,14 @@ module OpenTox feature = @model.create_resource @model.add feature, RDF['type'], OT["Feature"] @model.add feature, DC["identifier"], uri - @model.add feature, DC["title"], File.basename(uri) + @model.add feature, DC["title"], File.basename(uri).split(/#/)[1] @model.add feature, DC['source'], uri end feature end # find or create a new value and return the resource +=begin def find_or_create_value(v) value = @model.subject OT["value"], v.to_s if value.nil? @@ -48,47 +89,9 @@ module OpenTox end value end +=end - def tuple?(t) - statements = [] - has_tuple = true - t.each do |name,v| - feature = self.find_or_create_feature(:name => name) - value = self.find_or_create_value(v) - tuple = @model.subject(feature,value) - has_tuple = false if tuple.nil? - statements << [tuple,feature,value] - end - tuples_found = statements.collect{|s| s[0]}.uniq - has_tuple = false unless tuples_found.size == 1 - has_tuple - end - - def create_tuple(t) - tuple = @model.create_resource - @model.add tuple, RDF['type'], OT["Tuple"] - t.each do |name,value| - feature = self.find_or_create_feature(:name => name) - value = self.find_or_create_value(value) - pair = @model.create_resource - @model.add pair, RDF['type'], OT['FeatureValue'] - @model.add tuple, OT['complexValue'], pair - @model.add pair, OT['feature'], feature - @model.add pair, OT['value'], value #FIX - #@model.add tuple, OT['feature'], feature - #@model.add tuple, OT['values'], value - end - tuple - end - - def find_or_create_tuple(t) - if self.tuple?(t) - t - else - self.create_tuple(t) - end - end - +=begin def add_data_entry(compound,feature,value) data_entry = @model.create_resource @model.add data_entry, RDF['type'], OT["DataEntry"] @@ -96,6 +99,7 @@ module OpenTox @model.add data_entry, OT['feature'], feature @model.add data_entry, OT['values'], value end +=end def self.create(data, content_type = 'application/rdf+xml') uri = RestClient.post @@config[:services]["opentox-dataset"], data, :content_type => content_type @@ -254,57 +258,28 @@ module OpenTox end end - - -# def tanimoto(dataset) -# RestClient.get(File.join(@uri,'tanimoto',dataset.path)) -# end -# -# def weighted_tanimoto(dataset) -# RestClient.get(File.join(@uri,'weighted_tanimoto',dataset.path)) -# end =begin - def data_entries - data = {} - @model.subjects(RDF['type'], OT["Compound"]).each do |compound_node| - compound = @model.object(compound_node, DC["identifier"]).to_s#.sub(/^\[(.*)\]$/,'\1') - #compound = OpenTox::Compound.new(:inchi => compound).smiles - data[compound] = [] unless data[compound] - #puts compound - @model.subjects(OT['compound'], compound_node).each do |data_entry| - feature_node = @model.object(data_entry, OT['feature']) - feature = @model.object(feature_node, DC["identifier"]).to_s - values_node = @model.object(data_entry, OT['values']) - type = @model.object(values_node,RDF['type']).to_s - case type - when /FeatureValue/ - @model.find(values_node, OT['value'], nil) do |s,p,value| - case value.to_s - when "true" - data[compound] << {feature => true} - when "false" - data[compound] << {feature => false} - else - data[compound] << {feature => value.to_s} - end - end - when /Tuple/ # this is really slow - t = {} - @model.find(values_node, OT['tuple'], nil) do |s,p,tuple| - @model.find(tuple, OT['feature'], nil) do |s,p,feature| - @name = @model.object(feature,DC['title']).to_s - end - @model.find(tuple, OT['value'], nil) do |s,p,value| - v = @model.object(value,OT['value']).to_s - t[@name] = v - #print @name + ": " - #puts v - end - end - data[compound] << t - end - end + def tuple?(t) + statements = [] + has_tuple = true + t.each do |name,v| + feature = self.find_or_create_feature(:name => name) + value = self.find_or_create_value(v) + tuple = @model.subject(feature,value) + has_tuple = false if tuple.nil? + statements << [tuple,feature,value] + end + tuples_found = statements.collect{|s| s[0]}.uniq + has_tuple = false unless tuples_found.size == 1 + has_tuple + end + + def find_or_create_tuple(t) + if self.tuple?(t) + t + else + self.create_tuple(t) end - data end =end + diff --git a/lib/opentox.owl b/lib/opentox.owl new file mode 100644 index 0000000..4760055 --- /dev/null +++ b/lib/opentox.owl @@ -0,0 +1,809 @@ + + + + http://opentox.org/dev/apis/api-1.1 + 2009-11-22 + martin.guetlein@gmail.com + jeliazkova.nina@gmail.com + OpenTox resource ontology + OpenTox API + OpenTox + + + + http://opentox.org/dev/apis/api-1.1/dataset + + /dataset/{datasetid} + + Original source of the dataset + + + Provides access to chemical compounds and their features (e.g. structural, physical-chemical, biological, toxicological properties) + + + + + + + + + + + + + + + + + + + + + + + + + + + A generic OpenTox resource + name of the resource + URI of the resource + 1.1 + + + + + + + + + TODO: Specify allowed values for model content + The native format of the model content (e.g. PMML, Weka model, etc.) + + + + TODO: Introduce a link to User resource + /model/{modelid} + The model creator (perhaps a link to User resource) + + + The date of model creation + + + A validation corresponds to the validation of a model on a test dataset. The results are stored in another dataset. Parameters with default values are optional. + Datetime + http://opentox.org/dev/apis/api-1.1/Validation + + + + http://opentox.org/dev/apis/api-1.1/Validation#validation-report + + + + TODO: AlgorithmType, or link to Algorithm ontology + 1.1 + Reference + TODO: statistics supported - is it possible to reuse ValidationInfo classes? + /algorithm/{algorithmid} + + http://opentox.org/dev/apis/api-1.1/Algorithm + Name of the algorithm + + + + + + + + + + + + + Provides access to OpenTox algorithms + + + + + + + + + + + + + + + encapsulates validation information + + + + + + + + /compound/{compoundid} + http://opentox.org/dev/apis/api-1.1/structure + + + + + 1.1 + + + + + + + + API for OpenTox compound webservices + + + + + + + + true + + + + [Optional] support for multiple (e.g. 3D) structures per chemical compound (single structure by default) + /compound/{compoundid}/conformer/{conformerid} + + + + + + + + + + + + + + + + 1.1 + + + + /feature/{featureid} + + + + + + + + + + + + + + + + /dataset/{datasetid}/compound/{compoundid}?feature_uri[]=featureuris + + + 1.1 + + Encapsulates a dataset entry - defined by a single Compound (or conformer) and multiple FeatureValues. Could be regarded as "Compound with features" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PredictionDatasetURI + + + + + + + + + + + + + + + + + + + A model can have one or more dependent variables, described as multiple features, specified by this relationship. + + + + + + + + + + + + + + + + Algorithms and Models can have multiple parameters + http://opentox.org/api/1.1 + + + + + + + + + + + + + Test dataset , used in a validation exercise + + + + + + http://opentox.org/api/1.1 + + Variables, holding the predicted values, generated by the model + + + http://opentox.org/api/1.1 + + + A Dataset contains multiple DataEntries. This property specifies the relationship between Dataset and DataEntry. + + + + + + a link to UnscrambledDataset + UnscrambledDatasetURI + + + + http://opentox.org/api/1.1 + A model can have multiple independent variables, described as multiple features, specified by this relationship. + + + + + + Links Validation with Validation Info. One validation exercise may have multiple types of validation informaton + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A DataEntry is defined with a single compound and multiple feature values. This property sets the relationship between a DataEntry and multiple FeatureValues + http://opentox.org/api/1.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Cancelled + + + Running + + + Completed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Parameter value + The value of a Parameter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Units + Units for a feature value + TODO: make use of units ontology + + + + + + + + + + + + + + + + + + + + + + + Allows to define "is a" relationships outside of particular class hierarchy + + + + Model used in a validation exercise + + + + + + + + Number incorrect + + + + + + + Percent Correct + + + + + + + RootMeanSquaredError + + + + + + + + YScramblingEnabled + + YScramblingEnabled + + + + + YScramblingSeed + YScramblingSeed + + + + + + + + + + + Has 3D structure + + True, if the compound has 3D structure + + + + + + Literal + + Feature value + + + + + + A model is derived by applying an Algorithm on a training Dataset. + http://opentox.org/api/1.1 + + + + + + + + + + http://opentox.org/api/1.1 + The algorithm, used to create the Model + + + + + + + + + + Number correct + + + + + + + + + + + + + + + + + + specifies if a parameter is optional or mandatory + + + + + + + optional + + mandatory + + + + Parameter scope + + + + + Percentage completed + + + + + http://opentox.org/api/1.1 + + + + A DataEntry is defined with a single compound and multiple feature values. This property sets the relationship between a DataEntry and a Compound + + + + + Percent Incorrect + + + + + + MeanAbsolutError + + + + + + FeatureValue contains a value for specific Feature, specified by this relationship. + + + http://opentox.org/api/1.1 + + + + + + + + + + + + + + diff --git a/lib/owl.rb b/lib/owl.rb index c42f6ae..d9da563 100644 --- a/lib/owl.rb +++ b/lib/owl.rb @@ -21,7 +21,6 @@ module OpenTox end def uri=(uri) - puts "assigning uri" @uri = uri uri = Redland::Uri.new(uri) # rewrite uri @@ -40,8 +39,11 @@ module OpenTox end def title - me = @model.subject(RDF['type'],OT[self.owl_class]) - @model.object(me, DC['title']).to_s unless me.nil? + # I have no idea, why 2 subjects are returned + # iterating over all subjects leads to memory allocation problems + # SPARQL queries also do not work + me = @model.subjects(RDF['type'],OT[self.owl_class])[1] + @model.object(me, DC['title']).to_s end def title=(title) -- cgit v1.2.3