From 68ff57c18f9f2f737ecdd8e5c60f42aa2f925416 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Sat, 13 Aug 2011 08:39:22 +0200 Subject: Fixed variance to population --- lib/algorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 3cf4ecf..90049dc 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -923,7 +923,7 @@ module OpenTox # @param [Array] Array to test, must indicate non-occurrence with 0. # @return [Boolean] Whether the feature has variance zero. def self.zero_variance?(array) - return (array.to_scale.variance_sample == 0.0) + return (array.to_scale.variance_population == 0.0) end # Sum of an array for Arrays. -- cgit v1.2.3 From ed3a1a1d85fd6b3d1e00f3193cdbfe9bfbe8866c Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Sat, 13 Aug 2011 08:44:17 +0200 Subject: Checking for metadata nil --- lib/serializer.rb | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/serializer.rb b/lib/serializer.rb index 03dcf1f..7fe4a3e 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -268,28 +268,30 @@ module OpenTox # @param [Hash] metadata def add_metadata(uri,metadata) id = 0 - metadata.each do |u,v| - #if v.is_a? Array and (u == OT.parameters or u == RDF.type) - if v.is_a? Array and u == OT.parameters#or u == RDF.type) - @object[uri][u] = [] unless @object[uri][u] - v.each do |value| - id+=1 - genid = "_:genid#{id}" - @object[uri][u] << {"type" => "bnode", "value" => genid} - @object[genid] = { RDF["type"] => [{ "type" => "uri", "value" => OT.Parameter}] } - value.each do |name,entry| - @object[genid][name] = [{"type" => type(entry), "value" => entry }] - end - end - elsif v.is_a? Array #and u == RDF.type - @object[uri] = {} unless @object[uri] - v.each do |value| + if !metadata.nil? + metadata.each do |u,v| + #if v.is_a? Array and (u == OT.parameters or u == RDF.type) + if v.is_a? Array and u == OT.parameters#or u == RDF.type) @object[uri][u] = [] unless @object[uri][u] - @object[uri][u] << {"type" => type(value), "value" => value } + v.each do |value| + id+=1 + genid = "_:genid#{id}" + @object[uri][u] << {"type" => "bnode", "value" => genid} + @object[genid] = { RDF["type"] => [{ "type" => "uri", "value" => OT.Parameter}] } + value.each do |name,entry| + @object[genid][name] = [{"type" => type(entry), "value" => entry }] + end + end + elsif v.is_a? Array #and u == RDF.type + @object[uri] = {} unless @object[uri] + v.each do |value| + @object[uri][u] = [] unless @object[uri][u] + @object[uri][u] << {"type" => type(value), "value" => value } + end + elsif v.is_a? String + @object[uri] = {} unless @object[uri] + @object[uri][u] = [{"type" => type(v), "value" => v }] end - elsif v.is_a? String - @object[uri] = {} unless @object[uri] - @object[uri][u] = [{"type" => type(v), "value" => v }] end end end -- cgit v1.2.3 From ec7faee0180f61e2d1254a67cb9bff7eb95db78d Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Sat, 13 Aug 2011 08:45:46 +0200 Subject: Checking for metadata nil --- lib/opentox.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/opentox.rb b/lib/opentox.rb index c76e21a..3ad6f6a 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -31,12 +31,14 @@ module OpenTox end def add_metadata(metadata) - metadata.each do |k,v| - if v.is_a? Array - @metadata[k] = [] unless @metadata[k] - @metadata[k] << v - else - @metadata[k] = v + if !metadata.nil? + metadata.each do |k,v| + if v.is_a? Array + @metadata[k] = [] unless @metadata[k] + @metadata[k] << v + else + @metadata[k] = v + end end end end -- cgit v1.2.3 From 5eab9794b1f0df0921b51f1aa4009e24f3db21a4 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 16 Aug 2011 12:12:51 +0000 Subject: old installation scripts removed --- bin/opentox-install-debian.sh | 105 ------------ bin/opentox-install-ubuntu.sh | 375 ------------------------------------------ 2 files changed, 480 deletions(-) delete mode 100644 bin/opentox-install-debian.sh delete mode 100755 bin/opentox-install-ubuntu.sh 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 -- cgit v1.2.3 From 46d1fa0469d6b6f9c7ec184fcef0c41cbd3b8a9b Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 17 Aug 2011 12:42:51 +0200 Subject: A&A add missing subjectids --- lib/authorization.rb | 2 +- lib/dataset.rb | 4 ++-- lib/helper.rb | 2 +- lib/model.rb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/authorization.rb b/lib/authorization.rb index 288733a..8023f60 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -216,7 +216,7 @@ module OpenTox LOGGER.debug "OpenTox::Authorization.delete_policy policy: #{policy} with token: #{subjectid}" return true if resource.delete(:subjectid => subjectid, :id => policy) rescue - return nil + return false end end diff --git a/lib/dataset.rb b/lib/dataset.rb index 5ebad0f..4102e18 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -84,12 +84,12 @@ module OpenTox copy YAML.load(yaml) end - def load_rdfxml(rdfxml) + def load_rdfxml(rdfxml, subjectid=nil) 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 + load_rdfxml_file file, subjectid file.delete end diff --git a/lib/helper.rb b/lib/helper.rb index 33774b4..d255b08 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -30,9 +30,9 @@ helpers do def clean_uri(uri) uri = uri.sub(" ", "%20") #dirty hacks => to fix uri = uri[0,uri.index("InChI=")] if uri.index("InChI=") - out = URI.parse(uri) out.path = out.path[0, out.path.length - (out.path.reverse.rindex(/\/{1}\d+\/{1}/))] if out.path.index(/\/{1}\d+\/{1}/) #cuts after /id/ for a&a + out.path = out.path.split('.').first #cut extension port = (out.scheme=="http" && out.port==80)||(out.scheme=="https" && out.port==443) ? "" : ":#{out.port.to_s}" "#{out.scheme}://#{out.host}#{port}#{out.path.chomp("/")}" #" end diff --git a/lib/model.rb b/lib/model.rb index 8a07858..8548e47 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -199,7 +199,7 @@ module OpenTox count += 1 waiting_task.progress( count/d.compounds.size.to_f*100.0 ) if waiting_task rescue => ex - LOGGER.warn "prediction for compound "+compound_uri.to_s+" failed: "+ex.message + LOGGER.warn "prediction for compound "+compound_uri.to_s+" failed: "+ex.message+" subjectid: #{subjectid}" end end #@prediction_dataset.save(subjectid) @@ -225,7 +225,7 @@ module OpenTox } ) end - if OpenTox::Feature.find(metadata[OT.dependentVariables]).feature_type == "regression" + if OpenTox::Feature.find(metadata[OT.dependentVariables], subjectid).feature_type == "regression" all_activities = [] all_activities = @activities.values.flatten.collect! { |i| i.to_f } @prediction_min_max[0] = (all_activities.to_scale.min/2) -- cgit v1.2.3 From 89b583fbc8e2493bcfd912bed72b8a80d4d2474d Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 22 Aug 2011 11:23:49 +0200 Subject: unify cookies --- lib/environment.rb | 5 +++++ lib/helper.rb | 31 ++++++++++++++++++++++++++++++- lib/to-html.rb | 5 ++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/environment.rb b/lib/environment.rb index 6d1bb85..ccd5c9e 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -74,6 +74,11 @@ CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorizatio CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] +cookie_secret = CONFIG[:authorization] ? CONFIG[:authorization][:cookie_secret] : nil +cookie_secret = cookie_secret ? cookie_secret : "ui6vaiNi-change_me" +use Rack::Session::Cookie, :expire_after => 28800, + :secret => cookie_secret + 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/' diff --git a/lib/helper.rb b/lib/helper.rb index 33774b4..da77945 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -1,4 +1,34 @@ helpers do + + def login(username, password) + logout + session[:subjectid] = OpenTox::Authorization.authenticate(username, password) + #LOGGER.debug "ToxCreate login user #{username} with subjectid: " + session[:subjectid].to_s + if session[:subjectid] != nil + session[:username] = username + return session[:subjectid] + else + session[:username] = "" + return nil + end + end + + def logout + if session[:subjectid] != nil + session[:subjectid] = nil + session[:username] = "" + return true + end + return false + end + + def logged_in() + return true if !AA_SERVER + if session[:subjectid] != nil + return OpenTox::Authorization.is_token_valid(session[:subjectid]) + end + return false + end # Authentification def protected!(subjectid) @@ -56,7 +86,6 @@ helpers do subjectid = session[:subjectid] if session[:subjectid] subjectid = params[:subjectid] if params[:subjectid] and !subjectid subjectid = request.env['HTTP_SUBJECTID'] if request.env['HTTP_SUBJECTID'] and !subjectid - subjectid = request.cookies["subjectid"] unless subjectid # see http://rack.rubyforge.org/doc/SPEC.html subjectid = CGI.unescape(subjectid) if subjectid.include?("%23") @subjectid = subjectid diff --git a/lib/to-html.rb b/lib/to-html.rb index 2979062..519688f 100644 --- a/lib/to-html.rb +++ b/lib/to-html.rb @@ -111,7 +111,7 @@ module OpenTox end get '/sign_out/?' do - response.set_cookie("subjectid",{:value=>nil}) + logout content_type "text/html" content = "Sucessfully signed out from "+$url_provider.url_for("",:full) OpenTox.text_to_html(content) @@ -123,9 +123,8 @@ get '/sign_in/?' do end post '/sign_in/?' do - subjectid = OpenTox::Authorization.authenticate(params[:user], params[:password]) + subjectid = login(params[:user], params[:password]) if (subjectid) - response.set_cookie("subjectid",{:value=>subjectid}) content_type "text/html" content = "Sucessfully signed in as '"+params[:user]+"' to "+$url_provider.url_for("",:full) OpenTox.text_to_html(content,subjectid) -- cgit v1.2.3 From 7789591f370c290c265fce0d2103652b6c55687b Mon Sep 17 00:00:00 2001 From: opentox Date: Mon, 22 Aug 2011 09:34:56 +0000 Subject: carcinogen/non-carcinogen added to TRUE|FALSE Regexp --- lib/environment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/environment.rb b/lib/environment.rb index 6d1bb85..8745c54 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -40,8 +40,8 @@ else end # Regular expressions for parsing classification data -TRUE_REGEXP = /^(true|active|1|1.0|tox|activating)$/i -FALSE_REGEXP = /^(false|inactive|0|0.0|low tox|deactivating)$/i +TRUE_REGEXP = /^(true|active|1|1.0|tox|activating|carcinogen)$/i +FALSE_REGEXP = /^(false|inactive|0|0.0|low tox|deactivating|non-carcinogen)$/i # Task durations DEFAULT_TASK_MAX_DURATION = 36000 -- cgit v1.2.3 From 1e6bf954fb9cbc8a8aad9af3d6f653f79e0f401a Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 22 Aug 2011 12:12:52 +0200 Subject: adjust sign in/out messages --- lib/to-html.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/to-html.rb b/lib/to-html.rb index 519688f..678ef29 100644 --- a/lib/to-html.rb +++ b/lib/to-html.rb @@ -33,10 +33,10 @@ module OpenTox user = OpenTox::Authorization.get_user(subjectid) if subjectid html += "

" unless user - html += "You are currently not signed in to "+$url_provider.url_for("",:full)+ + html += "You are currently not signed in to "+$url_provider.request.host.to_s+ ", sign in" else - html += "You are signed in as '#{user}' to "+$url_provider.url_for("",:full)+ + html += "You are signed in as '#{user}' to "+$url_provider.request.host.to_s+ ", sign out" end html += "

" @@ -61,7 +61,7 @@ module OpenTox html += "
" html += "

" html += msg+"\n\n" if msg - html += "Please sign in to "+$url_provider.url_for("",:full)+"\n\n" + html += "Please sign in to "+$url_provider.request.host.to_s+"\n\n" html += "" html += ""+ ""+ @@ -113,7 +113,8 @@ end get '/sign_out/?' do logout content_type "text/html" - content = "Sucessfully signed out from "+$url_provider.url_for("",:full) + content = "Sucessfully signed out from "+$url_provider.request.host.to_s+" ( Back to "+ + $url_provider.url_for("",:full)+" )" OpenTox.text_to_html(content) end @@ -126,7 +127,8 @@ post '/sign_in/?' do subjectid = login(params[:user], params[:password]) if (subjectid) content_type "text/html" - content = "Sucessfully signed in as '"+params[:user]+"' to "+$url_provider.url_for("",:full) + content = "Sucessfully signed in as '"+params[:user]+"' to "+$url_provider.request.host.to_s+" ( Back to "+ + $url_provider.url_for("",:full)+" )" OpenTox.text_to_html(content,subjectid) else content_type "text/html" -- cgit v1.2.3 From cb2170529708deb0f711383040aa0ff174d35a36 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 22 Aug 2011 16:23:56 +0000 Subject: rdfxml of prediction features fixed --- lib/feature.rb | 11 +++++++++++ lib/model.rb | 4 ++-- lib/opentox.rb | 1 - lib/serializer.rb | 8 +++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/feature.rb b/lib/feature.rb index 4ba58ce..0099d41 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -42,4 +42,15 @@ module OpenTox end end end + + # Get OWL-DL representation in RDF/XML format + # @return [application/rdf+xml] RDF/XML representation + def to_rdfxml + s = Serializer::Owl.new + s.add_feature(@uri,@metadata) + @metadata.values.grep(/model\/\d+$/).each{ |m| s.add_uri(m,OT.Model)} + @metadata.values.grep(/feature/).each{ |f| s.add_uri(f,OT.Feature)} + #s.add_parameters(@uri,@parameters) if @parameters + s.to_rdfxml + end end diff --git a/lib/model.rb b/lib/model.rb index 8548e47..e9e0b09 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -385,7 +385,7 @@ module OpenTox dependent_uri = @metadata[OT.dependentVariables].first feature = OpenTox::Feature.new File.join( @uri, "predicted", "value") feature.add_metadata( { - RDF.type => [OT.ModelPrediction], + RDF.type => OT.ModelPrediction, OT.hasSource => @uri, DC.creator => @uri, DC.title => URI.decode(File.basename( dependent_uri )), @@ -398,7 +398,7 @@ module OpenTox dependent_uri = @metadata[OT.dependentVariables].first feature = OpenTox::Feature.new File.join( @uri, "predicted", "confidence") feature.add_metadata( { - RDF.type => [OT.ModelPrediction], + RDF.type => OT.ModelPrediction, OT.hasSource => @uri, DC.creator => @uri, DC.title => "#{URI.decode(File.basename( dependent_uri ))} confidence" diff --git a/lib/opentox.rb b/lib/opentox.rb index 3ad6f6a..14704ec 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -48,7 +48,6 @@ 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 diff --git a/lib/serializer.rb b/lib/serializer.rb index 9fc034d..87de036 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -21,6 +21,7 @@ module OpenTox OT.NominalFeature => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.NumericFeature => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.StringFeature => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , + OT.ModelPrediction => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.Dataset => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.DataEntry => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , OT.FeatureValue => { RDF["type"] => [{ "type" => "uri", "value" => OWL['Class'] }] } , @@ -69,6 +70,7 @@ module OpenTox OT.validation => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.crossvalidationInfo => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , OT.dataset => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , + OT.hasSource => { RDF["type"] => [{ "type" => "uri", "value" => OWL.ObjectProperty }] } , DC.title => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , DC.identifier => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , @@ -131,7 +133,7 @@ module OpenTox OT.actor => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , OT.errorCode => { RDF["type"] => [{ "type" => "uri", "value" => OWL.AnnotationProperty }] } , - OT.hasSource => { RDF["type"] => [{ "type" => "uri", "value" => OWL.DatatypeProperty }] } , + #OT.hasSource => { RDF["type"] => [{ "type" => "uri", "value" => OWL.DatatypeProperty }] } , OT.value => { RDF["type"] => [{ "type" => "uri", "value" => OWL.DatatypeProperty }] } , OT.paramScope => { RDF["type"] => [{ "type" => "uri", "value" => OWL.DatatypeProperty }] } , #OT.paramValue => { RDF["type"] => [{ "type" => "uri", "value" => OWL.DatatypeProperty }] } , @@ -216,6 +218,10 @@ module OpenTox @@content_id = 1 add_content uri, content end + + def add_uri(uri,type) + @object[uri] = { RDF["type"] => [{ "type" => "uri", "value" => type }] } + end private @@content_id = 1 -- cgit v1.2.3 From 067cf2332b85b29ed8054ab249322f8ae2345c2b Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 23 Aug 2011 12:46:33 +0200 Subject: optimize helper --- lib/helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/helper.rb b/lib/helper.rb index 76226e5..ce13ff1 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -90,10 +90,12 @@ helpers do subjectid = CGI.unescape(subjectid) if subjectid.include?("%23") @subjectid = subjectid rescue - subjectid = nil + @subjectid = nil end end def get_extension + @accept = request.env['HTTP_ACCEPT'] + @accept = 'application/rdf+xml' if @accept == '*/*' or @accept == '' or @accept.nil? extension = File.extname(request.path_info) unless extension.empty? case extension.gsub(".","") @@ -107,6 +109,8 @@ helpers do @accept = 'application/rdf+xml' when "xls" @accept = 'application/ms-excel' + when "sdf" + @accept = 'chemical/x-mdl-sdfile' when "css" @accept = 'text/css' else @@ -117,8 +121,8 @@ helpers do end before do - @subjectid = get_subjectid() - @accept = get_extension() + get_subjectid() + get_extension() unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD']) protected!(@subjectid) end -- cgit v1.2.3 From 64ab23142ffb068c8b901c73ec227ca484d9efb6 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 24 Aug 2011 11:20:32 +0200 Subject: quickfix to flatten error --- lib/feature.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/feature.rb b/lib/feature.rb index 0099d41..6d14444 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -23,9 +23,9 @@ module OpenTox # @return [String] feature type, unknown if OT.isA property is unknown/ not set def feature_type raise OpenTox::BadRequestError.new("rdf type of feature '"+uri.to_s+"' not set") unless metadata[RDF.type] - if metadata[RDF.type].flatten.include?(OT.NominalFeature) + if metadata[RDF.type].to_a.flatten.include?(OT.NominalFeature) "classification" - elsif metadata[RDF.type].flatten.include?(OT.NumericFeature) + elsif metadata[RDF.type].to_a.flatten.include?(OT.NumericFeature) "regression" elsif metadata[OWL.sameAs] metadata[OWL.sameAs].each do |f| -- cgit v1.2.3 From 5550566e7c72afd6d70d2d2180b780ffa876a691 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 24 Aug 2011 16:07:15 +0000 Subject: datasets stored as json (with Yajl) to improve performance --- lib/dataset.rb | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index 4102e18..8061153 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -46,6 +46,12 @@ module OpenTox dataset.save(subjectid) dataset end + + def self.from_json(json, subjectid=nil) + dataset = Dataset.new(nil,subjectid) + dataset.copy_hash Yajl::Parser.parse(json) + 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 @@ -84,6 +90,10 @@ module OpenTox copy YAML.load(yaml) end + def load_json(json) + copy_hash Yajl::Parser.parse(json) + end + def load_rdfxml(rdfxml, subjectid=nil) raise "rdfxml data is empty" if rdfxml.to_s.size==0 file = Tempfile.new("ot-rdfxml") @@ -146,7 +156,7 @@ module OpenTox # Load all data (metadata, data_entries, compounds and features) from URI def load_all(subjectid=nil) if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) - copy YAML.load(RestClientWrapper.get(@uri, {:accept => "application/x-yaml", :subjectid => subjectid})) + copy_hash Yajl::Parser.parse(RestClientWrapper.get(@uri, {:accept => "application/json", :subjectid => subjectid})) else parser = Parser::Owl::Dataset.new(@uri, subjectid) copy parser.load_uri(subjectid) @@ -170,7 +180,7 @@ module OpenTox # @return [Hash] Features of the dataset def load_features(subjectid=nil) 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 = Yajl::Parser.parse(RestClientWrapper.get(File.join(@uri,"features"), {:accept => "application/json", :subjectid => subjectid})) else parser = Parser::Owl::Dataset.new(@uri, subjectid) @features = parser.load_features(subjectid) @@ -203,6 +213,10 @@ module OpenTox =begin =end + def to_json + Yajl::Encoder.encode({:uri => @uri, :metadata => @metadata, :data_entries => @data_entries, :compounds => @compounds, :features => @features}) + 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 @@ -359,11 +373,11 @@ module OpenTox @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}) + #LOGGER.debug self.to_json + RestClientWrapper.post(@uri,self.to_json,{:content_type => "application/json", :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 @@ -379,6 +393,19 @@ module OpenTox RestClientWrapper.delete(@uri, :subjectid => subjectid) end + # Copy a hash (eg. from JSON) into a dataset (rewrites URI) + def copy_hash(hash) + @metadata = hash["metadata"] + @data_entries = hash["data_entries"] + @compounds = hash["compounds"] + @features = hash["features"] + if @uri + self.uri = @uri + else + @uri = hash["metadata"][XSD.anyURI] + end + end + private # Copy a dataset (rewrites URI) def copy(dataset) -- cgit v1.2.3 From b4e4ac6a6eee4d05144de7447091e27f624325d4 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 25 Aug 2011 10:41:37 +0000 Subject: json store for models --- lib/model.rb | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/model.rb b/lib/model.rb index e9e0b09..42e5b92 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -11,7 +11,7 @@ module OpenTox def run( params, accept_header=nil, waiting_task=nil ) unless accept_header if CONFIG[:yaml_hosts].include?(URI.parse(@uri).host) - accept_header = 'application/x-yaml' + accept_header = 'application/json' else accept_header = 'application/rdf+xml' end @@ -144,7 +144,7 @@ module OpenTox # @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}) + OpenTox::Model::Lazar.from_json RestClientWrapper.get(uri,{:accept => 'application/json', :subjectid => subjectid}) end # Create a new lazar model @@ -157,10 +157,42 @@ module OpenTox OpenTox::Model::Lazar.find(model_uri, subjectid) end + def self.from_json(json) + hash = Yajl::Parser.parse(json) + #LOGGER.debug hash.to_yaml + lazar = OpenTox::Model::Lazar.new + #hash.each { |k,v| eval("lazar.#{k} = #{v}") } + lazar.uri = hash["uri"] if hash["uri"] + lazar.metadata = hash["metadata"] if hash["metadata"] + lazar.compound = hash["compound"] if hash["compound"] + lazar.prediction_dataset = hash["prediction_dataset"] if hash["prediction_dataset"] + lazar.features = hash["features"] if hash["features"] + lazar.effects = hash["effects"] if hash["effects"] + lazar.activities = hash["activities"] if hash["activities"] + lazar.p_values = hash["p_values"] if hash["p_values"] + lazar.fingerprints = hash["fingerprints"] if hash["fingerprints"] + lazar.feature_calculation_algorithm = hash["feature_calculation_algorithm"] if hash["feature_calculation_algorithm"] + lazar.similarity_algorithm = hash["similarity_algorithm"] if hash["similarity_algorithm"] + lazar.prediction_algorithm = hash["prediction_algorithm"] if hash["prediction_algorithm"] + lazar.min_sim = hash["min_sim"] if hash["min_sim"] + lazar.subjectid = hash["subjectid"] if hash["subjectid"] + lazar.prop_kernel = hash["prop_kernel"] if hash["prop_kernel"] + lazar.value_map = hash["value_map"] if hash["value_map"] + lazar.nr_hits = hash["nr_hits"] if hash["nr_hits"] + lazar.transform = hash["transform"] if hash["transform"] + lazar.conf_stdev = hash["conf_stdev"] if hash["conf_stdev"] + lazar.prediction_min_max = hash["prediction_min_max"] if hash["prediction_min_max"] + lazar + end + + def to_json + Yajl::Encoder.encode({:uri => @uri,:metadata => @metadata, :compound => @compound, :prediction_dataset => @prediction_dataset, :features => @features, :effects => @effects, :activities => @activities, :p_values => @p_values, :fingerprints => @fingerprints, :feature_calculation_algorithm => @feature_calculation_algorithm, :similarity_algorithm => @similarity_algorithm, :prediction_algorithm => @prediction_algorithm, :min_sim => @min_sim, :subjectid => @subjectid, :prop_kernel => @prop_kernel, :value_map => @value_map, :nr_hits => @nr_hits, :transform => @transform, :conf_stdev => @conf_stdev, :prediction_min_max => @prediction_min_max}) + end + def run( params, accept_header=nil, waiting_task=nil ) unless accept_header if CONFIG[:yaml_hosts].include?(URI.parse(@uri).host) - accept_header = 'application/x-yaml' + accept_header = 'application/json' else accept_header = 'application/rdf+xml' end @@ -215,6 +247,7 @@ module OpenTox @compound = Compound.new compound_uri features = {} + #LOGGER.debug self.to_yaml unless @prediction_dataset @prediction_dataset = Dataset.create(CONFIG[:services]["opentox-dataset"], subjectid) @prediction_dataset.add_metadata( { @@ -255,7 +288,7 @@ module OpenTox @prediction_dataset.metadata[OT.predictedVariables] = [value_feature_uri, confidence_feature_uri] unless @prediction_dataset.metadata[OT.predictedVariables] if OpenTox::Feature.find(metadata[OT.dependentVariables], subjectid).feature_type == "classification" - @prediction_dataset.add @compound.uri, value_feature_uri, @value_map[prediction[:prediction]] + @prediction_dataset.add @compound.uri, value_feature_uri, @value_map[prediction[:prediction].to_s] else @prediction_dataset.add @compound.uri, value_feature_uri, prediction[:prediction] end @@ -365,7 +398,7 @@ module OpenTox def database_activity(subjectid) if @activities[@compound.uri] if OpenTox::Feature.find(metadata[OT.dependentVariables], subjectid).feature_type == "classification" - @activities[@compound.uri].each { |act| @prediction_dataset.add @compound.uri, @metadata[OT.dependentVariables], @value_map[act] } + @activities[@compound.uri].each { |act| @prediction_dataset.add @compound.uri, @metadata[OT.dependentVariables], @value_map[act.to_s] } else @activities[@compound.uri].each { |act| @prediction_dataset.add @compound.uri, @metadata[OT.dependentVariables], act } end @@ -408,7 +441,7 @@ module OpenTox # Save model at model service def save(subjectid) - self.uri = RestClientWrapper.post(@uri,self.to_yaml,{:content_type => "application/x-yaml", :subjectid => subjectid}) + self.uri = RestClientWrapper.post(@uri,self.to_json,{:content_type => "application/json", :subjectid => subjectid}) end # Delete model at model service -- cgit v1.2.3 From d408d94cb03f8254ab6cdfb84f3f557d1ca5e536 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 26 Aug 2011 13:32:48 +0000 Subject: yaml_hosts changed to json_hosts --- lib/dataset.rb | 6 +++--- lib/feature.rb | 2 +- lib/model.rb | 4 ++-- lib/task.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/dataset.rb b/lib/dataset.rb index 8061153..0911073 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -155,7 +155,7 @@ module OpenTox # Load all data (metadata, data_entries, compounds and features) from URI def load_all(subjectid=nil) - if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + if (CONFIG[:json_hosts].include?(URI.parse(@uri).host)) copy_hash Yajl::Parser.parse(RestClientWrapper.get(@uri, {:accept => "application/json", :subjectid => subjectid})) else parser = Parser::Owl::Dataset.new(@uri, subjectid) @@ -179,7 +179,7 @@ module OpenTox # Load and return only features from the dataset service # @return [Hash] Features of the dataset def load_features(subjectid=nil) - if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + if (CONFIG[:json_hosts].include?(URI.parse(@uri).host)) @features = Yajl::Parser.parse(RestClientWrapper.get(File.join(@uri,"features"), {:accept => "application/json", :subjectid => subjectid})) else parser = Parser::Owl::Dataset.new(@uri, subjectid) @@ -372,7 +372,7 @@ module OpenTox # TODO: rewrite feature URI's ?? @compounds.uniq! if @uri - if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + if (CONFIG[:json_hosts].include?(URI.parse(@uri).host)) #LOGGER.debug self.to_json RestClientWrapper.post(@uri,self.to_json,{:content_type => "application/json", :subjectid => subjectid}) else diff --git a/lib/feature.rb b/lib/feature.rb index 6d14444..55ac678 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -10,7 +10,7 @@ module OpenTox def self.find(uri, subjectid=nil) return nil unless uri feature = Feature.new uri - if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) + if (CONFIG[:json_hosts].include?(URI.parse(uri).host)) 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 diff --git a/lib/model.rb b/lib/model.rb index 42e5b92..0b116c2 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -10,7 +10,7 @@ module OpenTox # @return [text/uri-list] Task or resource URI def run( params, accept_header=nil, waiting_task=nil ) unless accept_header - if CONFIG[:yaml_hosts].include?(URI.parse(@uri).host) + if CONFIG[:json_hosts].include?(URI.parse(@uri).host) accept_header = 'application/json' else accept_header = 'application/rdf+xml' @@ -191,7 +191,7 @@ module OpenTox def run( params, accept_header=nil, waiting_task=nil ) unless accept_header - if CONFIG[:yaml_hosts].include?(URI.parse(@uri).host) + if CONFIG[:json_hosts].include?(URI.parse(@uri).host) accept_header = 'application/json' else accept_header = 'application/rdf+xml' diff --git a/lib/task.rb b/lib/task.rb index dbcbe59..e6fa5e1 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -182,7 +182,7 @@ module OpenTox end def load_metadata - if (CONFIG[:yaml_hosts].include?(URI.parse(@uri).host)) + if (CONFIG[:json_hosts].include?(URI.parse(@uri).host)) result = RestClientWrapper.get(@uri, {:accept => 'application/x-yaml'}, nil, false) @metadata = YAML.load result.to_s @http_code = result.code @@ -209,7 +209,7 @@ module OpenTox def reload( accept_header=nil ) unless accept_header - if (CONFIG[:yaml_hosts].include?(URI.parse(uri).host)) + if (CONFIG[:json_hosts].include?(URI.parse(uri).host)) accept_header = "application/x-yaml" else accept_header = 'application/rdf+xml' -- cgit v1.2.3 From 811ced6dfe7178ee985043f8ef9e304140158f96 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 26 Aug 2011 15:16:50 +0000 Subject: (non-)mutagenic added to TRUE|FALSE REGEXP --- lib/environment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/environment.rb b/lib/environment.rb index 35500f7..09830b8 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -40,8 +40,8 @@ else end # Regular expressions for parsing classification data -TRUE_REGEXP = /^(true|active|1|1.0|tox|activating|carcinogen)$/i -FALSE_REGEXP = /^(false|inactive|0|0.0|low tox|deactivating|non-carcinogen)$/i +TRUE_REGEXP = /^(true|active|1|1.0|tox|activating|carcinogen|mutagenic)$/i +FALSE_REGEXP = /^(false|inactive|0|0.0|low tox|deactivating|non-carcinogen|non-mutagenic)$/i # Task durations DEFAULT_TASK_MAX_DURATION = 36000 -- cgit v1.2.3 From d0ea360e353aacff9eabfe97882726134aec19c1 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 14 Sep 2011 09:37:52 +0200 Subject: register model to ontology service|ECHA Endpoints from ontology service --- lib/environment.rb | 2 ++ lib/ontology.rb | 61 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/lib/environment.rb b/lib/environment.rb index 09830b8..3775797 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -74,6 +74,8 @@ CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorizatio CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] +ONTOLOGY_SERVER = CONFIG[:services]["opentox-ontology"] ? CONFIG[:services]["opentox-ontology"] : "http://apps.ideaconsult.net:8080/ontology" + cookie_secret = CONFIG[:authorization] ? CONFIG[:authorization][:cookie_secret] : nil cookie_secret = cookie_secret ? cookie_secret : "ui6vaiNi-change_me" use Rack::Session::Cookie, :expire_after => 28800, diff --git a/lib/ontology.rb b/lib/ontology.rb index fa4ea6f..ca957af 100644 --- a/lib/ontology.rb +++ b/lib/ontology.rb @@ -1,11 +1,9 @@ module OpenTox module Ontology module Echa -=begin - require 'sparql/client' - @sparql = SPARQL::Client.new("http://apps.ideaconsult.net:8080/ontology") - def self.qs(classname="Endpoints") - return "PREFIX ot: + + def self.querystring(classname="Endpoints") + return CGI.escape("PREFIX ot: PREFIX ota: PREFIX owl: PREFIX dc: @@ -17,29 +15,44 @@ module OpenTox where { ?endpoint rdfs:subClassOf otee:#{classname}. ?endpoint dc:title ?title. - }" + }") end def self.make_option_list(endpoint="Endpoints", level=1) - out = "" - results = @sparql.query(qs(endpoint)) rescue results = [] + out = "" + results = echa_endpoints(endpoint) rescue results = [] results.each do |result| - endpointname = result.Endpoints.to_s.split('#').last - title = result.bound?(:title) ? result.title : endpointname - out += "\n" + r = result.split(',') + endpointname = r.first.split("#").last + title = r[1..r.size-1] + out += "\n" out += make_option_list(endpointname, level + 1) end return out end - def self.get_endpoint_selectlist(include_blank=true) + def self.endpoint_option_list(include_blank=true) out = "\n" return out end -=end + + # Gets Endpoints of specific level from ontology service + # Top level with endpoint="Endpoints" + # e.G. Ecotoxic effects endpoints with endpoint="EcotoxicEffects" + # if ontology service is not reachable it returns an empty array + # @param [String] endpoint + # @return [Array] of endpoints: e.G. "http://www.opentox.org/echaEndpoints.owl#EcotoxicEffects,Ecotoxic effects" + def self.echa_endpoints(endpoint) + begin + RestClientWrapper.get("#{ONTOLOGY_SERVER}?query=#{querystring(endpoint)}",:accept => "text/csv").collect{|l| l.gsub("\r\n", "") if l.match(/^http/)}.uniq.compact.sort + rescue + LOGGER.warn "OpenTox::Ontology::Echa.echa_endpoints ontology service is not reachable." + [] + end + end def self.endpoints RestClientWrapper.get("http://apps.ideaconsult.net:8080/ambit2/query/ndatasets_endpoint",:accept => "text/csv").collect { |line| line.split(',').first if line.match(/^http/) }.compact @@ -51,5 +64,27 @@ module OpenTox end + # Register an OpenTox resource into ontology service + # @param [String] uri, URI of recource to register + # @param [String] subjectid + def self.register(uri, subjectid=nil) + begin + RestClientWrapper.post(ONTOLOGY_SERVER, {:uri => uri}, {:subjectid => CGI.escape(subjectid)}) + rescue + false + end + end + + # Unregister an OpenTox resource into ontology service + # @param [String] uri, URI of recource to unregister + # @param [String] subjectid + def self.unregister(uri, subjectid=nil) + begin + RestClientWrapper.delete("#{ONTOLOGY_SERVER}?uri=#{CGI.escape(uri)}", {:subjectid => CGI.escape(subjectid)}) + rescue + false + end + end + end end -- cgit v1.2.3 From bd726758d25e44b74b694fb15ac6f348bf350c76 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 14 Sep 2011 15:30:34 +0200 Subject: load json prettifing gem --- lib/serializer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/serializer.rb b/lib/serializer.rb index 87de036..3a19bf0 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -1,5 +1,6 @@ require 'spreadsheet' require 'yajl' +require 'yajl/json_gem' module OpenTox -- cgit v1.2.3 From 7727060f8642bd26f837392b2069d89365eadee8 Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 20 Sep 2011 13:36:41 +0200 Subject: fix syntax for yard documentation --- lib/serializer.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/serializer.rb b/lib/serializer.rb index 3a19bf0..b62ac45 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -227,16 +227,16 @@ module OpenTox private @@content_id = 1 - # Recursiv function to add content - # @example - # { DC.description => "bla", - # OT.similar_resources => [ "http://uri1", "http://uri2" ], - # OT.matrixCells => - # [ { RDF.type => OT.MatrixCell, OT.cellIndex=1 OT.cellValue => "xy" }, - # { RDF.type => OT.MatrixCell, OT.cellIndex=2 OT.cellValue => "z" } ], - # OT.info => { RDF.type => OT.ImportantInfo, - # DC.description => "blub" } - # } + #Recursiv function to add content + #@example + # { DC.description => "bla", + # OT.similar_resources => [ "http://uri1", "http://uri2" ], + # OT.matrixCells => + # [ { RDF.type => OT.MatrixCell, OT.cellIndex=1 OT.cellValue => "xy" }, + # { RDF.type => OT.MatrixCell, OT.cellIndex=2 OT.cellValue => "z" } ], + # OT.info => { RDF.type => OT.ImportantInfo, + # DC.description => "blub" } + # } # @param [String] uri # @param [Hash] content as hash, uri must already have been added to @object def add_content(uri, hash) -- cgit v1.2.3 From 4fc797d5b7869f9d386df2b823168ff76f1359e6 Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 20 Sep 2011 13:38:56 +0200 Subject: feature: model registration to ontology service --- lib/ontology.rb | 87 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/lib/ontology.rb b/lib/ontology.rb index ca957af..ad7ba7b 100644 --- a/lib/ontology.rb +++ b/lib/ontology.rb @@ -17,7 +17,7 @@ module OpenTox ?endpoint dc:title ?title. }") end - + def self.make_option_list(endpoint="Endpoints", level=1) out = "" results = echa_endpoints(endpoint) rescue results = [] @@ -30,7 +30,7 @@ module OpenTox end return out end - + def self.endpoint_option_list(include_blank=true) out = "
user:
password: