diff options
author | Christoph Helma <helma@in-silico.ch> | 2015-08-25 17:20:55 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2015-08-25 17:20:55 +0200 |
commit | f8faf510b4574df1a00fa61a9f0a1681fc2f4857 (patch) | |
tree | acdbe6666ca5f528be368c6f9fdf4d7fb51d031e /lib/dataset.rb | |
parent | 8c6c59980bc82dc2177147f2fe34adf8bfbc1539 (diff) |
Experiments added
Diffstat (limited to 'lib/dataset.rb')
-rw-r--r-- | lib/dataset.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb index 5850c3d..b3f5392 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -10,7 +10,7 @@ module OpenTox # associations like has_many, belongs_to deteriorate performance field :feature_ids, type: Array, default: [] field :compound_ids, type: Array, default: [] - field :data_entries_id, type: BSON::ObjectId, default: [] + field :data_entries_id, type: BSON::ObjectId#, default: [] field :source, type: String field :warnings, type: Array, default: [] @@ -19,9 +19,9 @@ module OpenTox def save_all dump = Marshal.dump(@data_entries) file = Mongo::Grid::File.new(dump, :filename => "#{self.id.to_s}.data_entries") - data_entries_id = $gridfs.insert_one(file) - update(:data_entries_id => data_entries_id) - save + entries_id = $gridfs.insert_one(file) + update(:data_entries_id => entries_id) + #save end # Readers @@ -125,11 +125,11 @@ module OpenTox # Serialisation - # converts dataset to csv format including compound smiles as first column, other column headers are feature titles + # converts dataset to csv format including compound smiles as first column, other column headers are feature names # @return [String] def to_csv(inchi=false) CSV.generate() do |csv| #{:force_quotes=>true} - csv << [inchi ? "InChI" : "SMILES"] + features.collect{|f| f.title} + csv << [inchi ? "InChI" : "SMILES"] + features.collect{|f| f.name} compounds.each_with_index do |c,i| csv << [inchi ? c.inchi : c.smiles] + data_entries[i] end @@ -149,9 +149,10 @@ module OpenTox # Create a dataset from CSV file # TODO: document structure def self.from_csv_file file, source=nil, bioassay=true + $logger.debug "Parsing #{file}." source ||= file table = CSV.read file, :skip_blanks => true - dataset = self.new(:source => source, :name => File.basename(file)) + dataset = self.new(:source => source, :name => File.basename(file,".*")) dataset.parse_table table, bioassay dataset end |