summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2010-05-11 16:49:21 +0200
committermr <mr@mrautenberg.de>2010-05-11 16:49:21 +0200
commitba2d357cd97b41d9e305e2b24249509b75a47bef (patch)
tree7405bd21709726a75710df6c2889275f382bd026
parent7821b0e7c7d97a60b881afff67e557426256eac6 (diff)
xls export of trainings data
-rw-r--r--application.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/application.rb b/application.rb
index 2e56233..0702758 100644
--- a/application.rb
+++ b/application.rb
@@ -53,6 +53,9 @@ get '/:id' do
when /.rdf$/
params[:id].sub!(/.rdf$/,'')
accept = 'application/rdf+xml'
+ when /.xls$/
+ params[:id].sub!(/.xls$/,'')
+ accept = 'application/vnd.ms-excel'
end
begin
dataset = Dataset.get(params[:id])
@@ -72,7 +75,31 @@ get '/:id' do
when /yaml/
response['Content-Type'] = 'application/x-yaml'
dataset.yaml
- else
+ when /ms-excel/
+ require 'spreadsheet'
+ response['Content-Type'] = 'application/vnd.ms-excel'
+ book = Spreadsheet::Workbook.new
+ tmp = Tempfile.new('opentox-feature-xls')
+ sheet = book.create_worksheet :name => 'Training Data'
+ sheet.update_row(0, "Chemical Structure","Activity")
+ sheet.column(0).width = 100
+ headline = Spreadsheet::Format.new :weight => :bold, :size => 12
+ 2.times{|x| sheet.row(0).set_format(x , headline)}
+ i = 1
+ YAML.load(dataset.yaml).data.each do |line|
+ smilestring = RestClient.get(line[0], :accept => 'chemical/x-daylight-smiles').to_s
+ line[1][0] ? val = line[1][0].first[1] ? "1" : "0" : val = ""
+ sheet.update_row(i, smilestring , val)
+ i+=1
+ end
+ begin
+ book.write tmp.path
+ return tmp
+ rescue
+
+ end
+ tmp.close!
+ else
halt 400, "Unsupported MIME type '#{accept}'"
end
end