From 64354959e04fcac11bcf70e75099691b74573033 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 16 Aug 2011 14:46:31 +0200 Subject: initial minimal version --- README.markdown | 12 +- Rakefile | 50 +++--- bin/opentox-install-debian.sh | 105 ------------ bin/opentox-install-ubuntu.sh | 375 ------------------------------------------ lib/algorithm.rb | 15 +- lib/authorization.rb | 4 +- lib/compound.rb | 21 +-- lib/dataset.rb | 164 ++++++++---------- lib/environment.rb | 12 +- lib/error.rb | 1 - lib/feature.rb | 6 +- lib/helper.rb | 3 +- lib/model.rb | 66 +++++--- lib/opentox-ruby.rb | 17 +- lib/opentox.rb | 16 +- lib/overwrite.rb | 4 + lib/to-html.rb | 1 - 17 files changed, 193 insertions(+), 679 deletions(-) delete mode 100644 bin/opentox-install-debian.sh delete mode 100755 bin/opentox-install-ubuntu.sh diff --git a/README.markdown b/README.markdown index 79bdab2..5f12ad9 100644 --- a/README.markdown +++ b/README.markdown @@ -1,12 +1,14 @@ -opentox-ruby -============ +opentox-ruby-minimal +==================== -Ruby wrapper for the [OpenTox](http://www.opentox.org) REST API +Thin Ruby wrapper for the [OpenTox](http://www.opentox.org) REST API Installation ------------ -opentox-ruby depends on many third party programs and libraries, which makes the setup complicated and error prone. For this reason we recommend to use the installer from [opentox-install](http://github.com/opentox/opentox-install). If you want to install manually you can find the necessary steps in the installation scripts. + sudo gem install opentox-ruby-minimal + +opentox-ruby depends on [rapper](http://librdf.org/raptor/rapper.html) for parsing OWL-DL in RDFXML format. Quickstart ---------- @@ -32,7 +34,7 @@ This example shows how to create a lazar model and predict a compound, it assume prediction = OpenTox::LazarPrediction.find(prediction_uri, subjectid) puts prediction.to_yaml -[API documentation](http://rdoc.info/gems/opentox-ruby/1.0.0/frames) +[API documentation](http://rdoc.info/gems/opentox-ruby-minimal) ------------------------------------------------------------------- Copyright diff --git a/Rakefile b/Rakefile index 4fb851e..7e0bcf9 100644 --- a/Rakefile +++ b/Rakefile @@ -4,43 +4,43 @@ require 'rake' begin require 'jeweler' Jeweler::Tasks.new do |gem| - gem.name = "opentox-ruby" + gem.name = "opentox-ruby-minimal" gem.summary = %Q{Ruby wrapper for the OpenTox REST API} gem.description = %Q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)} gem.email = "helma@in-silico.ch" - gem.homepage = "http://github.com/helma/opentox-ruby" + gem.homepage = "http://github.com/opentox/opentox-ruby-minimal" gem.authors = ["Christoph Helma, Martin Guetlein, Andreas Maunz, Micha Rautenberg, David Vorgrimmler"] # dependencies with versions - gem.add_dependency "sinatra", "=1.2.6" - gem.add_dependency "emk-sinatra-url-for", "=0.2.1" - gem.add_dependency "sinatra-respond_to", "=0.7.0" - gem.add_dependency "sinatra-static-assets", "=0.5.0" +# gem.add_dependency "sinatra", "=1.2.6" +# gem.add_dependency "emk-sinatra-url-for", "=0.2.1" +# gem.add_dependency "sinatra-respond_to", "=0.7.0" +# gem.add_dependency "sinatra-static-assets", "=0.5.0" gem.add_dependency "rest-client", "=1.6.1" - gem.add_dependency "rack", "=1.3.0" - gem.add_dependency "rack-contrib", "=1.1.0" - gem.add_dependency "rack-flash", "=0.1.1" +# gem.add_dependency "rack", "=1.3.0" +# gem.add_dependency "rack-contrib", "=1.1.0" +# gem.add_dependency "rack-flash", "=0.1.1" gem.add_dependency "nokogiri", "=1.4.4" - gem.add_dependency "rubyzip", "=0.9.4" +# gem.add_dependency "rubyzip", "=0.9.4" gem.add_dependency "roo", "=1.9.3" gem.add_dependency "spreadsheet", "=0.6.5.4" gem.add_dependency "google-spreadsheet-ruby", "=0.1.5" gem.add_dependency "yajl-ruby", "=0.8.2" #gem.add_dependency "mail", "=2.3.0" - gem.add_dependency "rinruby", "=2.0.2" - gem.add_dependency "ohm", "=0.1.3" - gem.add_dependency "ohm-contrib", "=0.1.1" - gem.add_dependency "SystemTimer", "=1.2.3" - gem.add_dependency "rjb", "=1.3.4" - gem.add_dependency "haml", "=3.1.1" +# gem.add_dependency "rinruby", "=2.0.2" +# gem.add_dependency "ohm", "=0.1.3" +# gem.add_dependency "ohm-contrib", "=0.1.1" +# gem.add_dependency "SystemTimer", "=1.2.3" +# gem.add_dependency "rjb", "=1.3.4" +# gem.add_dependency "haml", "=3.1.1" #valiation-gems - gem.add_dependency "dm-core", "=1.1.0" - gem.add_dependency "dm-serializer", "=1.1.0" - gem.add_dependency "dm-timestamps", "=1.1.0" - gem.add_dependency "dm-types", "=1.1.0" - gem.add_dependency "dm-migrations", "=1.1.0" - gem.add_dependency "dm-validations", "=1.1.0" - gem.add_dependency "dm-sqlite-adapter", "=1.1.0" - gem.add_dependency "ruby-plot", "=0.5.0" +# gem.add_dependency "dm-core", "=1.1.0" +# gem.add_dependency "dm-serializer", "=1.1.0" +# gem.add_dependency "dm-timestamps", "=1.1.0" +# gem.add_dependency "dm-types", "=1.1.0" +# gem.add_dependency "dm-migrations", "=1.1.0" +# gem.add_dependency "dm-validations", "=1.1.0" +# gem.add_dependency "dm-sqlite-adapter", "=1.1.0" +# gem.add_dependency "ruby-plot", "=0.5.0" gem.add_development_dependency 'jeweler' gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*", 'lib/jeweler/templates/.gitignore'] @@ -83,7 +83,7 @@ Rake::RDocTask.new do |rdoc| end rdoc.rdoc_dir = 'rdoc' - rdoc.title = "opentox-ruby #{version}" + rdoc.title = "opentox-ruby-minimal #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end diff --git a/bin/opentox-install-debian.sh b/bin/opentox-install-debian.sh deleted file mode 100644 index cf173da..0000000 --- a/bin/opentox-install-debian.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash -#Installation is tested on Debian Lenny Ubuntu 9.04 -#Update the system - -ERRLOG='install_err.log' -INSTALLLOG='install_log.log' -DATE=$(date +%Y/%m/%d\ %H:%M:%S) - -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 unshure check with it 'sudo ls'" -echo "and installed it with 'apt-get install sudo'" -echo "and add your username with visudo." -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 "Installing: build-essential" -sudo apt-get install build-essential >> $INSTALLLOG 2>>$ERRLOG -echo "Installing: ruby 1.8 with its dev files" -sudo apt-get install ruby ruby1.8-dev >> $INSTALLLOG 2>>$ERRLOG -echo "Installing: gems rdoc rubygems and rake" -sudo apt-get install gems rdoc rubygems rake >> $INSTALLLOG 2>>$ERRLOG - -echo "Installing rubygems from source. This may take some time" -wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz >> $INSTALLLOG 2>>$ERRLOG -tar xzfv rubygems-1.3.5.tgz 2>>$ERRLOG -cd rubygems-1.3.5 >> $INSTALLLOG 2>>$ERRLOG -sudo ruby setup.rb 2>>$ERRLOG -cd .. - -echo "Adding http://gems.github.com to ruby gem sources" -sudo gem sources -a http://gems.github.com >> $INSTALLLOG 2>>$ERRLOG - -#for debian lenny: -echo "Installing packages: zlib1g-dev tcl curl perl ssh tcl tk8.5" -sudo apt-get install zlib1g-dev tcl curl perl ssh tcl tk8.5 >> $INSTALLLOG 2>>$ERRLOG -echo "Installing git from source" -wget http://www.kernel.org/pub/software/scm/git/git-1.6.5.2.tar.gz >> $INSTALLLOG 2>>$ERRLOG -tar xzfv git-1.6.5.2.tar.gz 2>>$ERRLOG -cd git-1.6.5.2 >> $INSTALLLOG 2>>$ERRLOG -./configure 2>>$ERRLOG -make 2>>$ERRLOG -make install 2>>$ERRLOG - -echo "Installing the opentox webservices" -mkdir webservices >> $INSTALLLOG 2>>$ERRLOG -cd webservices >> $INSTALLLOG 2>>$ERRLOG - -git clone git://github.com/helma/opentox-compound.git >> $INSTALLLOG 2>>$ERRLOG -git clone git://github.com/helma/opentox-feature.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-test.git >> $INSTALLLOG 2>>$ERRLOG - -cd opentox-compound >> $INSTALLLOG 2>>$ERRLOG -git checkout -b development origin/development >> $INSTALLLOG 2>>$ERRLOG -cd ../opentox-feature >> $INSTALLLOG 2>>$ERRLOG -git checkout -b development origin/development >> $INSTALLLOG 2>>$ERRLOG -cd ../opentox-dataset >> $INSTALLLOG 2>>$ERRLOG -git checkout -b development origin/development >> $INSTALLLOG 2>>$ERRLOG -cd ../opentox-algorithm >> $INSTALLLOG 2>>$ERRLOG -git checkout -b development origin/development >> $INSTALLLOG 2>>$ERRLOG -cd ../opentox-model >> $INSTALLLOG 2>>$ERRLOG -git checkout -b development origin/development >> $INSTALLLOG 2>>$ERRLOG -cd .. >> $INSTALLLOG 2>>$ERRLOG -git clone git://github.com/helma/opentox-ruby-api-wrapper.git >> $INSTALLLOG 2>>$ERRLOG -cd opentox-ruby-api-wrapper >> $INSTALLLOG 2>>$ERRLOG -git checkout -b development origin/development >> $INSTALLLOG 2>>$ERRLOG -rake install >> $INSTALLLOG 2>>$ERRLOG - - -cd ../opentox-compound >> $INSTALLLOG 2>>$ERRLOG -echo "Installing libopenssl-ruby" -sudo apt-get install libopenssl-ruby >> $INSTALLLOG 2>>$ERRLOG -echo "Installing dtach" -rake dtach:install >> $INSTALLLOG 2>>$ERRLOG -echo "Installing openbabel" -rake openbabel:install >> $INSTALLLOG 2>>$ERRLOG - -#debian lenny missed liblink: -ln -s /usr/local/lib/libopenbabel.so.3 /usr/lib/libopenbabel.so.3 >> $INSTALLLOG 2>>$ERRLOG - -rake redis:download >> $INSTALLLOG 2>>$ERRLOG -rake redis:install >> $INSTALLLOG 2>>$ERRLOG -#edit /home/[username]/.opentox/config/test.yaml set :base_dir: /home/[username]/webservices -sudo apt-get install libgsl0-dev >> $INSTALLLOG 2>>$ERRLOG -sudo apt-get install swig >> $INSTALLLOG 2>>$ERRLOG -sudo apt-get install curl >> $INSTALLLOG 2>>$ERRLOG -cd ../opentox-algorithm >> $INSTALLLOG 2>>$ERRLOG -echo "Installing fminer" -rake fminer:install >> $INSTALLLOG 2>>$ERRLOG -sudo apt-get install libsqlite3-dev >> $INSTALLLOG 2>>$ERRLOG - - -mkdir ../opentox-model/db >> $INSTALLLOG 2>>$ERRLOG diff --git a/bin/opentox-install-ubuntu.sh b/bin/opentox-install-ubuntu.sh deleted file mode 100755 index ae4807d..0000000 --- a/bin/opentox-install-ubuntu.sh +++ /dev/null @@ -1,375 +0,0 @@ -#!/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 sinatra-respond_to | 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 2652695..4c50d32 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -1,8 +1,8 @@ # R integration # workaround to initialize R non-interactively (former rinruby versions did this by default) # avoids compiling R with X -R = nil -require "rinruby" +#R = nil +#require "rinruby" module OpenTox @@ -16,6 +16,7 @@ module OpenTox # @param [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly # @return [String] URI of new resource (dataset, model, ...) def run(params=nil, waiting_task=nil) + #puts @uri RestClientWrapper.post(@uri, params, {:accept => 'text/uri-list'}, waiting_task).to_s end @@ -37,7 +38,7 @@ module OpenTox def self.find(uri, subjectid=nil) return nil unless uri alg = Generic.new(uri) - alg.load_metadata( subjectid ) + alg.load_metadata raise "cannot load algorithm metadata" if alg.metadata==nil or alg.metadata.size==0 alg end @@ -54,7 +55,7 @@ module OpenTox # Initialize bbrc algorithm def initialize(subjectid=nil) super File.join(CONFIG[:services]["opentox-algorithm"], "fminer/bbrc") - load_metadata(subjectid) + load_metadata end end @@ -64,7 +65,7 @@ module OpenTox # Initialize last algorithm def initialize(subjectid=nil) super File.join(CONFIG[:services]["opentox-algorithm"], "fminer/last") - load_metadata(subjectid) + load_metadata end end @@ -76,10 +77,11 @@ module OpenTox # Initialize lazar algorithm def initialize(subjectid=nil) super File.join(CONFIG[:services]["opentox-algorithm"], "lazar") - load_metadata(subjectid) + load_metadata end end +=begin # Utility methods without dedicated webservices # Similarity calculations @@ -399,6 +401,7 @@ module OpenTox m_pos = array.size / 2 return array.size % 2 == 1 ? array[m_pos] : (array[m_pos-1] + array[m_pos])/2 end +=end end end diff --git a/lib/authorization.rb b/lib/authorization.rb index 288733a..27ae734 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -2,7 +2,7 @@ module OpenTox #Module for Authorization and Authentication #@example Authentication - # require "opentox-ruby-api-wrapper" + # require "opentox-ruby" # OpenTox::Authorization::AA_SERVER = "https://opensso.in-silico.ch" #if not set in .opentox/conf/[environment].yaml # token = OpenTox::Authorization.authenticate("benutzer", "passwort") #@see http://www.opentox.org/dev/apis/api-1.2/AA OpenTox A&A API 1.2 specification @@ -389,4 +389,4 @@ module OpenTox end end -end \ No newline at end of file +end diff --git a/lib/compound.rb b/lib/compound.rb index a85507b..189db7b 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -29,30 +29,21 @@ module OpenTox # @param [String] smiles Smiles string # @return [OpenTox::Compound] Compound def self.from_smiles(smiles) - c = Compound.new - c.inchi = Compound.smiles2inchi(smiles) - c.uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(c.inchi)) - c + Compound.new RestClientWrapper.post(CONFIG[:services]["opentox-compound"], smiles, :content_type => 'chemical/x-daylight-smiles').to_s.chomp end # Create a compound from inchi string # @param [String] smiles InChI string # @return [OpenTox::Compound] Compound def self.from_inchi(inchi) - c = Compound.new - c.inchi = inchi - c.uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(c.inchi)) - c + Compound.new RestClientWrapper.post(CONFIG[:services]["opentox-compound"], inchi, :content_type => 'chemical/x-inchi').to_s.chomp end # Create a compound from sdf string # @param [String] smiles SDF string # @return [OpenTox::Compound] Compound def self.from_sdf(sdf) - c = Compound.new - c.inchi = Compound.sdf2inchi(sdf) - c.uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(c.inchi)) - c + Compound.new RestClientWrapper.post(CONFIG[:services]["opentox-compound"], sdf, :content_type => 'chemical/x-mdl-sdfile').to_s.chomp end # Create a compound from name. Relies on an external service for name lookups. @@ -77,13 +68,13 @@ module OpenTox # Get (canonical) smiles # @return [String] Smiles string def to_smiles - Compound.obconversion(@inchi,'inchi','can') + RestClientWrapper.get(@uri, :accept => 'chemical/x-daylight-smiles').chomp end # Get sdf # @return [String] SDF string def to_sdf - Compound.obconversion(@inchi,'inchi','sdf') + RestClientWrapper.get(@uri, :accept => 'chemical/x-mdl-sdfile').chomp end # Get gif image @@ -118,6 +109,7 @@ module OpenTox end end +=begin # Match a smarts string # @example # compound = OpenTox::Compound.from_name("Benzene") @@ -195,5 +187,6 @@ module OpenTox obconversion.write_string(obmol) end end +=end end end diff --git a/lib/dataset.rb b/lib/dataset.rb index 5e6a29b..84dce65 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -1,6 +1,7 @@ module OpenTox # Ruby wrapper for OpenTox Dataset Webservices (http://opentox.org/dev/apis/api-1.2/dataset). + # TODO: fix API Doc class Dataset include OpenTox @@ -15,7 +16,7 @@ module OpenTox # @param [optional, String] uri Dataset URI # @return [OpenTox::Dataset] Dataset object def initialize(uri=nil,subjectid=nil) - super uri + super uri, subjectid @features = {} @compounds = [] @data_entries = {} @@ -28,7 +29,17 @@ module OpenTox # @return [OpenTox::Dataset] Dataset object def self.create(uri=CONFIG[:services]["opentox-dataset"], subjectid=nil) dataset = Dataset.new(nil,subjectid) - dataset.save(subjectid) + dataset.save + dataset + end + + # Find a dataset and load all data. This can be time consuming, use Dataset.new together with one of the load_* methods for a fine grained control over data loading. + # @param [String] uri Dataset URI + # @return [OpenTox::Dataset] Dataset object with all data + def self.find(uri, subjectid=nil) + return nil unless uri + dataset = Dataset.new(uri, subjectid) + dataset.load_metadata dataset end @@ -40,20 +51,9 @@ module OpenTox # @return [OpenTox::Dataset] Dataset object with CSV data def self.create_from_csv_file(file, subjectid=nil) dataset = Dataset.create(CONFIG[:services]["opentox-dataset"], subjectid) - parser = Parser::Spreadsheets.new - parser.dataset = dataset - parser.load_csv(File.open(file).read) - dataset.save(subjectid) - dataset - end - - # Find a dataset and load all data. This can be time consuming, use Dataset.new together with one of the load_* methods for a fine grained control over data loading. - # @param [String] uri Dataset URI - # @return [OpenTox::Dataset] Dataset object with all data - def self.find(uri, subjectid=nil) - return nil unless uri - dataset = Dataset.new(uri, subjectid) - dataset.load_all(subjectid) + #RestClientWrapper.post(dataset.uri,File.read(file), {:content_type => "text/csv", :subjectid => @subjectid}) + RestClientWrapper.post(dataset.uri,{:file => File.new(file)},{:accept => "text/uri-list", :subjectid => subjectid})#, {:content_type => "text/csv", :subjectid => @subjectid}) + dataset.load_metadata dataset end @@ -64,7 +64,7 @@ module OpenTox return false unless uri dataset = Dataset.new(uri, subjectid) begin - dataset.load_metadata( subjectid ).size > 0 + dataset.load_metadata.size > 0 rescue false end @@ -80,26 +80,20 @@ module OpenTox # Load YAML representation into the dataset # @param [String] yaml YAML representation of the dataset # @return [OpenTox::Dataset] Dataset object with YAML data - def load_yaml(yaml) - copy YAML.load(yaml) + def store_yaml(yaml) + RestClientWrapper.post(@uri,yaml, {:content_type => "application/x-yaml", :subjectid => @subjectid}) end - def load_rdfxml(rdfxml) - raise "rdfxml data is empty" if rdfxml.to_s.size==0 - file = Tempfile.new("ot-rdfxml") - file.puts rdfxml - file.close - load_rdfxml_file file - file.delete + def store_rdfxml(rdfxml) + RestClientWrapper.post(@uri, rdfxml, {:content_type => "application/rdf+xml", :subjectid => @subjectid}) end # Load RDF/XML representation from a file # @param [String] file File with RDF/XML representation of the dataset # @return [OpenTox::Dataset] Dataset object with RDF/XML data - def load_rdfxml_file(file, subjectid=nil) - parser = Parser::Owl::Dataset.new @uri, subjectid - parser.uri = file.path - copy parser.load_uri(subjectid) + def store_rdfxml_file(file) + #RestClientWrapper.post(@uri, :file => File.new(file))#, {:content_type => "application/rdf+xml", :subjectid => @subjectid}) + RestClientWrapper.post(@uri, File.read(file), {:content_type => "application/rdf+xml", :subjectid => @subjectid}) end # Load CSV string (format specification: http://toxcreate.org/help) @@ -108,11 +102,8 @@ module OpenTox # - you will have to set remaining metadata manually # @param [String] csv CSV representation of the dataset # @return [OpenTox::Dataset] Dataset object with CSV data - def load_csv(csv, subjectid=nil) - save(subjectid) unless @uri # get a uri for creating features - parser = Parser::Spreadsheets.new - parser.dataset = self - parser.load_csv(csv) + def store_csv(csv) + RestClientWrapper.post(@uri, csv, {:content_type => "text/csv", :subjectid => @subjectid}) end # Load Spreadsheet book (created with roo gem http://roo.rubyforge.org/, excel format specification: http://toxcreate.org/help) @@ -121,35 +112,36 @@ module OpenTox # - you will have to set remaining metadata manually # @param [Excel] book Excel workbook object (created with roo gem) # @return [OpenTox::Dataset] Dataset object with Excel data - def load_spreadsheet(book, subjectid=nil) - save(subjectid) unless @uri # get a uri for creating features - parser = Parser::Spreadsheets.new - parser.dataset = self - parser.load_spreadsheet(book) + def store_spreadsheet_file(file) + RestClientWrapper.post(@uri, :file => File.new(file))#, {:content_type => "application/vnd.ms-excel", :subjectid => @subjectid}) end # Load and return only metadata of a Dataset object # @return [Hash] Metadata of the dataset - def load_metadata(subjectid=nil) - add_metadata Parser::Owl::Dataset.new(@uri, subjectid).load_metadata(subjectid) + def load_metadata + if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + @metadata = YAML.load(RestClientWrapper.get(File.join(@uri,"metadata"), {:accept => "application/x-yaml", :subjectid => @subjectid})) + else + add_metadata Parser::Owl::Dataset.new(@uri, @subjectid).load_metadata + end self.uri = @uri if @uri # keep uri @metadata end # Load all data (metadata, data_entries, compounds and features) from URI - def load_all(subjectid=nil) + def load_all if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) - copy YAML.load(RestClientWrapper.get(@uri, {:accept => "application/x-yaml", :subjectid => subjectid})) + copy YAML.load(RestClientWrapper.get(@uri, {:accept => "application/x-yaml", :subjectid => @subjectid})) else - parser = Parser::Owl::Dataset.new(@uri, subjectid) - copy parser.load_uri(subjectid) + parser = Parser::Owl::Dataset.new(@uri, @subjectid) + copy parser.load_uri end end # Load and return only compound URIs from the dataset service # @return [Array] Compound URIs in the dataset - def load_compounds(subjectid=nil) - RestClientWrapper.get(File.join(uri,"compounds"),{:accept=> "text/uri-list", :subjectid => subjectid}).to_s.each_line do |compound_uri| + def load_compounds + RestClientWrapper.get(File.join(uri,"compounds"),{:accept=> "text/uri-list", :subjectid => @subjectid}).to_s.each_line do |compound_uri| @compounds << compound_uri.chomp end @compounds.uniq! @@ -157,12 +149,12 @@ module OpenTox # Load and return only features from the dataset service # @return [Hash] Features of the dataset - def load_features(subjectid=nil) + def load_features if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) - @features = YAML.load(RestClientWrapper.get(File.join(@uri,"features"), {:accept => "application/x-yaml", :subjectid => subjectid})) + @features = YAML.load(RestClientWrapper.get(File.join(@uri,"features"), {:accept => "application/x-yaml", :subjectid => @subjectid})) else - parser = Parser::Owl::Dataset.new(@uri, subjectid) - @features = parser.load_features(subjectid) + parser = Parser::Owl::Dataset.new(@uri, @subjectid) + @features = parser.load_features end @features end @@ -171,6 +163,7 @@ module OpenTox # @param [String] feature the URI of the feature # @return [Array] return array with strings, nil if value is not set (e.g. when feature is numeric) def accept_values(feature) + load_features accept_values = features[feature][OT.acceptValue] accept_values.sort if accept_values accept_values @@ -178,8 +171,8 @@ module OpenTox # Detect feature type(s) in the dataset # @return [String] `classification", "regression", "mixed" or unknown` - def feature_type(subjectid=nil) - load_features(subjectid) + def feature_type + load_features feature_types = @features.collect{|f,metadata| metadata[RDF.type]}.flatten.uniq if feature_types.include?(OT.NominalFeature) "classification" @@ -189,13 +182,11 @@ module OpenTox "unknown" end end -=begin -=end # Get Spreadsheet representation # @return [Spreadsheet::Workbook] Workbook which can be written with the spreadsheet gem (data_entries only, metadata will will be discarded)) def to_spreadsheet - Serializer::Spreadsheets.new(self).to_spreadsheet + Spreadsheet::Workbook.new(RestClientWrapper.get(@uri, {:accept => "application/vnd.ms-excel", :subjectid => @subjectid})) end # Get Excel representation (alias for to_spreadsheet) @@ -207,33 +198,31 @@ module OpenTox # Get CSV string representation (data_entries only, metadata will be discarded) # @return [String] CSV representation def to_csv - Serializer::Spreadsheets.new(self).to_csv + RestClientWrapper.get(@uri, {:accept => "text/csv", :subjectid => @subjectid}) end # Get OWL-DL in ntriples format # @return [String] N-Triples representation def to_ntriples - s = Serializer::Owl.new - s.add_dataset(self) - s.to_ntriples + RestClientWrapper.get(@uri, {:accept => "application/rdf+xml", :subjectid => @subjectid}) end # Get OWL-DL in RDF/XML format # @return [String] RDF/XML representation def to_rdfxml - s = Serializer::Owl.new - s.add_dataset(self) - s.to_rdfxml + RestClientWrapper.get(@uri, {:accept => "application/rdf+xml", :subjectid => @subjectid}) end # Get name (DC.title) of a feature # @param [String] feature Feature URI # @return [String] Feture title def feature_name(feature) + load_features @features[feature][DC.title] end def title + load_metadata @metadata[DC.title] end @@ -251,14 +240,6 @@ module OpenTox @data_entries[compound][feature] << value if value!=nil end - # Add/modify metadata, existing entries will be overwritten - # @example - # dataset.add_metadata({DC.title => "any_title", DC.creator => "my_email"}) - # @param [Hash] metadata Hash mapping predicate_uris to values - def add_metadata(metadata) - metadata.each { |k,v| @metadata[k] = v } - end - # Add a feature # @param [String] feature Feature URI # @param [Hash] metadata Hash with feature metadata @@ -285,10 +266,10 @@ module OpenTox # @param [Hash] metadata Hash containing the metadata for the new dataset # @param [String] subjectid # @return [OpenTox::Dataset] newly created dataset, already saved - def split( compounds, features, metadata, subjectid=nil) + def split( compounds, features, metadata) LOGGER.debug "split dataset using "+compounds.size.to_s+"/"+@compounds.size.to_s+" compounds" raise "no new compounds selected" unless compounds and compounds.size>0 - dataset = OpenTox::Dataset.create(CONFIG[:services]["opentox-dataset"],subjectid) + dataset = OpenTox::Dataset.create(CONFIG[:services]["opentox-dataset"],@subjectid) if features.size==0 compounds.each{ |c| dataset.add_compound(c) } else @@ -311,7 +292,7 @@ module OpenTox end end dataset.add_metadata(metadata) - dataset.save(subjectid) + dataset.save dataset end @@ -319,29 +300,23 @@ module OpenTox # - creates a new dataset if uri is not set # - overwrites dataset if uri exists # @return [String] Dataset URI - def save(subjectid=nil) - # TODO: rewrite feature URI's ?? + def save @compounds.uniq! - if @uri - if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) - RestClientWrapper.post(@uri,self.to_yaml,{:content_type => "application/x-yaml", :subjectid => subjectid}) - else - File.open("ot-post-file.rdf","w+") { |f| f.write(self.to_rdfxml); @path = f.path } - task_uri = RestClient.post(@uri, {:file => File.new(@path)},{:accept => "text/uri-list" , :subjectid => subjectid}).to_s.chomp - #task_uri = `curl -X POST -H "Accept:text/uri-list" -F "file=@#{@path};type=application/rdf+xml" http://apps.ideaconsult.net:8080/ambit2/dataset` - Task.find(task_uri).wait_for_completion - self.uri = RestClientWrapper.get(task_uri,{:accept => 'text/uri-list', :subjectid => subjectid}) - end + # create dataset if uri is empty + self.uri = RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:subjectid => @subjectid}).to_s.chomp unless @uri + if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + RestClientWrapper.post(@uri,self.to_yaml,{:content_type => "application/x-yaml", :subjectid => @subjectid}) else - # create dataset if uri is empty - self.uri = RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:subjectid => subjectid}).to_s.chomp + s = Serializer::Owl.new + s.add_dataset(self) + RestClientWrapper.post(@uri, s.to_rdfxml,{:content_type => "application/rdf+xml" , :subjectid => @subjectid}) end @uri end # Delete dataset at the dataset service - def delete(subjectid=nil) - RestClientWrapper.delete(@uri, :subjectid => subjectid) + def delete + RestClientWrapper.delete(@uri, :subjectid => @subjectid) end private @@ -367,7 +342,7 @@ module OpenTox # @return [OpenTox::Dataset] Prediction dataset object with all data def self.find(uri, subjectid=nil) prediction = LazarPrediction.new(uri, subjectid) - prediction.load_all(subjectid) + prediction.load_all prediction end @@ -392,10 +367,5 @@ module OpenTox @data_entries[compound.uri].collect{|f,v| @features[f] if f.match(/neighbor/)}.compact end -# def errors(compound) -# features = @data_entries[compound.uri].keys -# features.collect{|f| @features[f][OT.error]}.join(" ") if features -# end - end end diff --git a/lib/environment.rb b/lib/environment.rb index 28a9a66..cae743c 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -24,7 +24,7 @@ end # database #`redis-server /opt/redis/redis.conf` unless File.exists? "/var/run/redis.pid" # removed by AM -Ohm.connect :thread_safe => true +# Ohm.connect :thread_safe => true # load mail settings for error messages #load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.rb") @@ -69,11 +69,6 @@ class OwlNamespace end -AA_SERVER = CONFIG[:authorization] ? (CONFIG[:authorization][:server] ? CONFIG[:authorization][:server] : nil) : nil -CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorization][:authenticate_request] -CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] -CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] - RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' OWL = OwlNamespace.new 'http://www.w3.org/2002/07/owl#' DC = OwlNamespace.new 'http://purl.org/dc/elements/1.1/' @@ -81,3 +76,8 @@ OT = OwlNamespace.new 'http://www.opentox.org/api/1.1#' OTA = OwlNamespace.new 'http://www.opentox.org/algorithmTypes.owl#' XSD = OwlNamespace.new 'http://www.w3.org/2001/XMLSchema#' +AA_SERVER = CONFIG[:authorization] ? (CONFIG[:authorization][:server] ? CONFIG[:authorization][:server] : nil) : nil +CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorization][:authenticate_request] +CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] +CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] + diff --git a/lib/error.rb b/lib/error.rb index b92f2a4..45b7545 100644 --- a/lib/error.rb +++ b/lib/error.rb @@ -1,4 +1,3 @@ - # adding additional fields to Exception class to format errors according to OT-API class Exception attr_accessor :errorCause diff --git a/lib/feature.rb b/lib/feature.rb index f3bec5c..84a85b9 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -6,12 +6,12 @@ module OpenTox # Find a feature # @param [String] uri Feature URI - # @return [OpenTox::Task] Feature object + # @return [OpenTox::Feature] Feature object def self.find(uri, subjectid=nil) return nil unless uri - feature = Feature.new uri + feature = Feature.new uri, subjectid if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) - feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => subjectid})) + feature.add_metadata YAML.load(RestClientWrapper.get(uri,{:accept => "application/x-yaml", :subjectid => @subjectid})) else feature.add_metadata Parser::Owl::Dataset.new(uri).load_metadata end diff --git a/lib/helper.rb b/lib/helper.rb index 995f3e9..04300e0 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -1,3 +1,4 @@ +=begin helpers do # Authentification @@ -94,4 +95,4 @@ before do protected!(@subjectid) end end - +=end diff --git a/lib/model.rb b/lib/model.rb index 02fabfa..a806b74 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -4,6 +4,24 @@ module OpenTox include OpenTox + # Find a lazar model + # @param [String] uri Model URI + # @return [OpenTox::Model::Lazar] lazar model + def self.find(uri, subjectid=nil) + if CONFIG[:yaml_hosts].include?(URI.parse(uri).host) + YAML.load RestClientWrapper.get(uri,{:accept => 'application/x-yaml', :subjectid => subjectid}) + else + parser = Parser::Owl::Feature.new(uri, @subjectid) + @metadata = parser.load_uri.metadata + end + end + + # Get URIs of all models + # @return [Array] List of lazar model URIs + def self.all(subjectid=nil) + RestClientWrapper.get(CONFIG[:services]["opentox-model"], :subjectid => subjectid).to_s.split("\n") + end + # Run a model with parameters # @param [Hash] params Parameters for OpenTox model # @param [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly @@ -29,35 +47,35 @@ module OpenTox # @return [OpenTox::Model::Generic] Model instance def self.find(uri,subjectid=nil) return nil unless uri - model = Generic.new(uri) - model.load_metadata(subjectid) + model = Generic.new(uri,subjectid) + model.load_metadata raise "could not load model metadata '"+uri.to_s+"'" if model.metadata==nil or model.metadata.size==0 model end # provides feature type, possible types are "regression" or "classification" # @return [String] feature type, "unknown" if type could not be estimated - def feature_type(subjectid=nil) + def feature_type unless @feature_type - load_predicted_variables( subjectid ) unless @predicted_variable - @feature_type = OpenTox::Feature.find( @predicted_variable, subjectid ).feature_type + load_predicted_variables unless @predicted_variable + @feature_type = OpenTox::Feature.find( @predicted_variable, @subjectid ).feature_type end @feature_type end - def predicted_variable( subjectid ) - load_predicted_variables( subjectid ) unless @predicted_variable + def predicted_variable + load_predicted_variables unless @predicted_variable @predicted_variable end - def predicted_confidence( subjectid ) - load_predicted_variables( subjectid ) unless @predicted_confidence + def predicted_confidence + load_predicted_variables unless @predicted_confidence @predicted_confidence end private - def load_predicted_variables( subjectid=nil ) - load_metadata(subjectid) if @metadata==nil or @metadata.size==0 or (@metadata.size==1 && @metadata.values[0]==@uri) + def load_predicted_variables + load_metadata if @metadata==nil or @metadata.size==0 or (@metadata.size==1 && @metadata.values[0]==@uri) if @metadata[OT.predictedVariables] predictedVariables = @metadata[OT.predictedVariables] if predictedVariables.is_a?(Array) @@ -86,14 +104,14 @@ module OpenTox end # Lazy Structure Activity Relationship class - class Lazar + class Lazar < Generic - include Model + #include Model include Algorithm attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :min_sim, :subjectid, :prop_kernel, :value_map - def initialize(uri=nil) + def initialize(uri=nil,subjectid=nil) if uri super uri @@ -119,17 +137,15 @@ module OpenTox end - # Get URIs of all lazar models - # @return [Array] List of lazar model URIs - def self.all(subjectid=nil) - RestClientWrapper.get(CONFIG[:services]["opentox-model"], :subjectid => subjectid).to_s.split("\n") - end - - # Find a lazar model + # Find a lazar model via URI, and loads metadata, could raise NotFound/NotAuthorized error # @param [String] uri Model URI - # @return [OpenTox::Model::Lazar] lazar model - def self.find(uri, subjectid=nil) - YAML.load RestClientWrapper.get(uri,{:accept => 'application/x-yaml', :subjectid => subjectid}) + # @return [OpenTox::Model::Generic] Model instance + def self.find(uri,subjectid=nil) + return nil unless uri + model = Lazar.new(uri,subjectid) + model.load_metadata + raise "could not load model metadata '"+uri.to_s+"'" if model.metadata==nil or model.metadata.size==0 + model end # Create a new lazar model @@ -142,6 +158,7 @@ module OpenTox OpenTox::Model::Lazar.find(model_uri, subjectid) end +=begin # Get a parameter value # @param [String] param Parameter name # @return [String] Parameter value @@ -465,6 +482,7 @@ module OpenTox RestClientWrapper.delete(@uri, :subjectid => subjectid) unless @uri == CONFIG[:services]["opentox-model"] end +=end end end end diff --git a/lib/opentox-ruby.rb b/lib/opentox-ruby.rb index ae05cb2..16abee9 100644 --- a/lib/opentox-ruby.rb +++ b/lib/opentox-ruby.rb @@ -1,14 +1,15 @@ -['rubygems', 'sinatra', 'sinatra/url_for', 'ohm', 'rest_client', 'yaml', 'cgi', 'spork', 'error', 'overwrite', 'environment'].each do |lib| +#['rubygems', 'sinatra', 'sinatra/url_for', 'ohm', 'rest_client', 'yaml', 'cgi', 'spork', 'error', 'overwrite', 'environment'].each do |lib| +['rubygems', 'rest_client', 'yaml', 'cgi', 'spork', 'error', 'overwrite', 'environment'].each do |lib| require lib end -begin - require 'openbabel' -rescue LoadError - puts "Please install Openbabel with 'rake openbabel:install' in the compound component" -end +#begin + #require 'openbabel' +#rescue LoadError + #puts "Please install Openbabel with 'rake openbabel:install' in the compound component" +#end -['opentox', 'compound','dataset', 'parser','serializer', 'algorithm','model','task','validation','feature', - 'rest_client_wrapper', 'authorization', 'policy', 'helper', 'to-html', 'ontology' ].each do |lib| +#['opentox', 'compound','dataset', 'parser','serializer', 'algorithm','model','task','validation','feature', 'rest_client_wrapper', 'authorization', 'policy', 'helper', 'to-html', 'ontology' ].each do |lib| +['opentox', 'compound','dataset', 'parser','serializer', 'algorithm','model','task','validation','feature', 'rest_client_wrapper', 'authorization', 'policy', 'ontology' ].each do |lib| require lib end diff --git a/lib/opentox.rb b/lib/opentox.rb index c76e21a..6250d86 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -5,8 +5,9 @@ module OpenTox # Initialize OpenTox object with optional uri # @param [optional, String] URI - def initialize(uri=nil) + def initialize(uri=nil,subjectid=nil) @metadata = {} + @subjectid = subjectid self.uri = uri if uri end @@ -25,11 +26,15 @@ module OpenTox # Load (and return) metadata from object URI # @return [Hash] Metadata - def load_metadata(subjectid=nil) - @metadata = Parser::Owl::Generic.new(@uri).load_metadata(subjectid) + def load_metadata + @metadata = Parser::Owl::Generic.new(@uri).load_metadata @metadata end + # Add/modify metadata, existing entries will be overwritten + # @example + # dataset.add_metadata({DC.title => "any_title", DC.creator => "my_email"}) + # @param [Hash] metadata Hash mapping predicate_uris to values def add_metadata(metadata) metadata.each do |k,v| if v.is_a? Array @@ -46,13 +51,12 @@ module OpenTox def to_rdfxml s = Serializer::Owl.new s.add_metadata(@uri,@metadata) - #s.add_parameters(@uri,@parameters) if @parameters s.to_rdfxml end # deletes the resource, deletion should have worked when no RestCallError raised - def delete(subjectid=nil) - RestClientWrapper.delete(uri,:subjectid => subjectid) + def delete + RestClientWrapper.delete(uri,:subjectid => @subjectid) end end diff --git a/lib/overwrite.rb b/lib/overwrite.rb index df4e1b7..efc570d 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -1,3 +1,4 @@ +=begin # class overwrites aka monkey patches # hack: store sinatra instance in global var $url_provider to make url_for and halt methods accessible before { @@ -61,6 +62,7 @@ class Sinatra::Base end end end +=end class String def task_uri? @@ -143,8 +145,10 @@ class OTLogger < Logger end # make migration from datamapper more straightforward +=begin class Ohm::Model def self.get(id) self[id] end end +=end diff --git a/lib/to-html.rb b/lib/to-html.rb index 2c29f7d..04fa158 100644 --- a/lib/to-html.rb +++ b/lib/to-html.rb @@ -1,4 +1,3 @@ - OT_LOGO = File.join(CONFIG[:services]["opentox-validation"],"resources/ot-logo.png") class String -- cgit v1.2.3