summaryrefslogtreecommitdiff
path: root/lib/dataset.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-11-24 13:13:40 +0100
committerChristoph Helma <helma@in-silico.ch>2010-11-24 13:13:40 +0100
commit7067bd44d5c97618ec6a968bbdfe6d6bda12a1cd (patch)
tree8d10b0b82ca124c1f2a99ec97658a89218c2b9b3 /lib/dataset.rb
parent7c743456c42ffa85e81db6d975ebd7ed260f81f0 (diff)
opentox-ruby-api-wrapper renamed to opentox-ruby
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r--lib/dataset.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 4737ea1..c5704ae 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -32,6 +32,21 @@ module OpenTox
dataset
end
+ # Create dataset from CSV file (format specification: http://toxcreate.org/help)
+ # - loads data_entries, compounds, features
+ # - sets metadata (warnings) for parser errors
+ # - you will have to set remaining metadata manually
+ # @param [String] file CSV file path
+ # @return [OpenTox::Dataset] Dataset object with CSV data
+ def self.create_from_csv_file(file)
+ dataset = Dataset.create
+ parser = Parser::Spreadsheets.new
+ parser.dataset = dataset
+ parser.load_csv(File.open(file).read)
+ dataset.save
+ 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
@@ -299,7 +314,7 @@ module OpenTox
def measured_activities(compound)
source = @metadata[OT.hasSource]
- @data_entries[compound.uri].collect{|f,v| v if f.match(/#{source}/)}.compact
+ @data_entries[compound.uri].collect{|f,v| v if f.match(/#{source}/)}.compact.flatten
end
def neighbors(compound)