summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2010-06-22 16:40:39 +0200
committermguetlein <martin.guetlein@gmail.com>2010-06-22 16:40:39 +0200
commit0a67c96df794af07d685449feaa5a75ebd58520b (patch)
tree29172caac555fc3153d6c9d07bae60ad5f94c8a5
parent52e468df820115b77f90d404cf6ec8b5678342d7 (diff)
parent2744d0df0e842f891931f6ab59d58f50445378b8 (diff)
resolved merge conflict
-rw-r--r--.gitignore1
-rw-r--r--README8
-rw-r--r--Rakefile2
-rwxr-xr-xapplication.rb42
-rw-r--r--public/robots.txt2
5 files changed, 41 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index b42cb55..1441bd2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,3 @@ api_key.rb
tmp/*
log/*
datasets/*
-public/*
diff --git a/README b/README
index 42f6276..9678cf2 100644
--- a/README
+++ b/README
@@ -21,19 +21,19 @@ Examples:
Get a list of all datasets:
- curl http://webservices.in-silico.ch/test/dataset
+ curl http://webservices.in-silico.ch/dataset
Upload a dataset:
- curl -X POST -H "Content-Type:application/rdf+xml" --data-binary @{my_rdf_file} http://webservices.in-silico.ch/test/dataset
+ curl -X POST -H "Content-Type:application/rdf+xml" --data-binary @{my_rdf_file} http://webservices.in-silico.ch/dataset
Get a dataset representation:
- curl http://webservices.in-silico.ch/test/dataset/{id}
+ curl http://webservices.in-silico.ch/dataset/{id}
Delete a dataset:
- curl -X DELETE http://webservices.in-silico.ch/test/dataset/{id}
+ curl -X DELETE http://webservices.in-silico.ch/dataset/{id}
Installation: http://wiki.github.com/helma/opentox-documentation/installation-of-opentox-webservices
diff --git a/Rakefile b/Rakefile
index 2b5727a..21e8bdf 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,7 +2,7 @@ require 'rubygems'
require 'rake'
require 'tasks/opentox'
-@gems = "sinatra emk-sinatra-url-for builder opentox-ruby-api-wrapper"
+@gems = "sinatra emk-sinatra-url-for opentox-ruby-api-wrapper"
desc "Run local tests"
task :test do
diff --git a/application.rb b/application.rb
index c92d31d..248a2d6 100755
--- a/application.rb
+++ b/application.rb
@@ -1,9 +1,6 @@
require 'rubygems'
-gem 'opentox-ruby-api-wrapper', '= 1.4.4.4'
+gem "opentox-ruby-api-wrapper", "= 1.5.6"
require 'opentox-ruby-api-wrapper'
-#require 'sinatra/respond_to'
-#Sinatra::Application.register Sinatra::RespondTo
-
LOGGER.progname = File.expand_path(__FILE__)
@@ -19,9 +16,7 @@ class Dataset
def to_owl
data = YAML.load(yaml)
owl = OpenTox::Owl.create 'Dataset', uri
- ['title', 'creator'].each do |method|
- owl.set(method, data.send(method))
- end
+ owl.set "title", data.title
if data.data
data.data.each do |compound,features|
owl.add_data_entries compound,features
@@ -52,6 +47,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])
@@ -60,6 +58,7 @@ get '/:id' do
raise e.message + e.backtrace
halt 404, "Dataset #{params[:id]} not found."
end
+ halt 404, "Dataset #{params[:id]} not found." if dataset.nil? # not sure how an empty cataset can be returned, but if this happens stale processes keep runing at 100% cpo
case accept
when /rdf/ # redland sends text/rdf instead of application/rdf+xml
response['Content-Type'] = 'application/rdf+xml'
@@ -71,7 +70,32 @@ get '/:id' do
when /yaml/
response['Content-Type'] = 'text/x-yaml'
dataset.yaml
- else
+ when /ms-excel/
+ require 'spreadsheet'
+ response['Content-Type'] = 'application/vnd.ms-excel'
+ Spreadsheet.client_encoding = 'UTF-8'
+ book = Spreadsheet::Workbook.new
+ tmp = Tempfile.new('opentox-feature-xls')
+ sheet = book.create_worksheet :name => 'Training Data'
+ sheet.column(0).width = 100
+ i = 0
+ YAML.load(dataset.yaml).data.each do |line|
+ begin
+ 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
+ rescue
+ end
+ end
+ begin
+ book.write tmp.path
+ return tmp
+ rescue
+
+ end
+ tmp.close!
+ else
halt 400, "Unsupported MIME type '#{accept}'"
end
end
@@ -132,6 +156,7 @@ end
delete '/?' do
+=begin
Dataset.all.each do |d|
begin
File.delete d.file
@@ -140,6 +165,7 @@ delete '/?' do
end
#d.destroy!
end
+=end
Dataset.auto_migrate!
response['Content-Type'] = 'text/plain'
"All datasets deleted."
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000..1f53798
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /