summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-03-01 16:47:08 +0100
committerChristoph Helma <helma@in-silico.de>2010-03-01 16:47:08 +0100
commita008ff7fce85e9532f257da863daeaf63fe7ee11 (patch)
treefa02fcf520f054204528b4cf720be43bc7db3641
parent166d6bc50a99f7c3a41325f08fdad001af88224e (diff)
parent0e461d0157337c699f2a5c6f0faaa9faeb881da3 (diff)
new gemspec generated
-rw-r--r--.gitignore1
-rw-r--r--Rakefile8
-rw-r--r--VERSION2
-rwxr-xr-xbin/opentox-install-ubuntu.sh375
-rw-r--r--lib/algorithm.rb87
-rw-r--r--lib/authorization.rb24
-rw-r--r--lib/compound.rb3
-rw-r--r--lib/config/config_ru.rb1
-rw-r--r--lib/dataset.rb34
-rw-r--r--lib/environment.rb17
-rw-r--r--lib/model.rb18
-rw-r--r--lib/opentox-ruby-api-wrapper.rb2
-rw-r--r--lib/owl.rb1
-rw-r--r--lib/task.rb47
-rw-r--r--lib/templates/users.yaml5
-rw-r--r--lib/validation.rb21
-rw-r--r--opentox-ruby-api-wrapper.gemspec28
17 files changed, 598 insertions, 76 deletions
diff --git a/.gitignore b/.gitignore
index 00c0b86..fedf1b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
coverage
rdoc
pkg
+*~
diff --git a/Rakefile b/Rakefile
index e585ca6..d2eaf64 100644
--- a/Rakefile
+++ b/Rakefile
@@ -10,12 +10,14 @@ begin
gem.email = "helma@in-silico.ch"
gem.homepage = "http://github.com/helma/opentox-ruby-api-wrapper"
gem.authors = ["Christoph Helma"]
- ["sinatra", "rest-client", "rack", "rack-contrib", "rack-flash", "thin", "emk-sinatra-url-for", "cehoffman-sinatra-respond_to", "dm-more", "dm-core", "sinatra-static-assets", "do_sqlite3", "do_postgres"].each do |dep|
+ ["sinatra", "rest-client", "rack", "rack-contrib", "rack-flash", "thin", "emk-sinatra-url-for", "cehoffman-sinatra-respond_to", "dm-more", "dm-core", "sinatra-static-assets"].each do |dep|
gem.add_dependency dep
end
- gem.add_development_dependency "cucumber"
+ ['cucmber','jeweler'].each do |dep|
+ gem.add_development_dependency dep
+ end
gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore']
- gem.files.include %w(lib/tasks/owl.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/model.rb, lib/utils.rb, lib/templates/*)
+ gem.files.include %w(lib/tasks/owl.rb, lib/environment.rb, lib/algorithm.rb, lib/compound.rb, lib/dataset.rb, lib/model.rb, lib/utils.rb, lib/validation.rb, lib/templates/*)
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
diff --git a/VERSION b/VERSION
index c04c650..f0bb29e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.7
+1.3.0
diff --git a/bin/opentox-install-ubuntu.sh b/bin/opentox-install-ubuntu.sh
new file mode 100755
index 0000000..75faff7
--- /dev/null
+++ b/bin/opentox-install-ubuntu.sh
@@ -0,0 +1,375 @@
+#!/bin/bash
+#Installation is tested on Debian Ubuntu 9.10
+#Update the system
+
+FAILED=0
+STARTPATH=$PWD
+ERRLOG=$PWD/'install_err.log'
+INSTALLLOG=$PWD/'install_log.log'
+DATE=$(date +%Y/%m/%d\ %H:%M:%S)
+BRANCH=$1
+GEMVERSION="1.3.5"
+GITVERSION="1.6.5.2"
+RAPTORVERSION="1.4.20"
+RASQALVERSION="0.9.16"
+RASQALVERSION2="0.9.15"
+REDLANDVERSION="1.0.7"
+REDBINDVERSION="1.0.7.1"
+
+if [ "$BRANCH" = '' ]
+then
+ echo "Please enter: sudo ./[filename] [brunchtpy]"
+ exit 1
+fi
+echo "================================================="
+echo "Selected branch is: $BRANCH"
+echo "================================================="
+echo "Please enshure that the sudo package is installed"
+echo "on your system. "
+echo "On Ubuntu Linux sudo is installed by default."
+echo "If you are unsure check with it 'sudo ls'"
+echo "and installed it with 'apt-get install sudo'"
+echo "and add your username with visudo."
+echo "================================================="
+echo "Some programs and the OpenTox webservices will be installed in the current folder."
+echo "================================================="
+echo -n "To continue installation press y: "
+read answer
+if [ "$answer" != "y" ]
+then
+ echo "exiting the script..."
+ exit 1
+fi
+
+echo "opentox webservice install log - " $DATE > $INSTALLLOG
+echo "opentox webservice install err log - " $DATE > $ERRLOG
+echo "Installing: build-essential"
+sudo apt-get install build-essential | tee -a $INSTALLLOG
+
+echo "Installing: ruby 1.8 with its dev files"
+sudo apt-get install ruby ruby1.8-dev | tee -a $INSTALLLOG
+
+echo "Installing: gems rdoc rubygems libxml-parser-ruby1.8 libxml++2.6-dev libyaml-ruby libzlib-ruby sqlite3 libsqlite3-dev libsqlite3-ruby1.8 and rake"
+sudo apt-get install gems rdoc rubygems libxml-parser-ruby1.8 libxml++2.6-dev libyaml-ruby libzlib-ruby rake sqlite3 libsqlite3-dev libsqlite3-ruby1.8 | tee -a $INSTALLLOG
+
+#RUBYGEMS
+echo "Installing rubygems from source. This may take some time"
+if [ ! -d $STARTPATH/rubygems-$GEMVERSION ];
+then
+ wget http://rubyforge.org/frs/download.php/60718/rubygems-$GEMVERSION.tgz >>$INSTALLLOG 2>>$ERRLOG
+ tar xzfv rubygems-$GEMVERSION.tgz >>$INSTALLLOG 2>>$ERRLOG
+ cd rubygems-$GEMVERSION
+ sudo ruby setup.rb >>$INSTALLLOG 2>>$ERRLOG
+ cd ..
+ sudo rm rubygems-$GEMVERSION.tgz
+ CHECKGEM=`gem -v`
+ if [ "$CHECKGEM" == "$GEMVERSION" ]
+ then
+ echo "Adding http://gems.github.com to ruby gem sources"
+ sudo gem sources -a http://gems.github.com >>$INSTALLLOG 2>>$ERRLOG
+
+ echo "================================================="
+ echo "Rubygems version $GEMVERSION successfully installed."
+ echo "================================================="
+ else
+ echo "Rubygems version $GEMVERSION installation failed."
+ FAILED=1
+ exit $FAILED
+ fi
+else
+ echo "rubygems-$GEMVERSION folder already exist. "
+fi
+
+echo "Installing packages: zlib1g-dev tcl curl perl ssh tcl tk8.5 libopenssl-ruby libgsl0-dev swig r-base rinruby"
+sudo apt-get install zlib1g-dev tcl curl perl libopenssl-ruby libgsl0-dev r-base | tee -a $INSTALLLOG
+sudo apt-get install ssh tcl tk8.5 | tee -a $INSTALLLOG
+sudo apt-get install swig | tee -a $INSTALLLOG
+sudo apt-get install postgresql-server-dev-8.4 | tee -a $INSTALLLOG
+
+
+#echo "Installing gems jeweler sinatra emk-sinatra-url-for dm-core cehoffman-sinatra-respond_to rest-client rack-contrib thin cucumber datamapper data_objects do_sqlite3 rinruby"
+sudo gem install jeweler | tee -a $INSTALLLOG
+sudo gem install sinatra | tee -a $INSTALLLOG
+sudo gem install emk-sinatra-url-for -s http://gems.github.com | tee -a $INSTALLLOG
+sudo gem install dm-core | tee -a $INSTALLLOG
+sudo gem install cehoffman-sinatra-respond_to -s http://gems.github.com | tee -a $INSTALLLOG
+sudo gem install rest-client | tee -a $INSTALLLOG
+sudo gem install rack-contrib | tee -a $INSTALLLOG
+sudo gem install thin | tee -a $INSTALLLOG
+sudo gem install cucumber | tee -a $INSTALLLOG
+sudo gem install datamapper | tee -a $INSTALLLOG
+sudo gem install data_objects | tee -a $INSTALLLOG
+sudo gem install do_sqlite3 | tee -a $INSTALLLOG
+sudo gem install rinruby | tee -a $INSTALLLOG
+sudo gem cleanup | tee -a $INSTALLLOG
+
+echo "Installing LibRDF-ruby"
+sudo apt-get install librdf0 librdf-ruby | tee -a $INSTALLLOG
+
+#GIT
+echo "Installing git from source"
+echo "This could take a while..."
+if [ ! -d $STARTPATH/git-$GITVERSION ];
+then
+ wget http://www.kernel.org/pub/software/scm/git/git-$GITVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ tar xzfv git-$GITVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ cd git-$GITVERSION
+ ./configure >>$INSTALLLOG 2>>$ERRLOG
+ make >>$INSTALLLOG 2>>$ERRLOG
+ sudo make install >>$INSTALLLOG 2>>$ERRLOG
+ cd ..
+ sudo rm git-$GITVERSION.tar.gz
+ CHECKGIT=`git --version`
+ if [ "$CHECKGIT" == "git version $GITVERSION" ]
+ then
+ echo "================================================="
+ echo "Git version $GITVERSION successfully installed."
+ echo "================================================="
+ else
+ echo "Git version $GITVERSION installation failed."
+ FAILED=1
+ exit $FAILED
+ fi
+else
+ echo "git-$GITVERSION folder exists."
+fi
+
+#REDLAND
+if [ ! -d $STARTPATH/redland ];
+then
+ echo "Making Redland folder."
+ mkdir redland >>$INSTALLLOG 2>>$ERRLOG
+ cd redland
+ echo "Installing Redland raptor"
+ if [ ! -d $STARTPATH/redland/raptor-$RAPTORVERSION ];
+ then
+ wget wget http://download.librdf.org/source/raptor-$RAPTORVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ tar xzfv raptor-$RAPTORVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ cd raptor-$RAPTORVERSION
+ ./configure >>$INSTALLLOG 2>>$ERRLOG
+ sudo make >>$INSTALLLOG 2>>$ERRLOG
+ sudo make install >>$INSTALLLOG 2>>$ERRLOG
+ cd ..
+ sudo rm raptor-$RAPTORVERSION.tar.gz
+ CHECKRAPTOR=`raptor-config --version`
+ if [ "$CHECKRAPTOR" == "$RAPTORVERSION" ]
+ then
+ echo "================================================="
+ echo "Raptor version $RAPTORVERSION successfully installed."
+ echo "================================================="
+ else
+ echo "Raptor version $RAPTORVERSION installation failed."
+ FAILED=1
+ exit $FAILED
+ fi
+ else
+ echo "raptor-$RAPTORVERSION folder exists."
+ fi
+
+ echo "Installing Redland rasqal"
+ wget wget http://download.librdf.org/source/rasqal-$RASQALVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ tar xzfv rasqal-$RASQALVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ cd rasqal-$RASQALVERSION
+ ./configure >>$INSTALLLOG 2>>$ERRLOG
+ sudo make >>$INSTALLLOG 2>>$ERRLOG
+ sudo make install >>$INSTALLLOG 2>>$ERRLOG
+ cd ..
+ sudo rm rasqal-$RASQALVERSION.tar.gz
+ CHECKRASQAL=`rasqal-config --version`
+ if [ "$CHECKRASQAL" == "$RASQALVERSION2" -o "$CHECKRASQAL" == "$RASQALVERSION" ]
+ then
+ echo "================================================="
+ echo "Raptor version $RASQALVERSION2 or higher successfully installed."
+ echo "================================================="
+ else
+ echo "Raptor version $RASQALVERSION2 or higher installation failed."
+ FAILED=1
+ exit $FAILED
+ fi
+
+ echo "Installing Redland redland"
+ wget wget http://download.librdf.org/source/redland-$REDLANDVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ tar xzfv redland-$REDLANDVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ cd redland-$REDLANDVERSION
+ ./configure >>$INSTALLLOG 2>>$ERRLOG
+ sudo make >>$INSTALLLOG 2>>$ERRLOG
+ sudo make install >>$INSTALLLOG 2>>$ERRLOG
+ cd ..
+ sudo rm redland-$REDLANDVERSION.tar.gz
+ CHECKREDLAND=`redland-config --version`
+ if [ "$CHECKREDLAND" == "$REDLANDVERSION" ]
+ then
+ echo "================================================="
+ echo "Redland version $REDLANDVERSION successfully installed."
+ echo "================================================="
+ else
+ echo "Redland version $REDLANDVERSION installation failed."
+ FAILED=1
+ exit $FAILED
+ fi
+
+
+ echo "Installing Redland Bindings with ruby"
+ wget http://download.librdf.org/source/redland-bindings-$REDBINDVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ tar xzfv redland-bindings-$REDBINDVERSION.tar.gz >>$INSTALLLOG 2>>$ERRLOG
+ cd redland-bindings-$REDBINDVERSION
+ ./configure --with-ruby >>$INSTALLLOG 2>>$ERRLOG
+ sudo make >>$INSTALLLOG 2>>$ERRLOG
+ sudo make install >>$INSTALLLOG 2>>$ERRLOG
+ cd ..
+ sudo rm redland-bindings-$REDBINDVERSION.tar.gz
+ cd ..
+ #CHECKREDBIND=`??? --version`
+ #if [ "$CHECKREDBIND" == "$REDBINDVERSION" ]
+ #then
+ # echo "================================================="
+ # echo "Redland Bindings version $REDBINDVERSION successfully installed."
+ # echo "================================================="
+ #else
+ # echo "Redland Bindings version $REDBINDVERSION installation failed."
+ # FAILED=1
+ # exit $FAILED
+ #fi
+else
+ echo "Redland folder exists."
+fi
+
+echo "Installing the opentox webservices"
+mkdir webservices
+cd webservices
+
+echo "Install the opentox-ruby-api-wrapper"
+echo "This could take a while..."
+git clone git://github.com/helma/opentox-ruby-api-wrapper.git >>$INSTALLLOG 2>>$ERRLOG
+cd opentox-ruby-api-wrapper
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+OTAPIVERSION=`cat VERSION`
+sudo rake install | tee -a $INSTALLLOG
+cd ..
+CHECKOTAPI=`gem list | grep "opentox-ruby-api-wrapper" | grep "$OTAPIVERSION"`
+if [ ! "$CHECKOTAPI" = '' ]
+then
+ echo "================================================="
+ echo "opentox-ruby-api-wrapper ($OTAPIVERSION) successfully installed."
+ echo "================================================="
+else
+ echo "opentox-ruby-api-wrapper ($OTAPIVERSION) installation failed."
+ FAILED=1
+ exit $FAILED
+fi
+
+echo "Installing the webservices: compound, dataset, algorithm, model, task, feature"
+git clone git://github.com/helma/opentox-compound.git >>$INSTALLLOG 2>>$ERRLOG
+git clone git://github.com/helma/opentox-dataset.git >>$INSTALLLOG 2>>$ERRLOG
+git clone git://github.com/helma/opentox-algorithm.git >>$INSTALLLOG 2>>$ERRLOG
+git clone git://github.com/helma/opentox-model.git >>$INSTALLLOG 2>>$ERRLOG
+git clone git://github.com/helma/opentox-task.git >>$INSTALLLOG 2>>$ERRLOG
+git clone git://github.com/helma/opentox-feature.git >>$INSTALLLOG 2>>$ERRLOG
+
+cd opentox-compound
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+cd ../opentox-dataset
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+cd ../opentox-algorithm
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+cd ../opentox-model
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+cd ../opentox-task
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+cd ../opentox-task
+git checkout -b development origin/development >>$INSTALLLOG 2>>$ERRLOG
+cd ..
+
+#edit /home/[username]/.opentox/config/test.yaml set :base_dir: /home/[username]/webservices
+
+echo "Installing the tests"
+git clone git://github.com/helma/opentox-test.git >>$INSTALLLOG 2>>$ERRLOG
+cd opentox-test
+git checkout -b $BRANCH origin/$BRANCH >>$INSTALLLOG 2>>$ERRLOG
+
+echo "Installing openbabel"
+cd ../opentox-compound
+sudo rake openbabel:install | tee -a $INSTALLLOG
+sudo ldconfig >>$INSTALLLOG 2>>$ERRLOG
+
+ln -s /usr/local/lib/libopenbabel.so.3 /usr/lib/libopenbabel.so.3 >> $INSTALLLOG 2>>$ERR
+#VERSION=` --version`
+#if [ "$VERSION" == "$RAPTORVERSION" ]
+#then
+# echo "================================================="
+# echo "Raptor version $RAPTORVERSION successfully installed."
+# echo "================================================="
+#else
+# echo "Raptor version $RAPTORVERSION installation failed."
+# FAILED=1
+# exit $FAILED
+#fi
+
+
+#check /webservices/opentox-algorithm/fminer.rb for 1,0/ture,false bug
+BUGCHECK1=`grep "@@fminer.AddActivity(true, id)" $STARTPATH/webservices/opentox-algorithm/fminer.rb`
+BUGCHECK2=`grep "@@fminer.AddActivity(false, id)" $STARTPATH/webservices/opentox-algorithm/fminer.rb`
+if [ -z "$BUGCHECK1$BUGCHECK2" ]
+then
+ echo "fminer.rb is correct."
+else
+ sed -i 's/@@fminer.AddActivity(true, id)/@@fminer.AddActivity(1, id)/g' $STARTPATH/webservices/opentox-algorithm/fminer.rb
+ sed -i 's/@@fminer.AddActivity(false, id)/@@fminer.AddActivity(0, id)/g' $STARTPATH/webservices/opentox-algorithm/fminer.rb
+ echo "fminer.rb updated."
+fi
+
+#todo: configure libfminer Makefile (location of ruby.h)
+#-> fixed by using davor's repository
+
+
+cd ../opentox-algorithm
+echo "Installing fminer"
+echo "This could take a while..."
+sudo updatedb
+sudo rake fminer:install | tee -a $INSTALLLOG
+cd ..
+FMINERVERSION=`ls $STARTPATH/webservices/opentox-algorithm/libfminer | grep "fminer.so"`
+if [ "$FMINERVERSION" == "fminer.so" ]
+then
+ echo "================================================="
+ echo "Fminer successfully installed."
+ echo "================================================="
+else
+ echo "Fminer installation failed."
+ FAILED=1
+ exit $FAILED
+fi
+
+if [ $FAILED == 0 ]
+then
+ #get username
+ echo "Please enter username:"
+ read USERNAME
+
+ #change rights from root to user
+ sudo chown -R $USERNAME: $STARTPATH/webservices/
+ sudo chown -R $USERNAME: ~/.opentox/
+fi
+
+if [ "$FAILED" == "1" ]
+then
+ echo "================================================="
+ echo "Installation script failed!"
+ echo "================================================="
+ exit 1
+else
+echo "================================================="
+echo "opentox-install-script is completed."
+echo "================================================="
+echo "Configuration:"
+echo "Edit the settings in $HOME/.opentox/config/{development|production|test}.yaml for your environment."
+echo "================================================="
+echo "Start the webservices local:"
+echo "cd webservices/opentox-test/"
+echo "rake opentox:services:start"
+echo "================================================="
+echo "Test local webservices:"
+echo "rake features"
+echo "================================================="
+fi
+exit 0
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 25ae4cb..817340f 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -1,27 +1,35 @@
+LOGGER.progname = File.expand_path(__FILE__)
+
module OpenTox
- module Algorithm
+ module Algorithm
- class Fminer
- include Owl
+ class Fminer
+ include Owl
- def initialize
- super
- self.uri = File.join(@@config[:services]["opentox-algorithm"],'fminer')
- self.title = "fminer"
- self.source = "http://github.com/amaunz/libfminer"
- self.parameters = {
- "Dataset URI" => { :scope => "mandatory", :value => "dataset_uri" },
- "Feature URI for dependent variable" => { :scope => "mandatory", :value => "feature_uri" }
- }
- end
+ def initialize
+ super
+ self.uri = File.join(@@config[:services]["opentox-algorithm"],'fminer')
+ self.title = "fminer"
+ self.source = "http://github.com/amaunz/libfminer"
+ self.parameters = {
+ "Dataset URI" => { :scope => "mandatory", :value => "dataset_uri" },
+ "Feature URI for dependent variable" => { :scope => "mandatory", :value => "feature_uri" }
+ }
+ end
+
+ def self.create_feature_dataset(params)
+ LOGGER.debug File.basename(__FILE__) + ": creating feature dataset"
+ resource = RestClient::Resource.new(params[:feature_generation_uri], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.post :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri]
+ end
- def self.create_feature_dataset(params)
- RestClient.post params[:feature_generation_uri], :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri]
+ def self.uri
+ File.join(@@config[:services]["opentox-algorithm"], "fminer")
end
- end
+ end
- class Lazar
- include Owl
+ class Lazar
+ include Owl
def initialize
super
@@ -40,26 +48,33 @@ module OpenTox
def self.create_model(params)
LOGGER.debug params
- @uri = RestClient.post File.join(@@config[:services]["opentox-algorithm"], "lazar"), :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")
+ LOGGER.debug File.basename(__FILE__) + ": creating model"
+ #@uri = RestClient.post File.join(@@config[:services]["opentox-algorithm"], "lazar"), :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")
+ resource = RestClient::Resource.new(File.join(@@config[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ @uri = resource.post :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")
end
- end
-
- class Similarity
- def self.weighted_tanimoto(fp_a,fp_b,p)
- common_features = fp_a & fp_b
- all_features = fp_a + fp_b
- common_p_sum = 0.0
- if common_features.size > 0
- common_features.each{|f| common_p_sum += p[f]}
- all_p_sum = 0.0
- all_features.each{|f| all_p_sum += p[f]}
- common_p_sum/all_p_sum
- else
- 0.0
- end
+ def self.uri
+ File.join(@@config[:services]["opentox-algorithm"], "lazar")
end
- end
- end
+ end
+
+ class Similarity
+ def self.weighted_tanimoto(fp_a,fp_b,p)
+ common_features = fp_a & fp_b
+ all_features = fp_a + fp_b
+ common_p_sum = 0.0
+ if common_features.size > 0
+ common_features.each{|f| common_p_sum += p[f]}
+ all_p_sum = 0.0
+ all_features.each{|f| all_p_sum += p[f]}
+ common_p_sum/all_p_sum
+ else
+ 0.0
+ end
+ end
+ end
+
+ end
end
diff --git a/lib/authorization.rb b/lib/authorization.rb
new file mode 100644
index 0000000..9a1760a
--- /dev/null
+++ b/lib/authorization.rb
@@ -0,0 +1,24 @@
+helpers do
+
+ def protected!
+ response['WWW-Authenticate'] = %(Basic realm="Opentox Webservice Authentication") and \
+ throw(:halt, [401, "Not authorized\n"]) and \
+ return unless authorized?
+ end
+
+ def authorized?
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
+ @auth.provided? && @auth.basic? && @auth.credentials && valid_user?
+ end
+
+ def valid_user?
+ users = @@users[:users]
+ return @auth.credentials == [@auth.username, users.fetch(@auth.username)] if users.has_key?(@auth.username)
+ return false
+ end
+
+end
+
+before do
+ #protected! unless env['REQUEST_METHOD'] == "GET"
+end
diff --git a/lib/compound.rb b/lib/compound.rb
index 56646c0..0ee853d 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -17,7 +17,8 @@ module OpenTox
@inchi = sdf2inchi(params[:sdf])
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:name]
- @inchi = RestClient.get("#{@@cactus_uri}#{params[:name]}/stdinchi").chomp
+ # paranoid URI encoding to keep SMILES charges and brackets
+ @inchi = RestClient.get("#{@@cactus_uri}#{URI.encode(params[:name], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}/stdinchi").chomp
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:uri]
@uri = params[:uri]
diff --git a/lib/config/config_ru.rb b/lib/config/config_ru.rb
index 3720ef3..1d32c7e 100644
--- a/lib/config/config_ru.rb
+++ b/lib/config/config_ru.rb
@@ -10,6 +10,7 @@ $stdout.reopen(log)
$stderr.reopen(log)
$stdout.sync = true
$stderr.sync = true
+set :logging, false
set :raise_errors, true
['public','tmp'].each do |dir|
diff --git a/lib/dataset.rb b/lib/dataset.rb
index bd523a3..b5b2e06 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -1,3 +1,5 @@
+LOGGER.progname = File.expand_path(__FILE__)
+
module OpenTox
class Dataset
@@ -14,6 +16,8 @@ module OpenTox
data_entry = @model.subject OT['compound'], compound
if data_entry.nil?
data_entry = @model.create_resource
+ dataset = @model.subject(RDF['type'],OT[self.owl_class])
+ @model.add dataset, OT['dataEntry'], data_entry
@model.add data_entry, RDF['type'], OT["DataEntry"]
@model.add data_entry, OT['compound'], compound
end
@@ -29,6 +33,8 @@ module OpenTox
data_entry = @model.subject OT['compound'], compound
if data_entry.nil?
data_entry = @model.create_resource
+ dataset = @model.subject(RDF['type'],OT[self.owl_class])
+ @model.add dataset, OT['dataEntry'], data_entry
@model.add data_entry, RDF['type'], OT["DataEntry"]
@model.add data_entry, OT['compound'], compound
end
@@ -57,7 +63,7 @@ module OpenTox
def find_or_create_compound(uri)
compound = @model.subject(DC["identifier"], uri)
if compound.nil?
- compound = @model.create_resource
+ compound = @model.create_resource(uri)
@model.add compound, RDF['type'], OT["Compound"]
@model.add compound, DC["identifier"], uri
end
@@ -68,7 +74,7 @@ module OpenTox
def find_or_create_feature(uri)
feature = @model.subject(DC["identifier"], uri)
if feature.nil?
- feature = @model.create_resource
+ feature = @model.create_resource(uri)
@model.add feature, RDF['type'], OT["Feature"]
@model.add feature, DC["identifier"], uri
@model.add feature, DC["title"], File.basename(uri).split(/#/)[1]
@@ -78,7 +84,8 @@ module OpenTox
end
def self.create(data, content_type = 'application/rdf+xml')
- uri = RestClient.post @@config[:services]["opentox-dataset"], data, :content_type => content_type
+ resource = RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ uri = resource.post data, :content_type => content_type
dataset = Dataset.new
dataset.read uri.to_s
dataset
@@ -86,7 +93,9 @@ module OpenTox
def self.find(uri)
dataset = Dataset.new
+ LOGGER.debug "Getting data from #{uri}"
data = `curl "#{uri}"`
+ #LOGGER.debug data
#data = RestClient.get(uri, :accept => 'application/rdf+xml') # unclear why this does not work for complex uris, Dataset.find works from irb
dataset.rdf = data
dataset
@@ -152,11 +161,24 @@ module OpenTox
# Delete a dataset
def delete
- RestClient.delete @uri
- end
+ resource = RestClient::Resource.new(@uri, :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.delete
+ end
def save
- RestClient.post(@@config[:services]["opentox-dataset"], self.rdf, :content_type => "application/rdf+xml").to_s
+ LOGGER.debug "Saving dataset"
+ #task_uri = RestClient.post(@@config[:services]["opentox-dataset"], self.rdf, :content_type => "application/rdf+xml").to_s
+ task_uri = RestClient::Resource.new(@@config[:services]["opentox-dataset"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0]).post(self.rdf, :content_type => "application/rdf+xml").to_s
+ task = OpenTox::Task.find(task_uri)
+ LOGGER.debug "Waiting for task #{task_uri}"
+ task.wait_for_completion
+ LOGGER.debug "Dataset task #{task_uri} completed"
+ if task.failed?
+ LOGGER.error "Saving dataset failed"
+ task.failed
+ exit
+ end
+ task.resource
end
def to_yaml
diff --git a/lib/environment.rb b/lib/environment.rb
index fedc3cf..9338ca5 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -6,6 +6,7 @@ ENV['RACK_ENV'] = 'test' unless ENV['RACK_ENV']
basedir = File.join(ENV['HOME'], ".opentox")
config_dir = File.join(basedir, "config")
config_file = File.join(config_dir, "#{ENV['RACK_ENV']}.yaml")
+user_file = File.join(config_dir, "users.yaml")
TMP_DIR = File.join(basedir, "tmp")
LOG_DIR = File.join(basedir, "log")
@@ -15,6 +16,7 @@ if File.exist?(config_file)
else
FileUtils.mkdir_p TMP_DIR
FileUtils.mkdir_p LOG_DIR
+ FileUtils.mkdir_p config_dir
FileUtils.cp(File.join(File.dirname(__FILE__), 'templates/config.yaml'), config_file)
puts "Please edit #{config_file} and restart your application."
exit
@@ -43,6 +45,21 @@ logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log"
LOGGER = Logger.new(logfile,'daily') # daily rotation
LOGGER.level = Logger::DEBUG
+if File.exist?(user_file)
+ @@users = YAML.load_file(user_file)
+else
+ FileUtils.cp(File.join(File.dirname(__FILE__), 'templates/users.yaml'), user_file)
+ puts "Please edit #{user_file} and restart your application."
+ exit
+end
+
+begin
+ 0 < @@users[:users].keys.length
+rescue
+ puts "Please edit #{user_file} and restart your application. Create at least one user with password."
+ exit
+end
+
# RDF namespaces
RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
diff --git a/lib/model.rb b/lib/model.rb
index a585b59..b5129d7 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -24,7 +24,7 @@ module OpenTox
lazar.algorithm = File.join(@@config[:services]["opentox-algorithm"],"lazar")
lazar.trainingDataset = yaml[:activity_dataset]
lazar.dependentVariables = yaml[:endpoint]
- lazar.predictedVariables = yaml[:endpoint] #+ " lazar prediction"
+ lazar.predictedVariables = yaml[:endpoint] + "_lazar_prediction"
lazar
end
@@ -39,15 +39,25 @@ module OpenTox
# Predict a compound
def predict(compound)
- RestClient.post(@uri, :compound_uri => compound.uri)
+ # nicht absichern??
+ resource = RestClient::Resource.new(@uri, :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.post(:compound_uri => compound.uri)
end
def self.base_uri
- @@config[:services]["opentox-model"]
+ File.join @@config[:services]["opentox-model"],'lazar'
end
def self.create(data)
- RestClient.post(@@config[:services]["opentox-model"], data, :content_type => "application/x-yaml").to_s
+ resource = RestClient::Resource.new(@@config[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.post(data, :content_type => "application/x-yaml").to_s
+ end
+
+ def delete
+ resource = RestClient::Resource.new(self.uri, :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.delete
+ #RestClient.delete @uri if @uri
+ #RestClient.delete model.task_uri if model.task_uri
end
# def self.create(task)
diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb
index ca57fc9..849043c 100644
--- a/lib/opentox-ruby-api-wrapper.rb
+++ b/lib/opentox-ruby-api-wrapper.rb
@@ -8,6 +8,6 @@ rescue LoadError
puts "Please install Openbabel with 'rake openbabel:install' in the compound component"
end
-['owl', 'compound','dataset','algorithm','model','task','utils'].each do |lib|
+['owl', 'compound','dataset','algorithm','model','task','validation','utils','authorization'].each do |lib|
require lib
end
diff --git a/lib/owl.rb b/lib/owl.rb
index a843e59..82d6e0e 100644
--- a/lib/owl.rb
+++ b/lib/owl.rb
@@ -16,7 +16,6 @@ module OpenTox
# reate an anonymous resource for metadata
# this has to be rewritten with an URI as soon as the resource has been saved at an definitive location
tmp = @model.create_resource
- @model.add tmp, RDF['type'], OWL['Ontology']
@model.add tmp, RDF['type'], OT[self.owl_class]
end
diff --git a/lib/task.rb b/lib/task.rb
index 70d22bf..f507a22 100644
--- a/lib/task.rb
+++ b/lib/task.rb
@@ -1,3 +1,5 @@
+LOGGER.progname = File.expand_path(__FILE__)
+
module OpenTox
class Task
@@ -10,7 +12,10 @@ module OpenTox
end
def self.create
- uri = RestClient.post @@config[:services]["opentox-task"], {}
+ #uri = RestClient.post @@config[:services]["opentox-task"], {}
+ resource = RestClient::Resource.new(@@config[:services]["opentox-task"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ #uri = resource.post(nil)
+ uri = resource.post({})
Task.new(uri)
end
@@ -26,7 +31,7 @@ module OpenTox
task_uris = RestClient.get(@@config[:services]["opentox-task"]).split(/\n/)
task_uris.collect{|uri| Task.new(uri)}
end
-
+
def created_at
RestClient.get File.join(@uri, 'created_at')
end
@@ -42,7 +47,24 @@ module OpenTox
def resource
RestClient.get File.join(@uri, 'resource')
end
+
+ def started
+ LOGGER.info File.join(@uri,'started')
+ resource = RestClient::Resource.new(File.join(@uri,'started'), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.put({})
+ end
+
+ def cancel
+ resource = RestClient::Resource.new(@File.join(@uri,'cancelled'), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.put({})
+ end
+
+ def completed(uri)
+ resource = RestClient::Resource.new(File.join(@uri,'completed'), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.put :resource => uri
+ end
+=begin
def started
RestClient.put File.join(@uri,'started'), {}
end
@@ -51,20 +73,27 @@ module OpenTox
RestClient.put File.join(@uri,'cancelled'), {}
end
- def failed
- RestClient.put File.join(@uri,'failed'), {}
+ def completed(uri)
+ RestClient.put File.join(@uri,'completed'), :resource => uri
end
- def parent=(task)
- RestClient.put File.join(@uri,'parent'), {:uri => task.uri}
+=end
+ def failed
+ #RestClient.put File.join(@uri,'failed'), {}
+ resource = RestClient::Resource.new(@File.join(@uri,'failed'), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.put({})
end
- def completed(uri)
- RestClient.put File.join(@uri,'completed'), :resource => uri
+ def parent=(task)
+ #RestClient.put File.join(@uri,'parent'), {:uri => task.uri}
+ resource = RestClient::Resource.new(File.join(@uri,'parent'), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ LOGGER.debug "task.rb: #{resource}"
+ resource.put :uri => task.uri
end
def pid=(pid)
- RestClient.put File.join(@uri, 'pid'), :pid => pid
+ resource = RestClient::Resource.new(File.join(@uri,'pid'), :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource.put :pid => pid
end
def completed?
diff --git a/lib/templates/users.yaml b/lib/templates/users.yaml
new file mode 100644
index 0000000..483fd7b
--- /dev/null
+++ b/lib/templates/users.yaml
@@ -0,0 +1,5 @@
+# please insert users and passwords here.
+# one user and password each line. uncomment the line.
+:users:
+# username: "secretpassword"
+# exampleuser: "ih9aiTog" \ No newline at end of file
diff --git a/lib/validation.rb b/lib/validation.rb
new file mode 100644
index 0000000..6fd5704
--- /dev/null
+++ b/lib/validation.rb
@@ -0,0 +1,21 @@
+module OpenTox
+ class Validation
+
+ attr_accessor :uri
+
+ def initialize(params)
+ resource = RestClient::Resource.new(params[:uri], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ @uri = resource.post(params).to_s
+ end
+
+ def self.crossvalidation(params)
+ params[:uri] = File.join(@@config[:services]['opentox-validation'], "crossvalidation")
+ params[:num_folds] = 10 unless params[:num_folds]
+ params[:random_seed] = 2 unless params[:random_seed]
+ params[:stratified] = false unless params[:stratified]
+ OpenTox::Validation.new(params)
+ end
+
+ end
+end
+
diff --git a/opentox-ruby-api-wrapper.gemspec b/opentox-ruby-api-wrapper.gemspec
index 75f5d6b..9500df4 100644
--- a/opentox-ruby-api-wrapper.gemspec
+++ b/opentox-ruby-api-wrapper.gemspec
@@ -5,14 +5,14 @@
Gem::Specification.new do |s|
s.name = %q{opentox-ruby-api-wrapper}
- s.version = "1.2.7"
+ s.version = "1.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Christoph Helma"]
- s.date = %q{2010-02-08}
+ s.date = %q{2010-03-01}
s.description = %q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)}
s.email = %q{helma@in-silico.ch}
- s.executables = ["opentox-install-debian.sh", "yaml2owl.rb"]
+ s.executables = ["opentox-install-ubuntu.sh", "opentox-install-debian.sh", "yaml2owl.rb"]
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
@@ -23,11 +23,12 @@ Gem::Specification.new do |s|
"Rakefile",
"VERSION",
"bin/opentox-install-debian.sh",
+ "bin/opentox-install-ubuntu.sh",
"bin/yaml2owl.rb",
"lib/algorithm.rb",
+ "lib/authorization.rb",
"lib/compound.rb",
"lib/config/config_ru.rb",
- "lib/config/database.rb",
"lib/dataset.rb",
"lib/environment.rb",
"lib/helper.rb",
@@ -39,7 +40,9 @@ Gem::Specification.new do |s|
"lib/task.rb",
"lib/tasks/opentox.rb",
"lib/templates/config.yaml",
- "lib/utils.rb"
+ "lib/templates/users.yaml",
+ "lib/utils.rb",
+ "lib/validation.rb"
]
s.homepage = %q{http://github.com/helma/opentox-ruby-api-wrapper}
s.rdoc_options = ["--charset=UTF-8"]
@@ -63,9 +66,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<dm-more>, [">= 0"])
s.add_runtime_dependency(%q<dm-core>, [">= 0"])
s.add_runtime_dependency(%q<sinatra-static-assets>, [">= 0"])
- s.add_runtime_dependency(%q<do_sqlite3>, [">= 0"])
- s.add_runtime_dependency(%q<do_postgres>, [">= 0"])
- s.add_development_dependency(%q<cucumber>, [">= 0"])
+ s.add_development_dependency(%q<cucmber>, [">= 0"])
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
else
s.add_dependency(%q<sinatra>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
@@ -78,9 +80,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<dm-more>, [">= 0"])
s.add_dependency(%q<dm-core>, [">= 0"])
s.add_dependency(%q<sinatra-static-assets>, [">= 0"])
- s.add_dependency(%q<do_sqlite3>, [">= 0"])
- s.add_dependency(%q<do_postgres>, [">= 0"])
- s.add_dependency(%q<cucumber>, [">= 0"])
+ s.add_dependency(%q<cucmber>, [">= 0"])
+ s.add_dependency(%q<jeweler>, [">= 0"])
end
else
s.add_dependency(%q<sinatra>, [">= 0"])
@@ -94,9 +95,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<dm-more>, [">= 0"])
s.add_dependency(%q<dm-core>, [">= 0"])
s.add_dependency(%q<sinatra-static-assets>, [">= 0"])
- s.add_dependency(%q<do_sqlite3>, [">= 0"])
- s.add_dependency(%q<do_postgres>, [">= 0"])
- s.add_dependency(%q<cucumber>, [">= 0"])
+ s.add_dependency(%q<cucmber>, [">= 0"])
+ s.add_dependency(%q<jeweler>, [">= 0"])
end
end