summaryrefslogtreecommitdiff
path: root/lib/dataset.rb
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-01-13 14:02:58 +0100
committermguetlein <martin.guetlein@gmail.com>2011-01-13 14:02:58 +0100
commitf2ca545448ab8a6f654309f23cfce9416b2e9856 (patch)
treedb97da6b26689585ab2d51467ec72a6999e32cd8 /lib/dataset.rb
parentc923250bccd4023447feb46935f3b59ce5cfb843 (diff)
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
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r--lib/dataset.rb33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index aba7754..d45c821 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -46,7 +46,7 @@ module OpenTox
dataset.save(subjectid)
dataset
end
-
+
# Find a dataset and load all data. This can be time consuming, use Dataset.new together with one of the load_* methods for a fine grained control over data loading.
# @param [String] uri Dataset URI
# @return [OpenTox::Dataset] Dataset object with all data
@@ -242,6 +242,37 @@ module OpenTox
def add_feature_metadata(feature,metadata)
metadata.each { |k,v| @features[feature][k] = v }
end
+
+ # Add a new compound
+ # @param [String] compound Compound URI
+ def add_compound (compound)
+ @compounds << compound unless @compounds.include? compound
+ end
+
+ # Creates a new dataset, by splitting the current dataset, i.e. using only a subset of compounds and features
+ # @param [Array] compounds List of compound URIs
+ # @param [Array] features List of feature URIs
+ # @param [Hash] metadata Hash containing the metadata for the new dataset
+ # @return [OpenTox::Dataset] newly created dataset, already saved
+ def split( compounds, features, metadata)
+ LOGGER.debug "split dataset using "+compounds.size.to_s+"/"+@compounds.size.to_s+" compounds"
+ raise "no new compounds selected" unless compounds and compounds.size>0
+ dataset = OpenTox::Dataset.create
+ if features.size==0
+ compounds.each{ |c| dataset.add_compound(c) }
+ else
+ compounds.each do |c|
+ features.each do |f|
+ @data_entries[c][f].each do |v|
+ dataset.add(c,f,v)
+ end
+ end
+ end
+ end
+ dataset.add_metadata(metadata)
+ dataset.save
+ dataset
+ end
# Save dataset at the dataset service
# - creates a new dataset if uri is not set