diff options
author | Christoph Helma <helma@in-silico.ch> | 2012-07-13 17:12:19 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2012-07-13 17:12:19 +0200 |
commit | d9a599f46009ad19e5ccfeb3c511f8d578635802 (patch) | |
tree | de8645c539c9d48b9efe002606ed322320eb4b65 | |
parent | 86247691a4414780130b094ccf5578ff2eb7d532 (diff) |
csv handling of empty cells fixed
-rw-r--r-- | application.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/application.rb b/application.rb index fa04f92..d0f512f 100644 --- a/application.rb +++ b/application.rb @@ -61,7 +61,7 @@ module OpenTox feature = OpenTox::Feature.new File.join($feature[:uri], SecureRandom.uuid) feature[RDF::DC.title] = f features << feature - values = table.collect{|row| row[i+1].strip unless row[i+1].nil?}.uniq # skip compound column + values = table.collect{|row| row[i+1].strip unless row[i+1].nil?}.uniq.compact # skip compound column if values.size <= 3 # max classes feature.append RDF.type, RDF::OT.NominalFeature feature.append RDF.type, RDF::OT.StringFeature @@ -82,7 +82,7 @@ module OpenTox # compounds and values compound_uris = [] table.each_with_index do |values,j| - values.collect!{|v| v.strip unless v.nil?} + values.collect!{|v| v.nil? ? nil : v.strip } compound = values.shift begin case compound_format @@ -157,7 +157,9 @@ module OpenTox ?f <#{RDF::OLO.index}> ?i. } ORDER BY ?i" - csv << [compound.to_smiles] + FourStore.query(sparql,accept).split("\n") + values = FourStore.query(sparql,accept).split("\n") + # Fill up trailing empty cells + csv << [compound.to_smiles] + values.fill("",values.size,features.size-values.size) end else sparql = "SELECT DISTINCT ?s FROM <#{@uri}> WHERE {?s <#{RDF.type}> <#{RDF::OT.Feature}>}" @@ -175,7 +177,7 @@ module OpenTox <#{RDF::OT.value}> ?value. } ORDER BY ?data_entry" FourStore.query(sparql, accept).split("\n").each_with_index do |value,i| - data_entries[i] = [] unless data_entries[i] + data_entries[i] = Array.new(features.size) unless data_entries[i] data_entries[i] << value end end |