diff options
author | Andreas Maunz <andreas@maunz.de> | 2012-10-30 16:00:58 +0100 |
---|---|---|
committer | Andreas Maunz <andreas@maunz.de> | 2012-10-30 16:00:58 +0100 |
commit | a1f96efdda366ba19f70222bc2e145b6fe730a54 (patch) | |
tree | 31d2a389bf6b1d76eed4873dca2f4f033776d7f7 | |
parent | 35346926e9690f14a7e587d62ef76e82ddcac3ad (diff) |
CSV dl iteration: cols->rows
-rw-r--r-- | application.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/application.rb b/application.rb index 99abe09..65cab40 100644 --- a/application.rb +++ b/application.rb @@ -299,15 +299,29 @@ module OpenTox quoted_features = []; feature_names = [] features.each { |feature| quoted_features << feature_props[feature.uri][:type].include?(RDF::OT.NominalFeature) - feature_names << feature_props[feature.uri][:title][0].strip + feature_names << "\"#{feature_props[feature.uri][:title][0].strip}\"" } - table << ["InChI"] + feature_names compounds = OpenTox::Dataset.find_compounds_sparql(@uri) values = OpenTox::Dataset.find_data_entries_sparql(@uri) values += Array.new(compounds.size*features.size-values.size, "") - values.each_slice(features.size).each_with_index { |vals,row_idx| - table << ["\"#{compounds[row_idx].inchi}\""] + vals.each_with_index.collect { |value,col_idx| (quoted_features[col_idx] ? "\"#{value}\"" : value) } + clim=(compounds.size-1) + cidx = fidx = 0 + num=(!quoted_features[fidx]) + table = (Array.new((features.size)*(compounds.size))).each_slice(features.size).to_a + values.each { |val| + unless val.blank? + table[cidx][fidx] = (num ? val : "\"#{val}\"") + end + if (cidx < clim) + cidx+=1 + else + cidx=0 + fidx+=1 + num=(!quoted_features[fidx]) + end } + table.each_with_index { |row,idx| row.unshift("\"#{compounds[idx].inchi}\"") } + table.unshift([ "\"InChI\"" ] + feature_names) else sparql = "SELECT DISTINCT ?s FROM <#{@uri}> WHERE {?s <#{RDF.type}> <#{RDF::OT.Feature}>}" features = FourStore.query(sparql, accept).split("\n").collect{|uri| OpenTox::Feature.new uri}.each { |f| f.get } |