summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2012-12-04 11:14:14 +0100
committermguetlein <martin.guetlein@gmail.com>2012-12-04 11:14:14 +0100
commit614dc876d22258a4d6f96e56db6c6f43a2ed6bba (patch)
tree70d05c7e0bd301c290d048726da67081176d90a7
parent043335dfc8a4074f061b27fc0f4663100c599143 (diff)
replace remaining occurences of dataset.add with add_data_entry, adjust parsing code respectively
-rw-r--r--lib/dataset.rb4
-rw-r--r--lib/parser.rb10
-rw-r--r--lib/serializer.rb4
3 files changed, 12 insertions, 6 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 27457c9..c075790 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -319,7 +319,7 @@ module OpenTox
# @param [String] feature Compound URI
# @param [Boolean,Float] value Feature value
def add (compound,feature,value)
- LOGGER.warn("dataset.add is deprecated and should not be used any longer")
+ raise("dataset.add is deprecated, use add_data_entry instead")
self.add_compound(compound)
self.add_data_entry(compound,feature,value)
end
@@ -334,6 +334,8 @@ module OpenTox
@data_entries[compound] = {} unless @data_entries[compound]
@data_entries[compound][feature] = [] unless @data_entries[compound][feature]
@data_entries[compound][feature] << value
+ else
+ raise "dataset.add_data_entry> add compound #{compound} first"
end
end
diff --git a/lib/parser.rb b/lib/parser.rb
index fb67882..1f15621 100644
--- a/lib/parser.rb
+++ b/lib/parser.rb
@@ -206,8 +206,9 @@ module OpenTox
end
File.delete(to_delete) if to_delete
data.each do |id,entry|
- if entry[:values].size==0
+ if entry[:values].size==0 and !@dataset.compounds.include?(entry[:compound])
# no feature values add plain compounds
+ #RDF has no support for multiple occurences yet!
@dataset.add_compound(entry[:compound])
else
entry[:values].each do |value_id|
@@ -222,7 +223,9 @@ module OpenTox
value = split.first
end
end
- @dataset.add entry[:compound],feature[value_id],value
+ #RDF has no support for multiple occurences yet!
+ @dataset.add_compound(entry[:compound]) unless @dataset.compounds.include?(entry[:compound])
+ @dataset.add_data_entry entry[:compound],feature[value_id],value
end
end
end
@@ -591,6 +594,7 @@ module OpenTox
end
@data.each do |compound,row|
+ dataset.add_compound(compound)
unless row.empty?
row.each do |feature,value|
if OpenTox::Algorithm::numeric?(value)
@@ -601,7 +605,7 @@ module OpenTox
value = value.to_s
end
feature_uri = File.join(dataset.uri,"feature",URI.encode(feature))
- dataset.add(compound, feature_uri, value)
+ dataset.add_data_entry(compound, feature_uri, value)
#dataset.features[feature_uri][RDF.type] = feature_types(feature)
#dataset.features[feature_uri][OT.acceptValue] = feature_values(feature)
if feature_types(feature).include? OT.NumericFeature
diff --git a/lib/serializer.rb b/lib/serializer.rb
index 8d41f05..019d9a2 100644
--- a/lib/serializer.rb
+++ b/lib/serializer.rb
@@ -466,7 +466,7 @@ module OpenTox
features.sort!
# prepare for subgraphs
- have_substructures = features.collect{ |id| dataset.features[id][RDF.type].include? OT.Substructure}.compact.uniq
+ have_substructures = features.collect{ |id| (dataset.features[id][RDF.type] and dataset.features[id][RDF.type].include?(OT.Substructure))}.compact.uniq
if have_substructures.size == 1 && have_substructures[0]
features_smarts = features.collect{ |id| "\"" + dataset.features[id][OT.smarts] + "\"" }
end
@@ -501,7 +501,7 @@ module OpenTox
feature_quoting = {}
features.each_with_index { |f,idx|
feature_quoting[f] = false
- if dataset.features[f][RDF.type].size == 1 && dataset.features[f][RDF.type][0] == OT.NominalFeature
+ if dataset.features[f][RDF.type] && dataset.features[f][RDF.type].size == 1 && dataset.features[f][RDF.type][0] == OT.NominalFeature
feature_quoting[f] = true
end
}