summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-09-23 12:27:16 +0200
committermr <mr@mrautenberg.de>2011-09-23 12:27:16 +0200
commitbe69826665ef75f00a0d96c73bb2f999b979052d (patch)
treecb7735dcfb2926e2e2697b06ab161dae0227b1d2
parente1b67ddbefe6e4f456346943ffb604d2b5ad44e3 (diff)
parent309a0bf24667de1ad0654118b3f7d4eeb66d2a0a (diff)
Merge branch 'release/v3.0.0'v3.0.0
-rw-r--r--VERSION2
-rw-r--r--bin/opentox-install-debian.sh105
-rwxr-xr-xbin/opentox-install-ubuntu.sh375
-rw-r--r--lib/algorithm.rb2
-rw-r--r--lib/authorization.rb2
-rw-r--r--lib/dataset.rb45
-rw-r--r--lib/environment.rb11
-rw-r--r--lib/feature.rb17
-rw-r--r--lib/helper.rb43
-rw-r--r--lib/model.rb57
-rw-r--r--lib/ontology.rb114
-rw-r--r--lib/opentox.rb15
-rw-r--r--lib/serializer.rb71
-rw-r--r--lib/task.rb4
-rw-r--r--lib/to-html.rb17
15 files changed, 302 insertions, 578 deletions
diff --git a/VERSION b/VERSION
index 50aea0e..56fea8a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.0 \ No newline at end of file
+3.0.0 \ No newline at end of file
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 85b54ab..cf88bab 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -927,7 +927,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.
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..0911073 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,12 +90,16 @@ module OpenTox
copy YAML.load(yaml)
end
- def load_rdfxml(rdfxml)
+ 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")
file.puts rdfxml
file.close
- load_rdfxml_file file
+ load_rdfxml_file file, subjectid
file.delete
end
@@ -145,8 +155,8 @@ 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}))
+ 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)
copy parser.load_uri(subjectid)
@@ -169,8 +179,8 @@ 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))
- @features = YAML.load(RestClientWrapper.get(File.join(@uri,"features"), {:accept => "application/x-yaml", :subjectid => subjectid}))
+ 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)
@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
@@ -358,12 +372,12 @@ module OpenTox
# TODO: rewrite feature URI's ??
@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})
+ 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
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)
diff --git a/lib/environment.rb b/lib/environment.rb
index 6d1bb85..3775797 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|mutagenic)$/i
+FALSE_REGEXP = /^(false|inactive|0|0.0|low tox|deactivating|non-carcinogen|non-mutagenic)$/i
# Task durations
DEFAULT_TASK_MAX_DURATION = 36000
@@ -74,6 +74,13 @@ 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,
+ :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/feature.rb b/lib/feature.rb
index 4ba58ce..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
@@ -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|
@@ -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/helper.rb b/lib/helper.rb
index 33774b4..ce13ff1 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)
@@ -30,9 +60,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
@@ -56,15 +86,16 @@ 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
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(".","")
@@ -78,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
@@ -88,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
diff --git a/lib/model.rb b/lib/model.rb
index 8a07858..0b116c2 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -10,8 +10,8 @@ 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)
- accept_header = 'application/x-yaml'
+ if CONFIG[:json_hosts].include?(URI.parse(@uri).host)
+ 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'
+ if CONFIG[:json_hosts].include?(URI.parse(@uri).host)
+ accept_header = 'application/json'
else
accept_header = 'application/rdf+xml'
end
@@ -199,7 +231,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)
@@ -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( {
@@ -225,7 +258,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)
@@ -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
@@ -385,7 +418,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 +431,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"
@@ -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
diff --git a/lib/ontology.rb b/lib/ontology.rb
index fa4ea6f..ad7ba7b 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:<http://www.opentox.org/api/1.1#>
+
+ def self.querystring(classname="Endpoints")
+ return CGI.escape("PREFIX ot:<http://www.opentox.org/api/1.1#>
PREFIX ota:<http://www.opentox.org/algorithms.owl#>
PREFIX owl:<http://www.w3.org/2002/07/owl#>
PREFIX dc:<http://purl.org/dc/elements/1.1/>
@@ -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 += "<option value='#{title}' id='#{endpointname}' class='level_#{level}'>#{title}</option>\n"
+ r = result.split(',')
+ endpointname = r.first.split("#").last
+ title = r[1..r.size-1]
+ out += "<option value='#{r.first}' id='#{endpointname}' class='level_#{level}'>#{title}</option>\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 = "<select id='endpoint' name='endpoint'>\n"
out += "<option value='' id='please_select'>Please select</option>\n" if include_blank
out += make_option_list
out += "</select>\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,74 @@ module OpenTox
end
+ #Model Class for OpenTox::Ontology to register/deregister and check models in the ontology service
+ #@example Register a model URI to the ontology service, check if model URI exists and delete it
+ # uri = "http://mymodelservice.net/model/1" # model uri will be checked by the ontology service itself
+ # OpenTox::Ontology::Model.register(uri)
+ # puts OpenTox::Ontology::Model.exists?(uri) # => should return true
+ # OpenTox::Ontology::Model.delete(uri)
+ # puts OpenTox::Ontology::Model.exists?(uri) # => should return false
+ module Model
+
+ # 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
+ LOGGER.warn "OpenTox::Ontology::Model.register ontology service is not reachable. Failed to register URI: #{uri} with subjectid: #{subjectid}"
+ false
+ end
+ end
+
+ # Deregister an OpenTox resource into ontology service
+ # @param [String] uri, URI of recource to deregister/delete
+ # @param [String] subjectid
+ def self.delete(uri, subjectid=nil)
+ begin
+ RestClientWrapper.delete("#{ONTOLOGY_SERVER}?uri=#{CGI.escape(uri)}", {:subjectid => CGI.escape(subjectid)})
+ rescue
+ LOGGER.warn "OpenTox::Ontology::Model.exists ontology service is not reachable. Failed to delete URI: #{uri} with subjectid: #{subjectid}"
+ false
+ end
+ end
+
+ # Find an OpenTox resource in the ontology service
+ # @param [String] uri, URI of recource to find
+ # @param [String] subjectid
+ def self.exists?(uri, subjectid=nil)
+ begin
+ out = RestClientWrapper.get("#{ONTOLOGY_SERVER}?query=#{querystring(uri)}",:accept => "text/csv").collect{|l| l.gsub("\r\n", "") if l.match(/^http/)}.uniq.compact
+ return true if out.size > 0
+ false
+ rescue
+ LOGGER.warn "OpenTox::Ontology::Model.exists ontology service is not reachable. Failed to check for URI: #{uri} with subjectid: #{subjectid}"
+ false
+ end
+ end
+
+ private
+ # Query string to find a registered model
+ # @param [String] uri, model URI
+ def self.querystring(uri)
+ return CGI.escape("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+ PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ PREFIX owl:<http://www.w3.org/2002/07/owl#>
+ PREFIX dc:<http://purl.org/dc/elements/1.1/>
+ PREFIX dcterms:<http://purl.org/dc/terms/>
+ PREFIX ot:<http://www.opentox.org/api/1.1#>
+ select distinct ?model ?title ?creator ?trainingDataset ?algorithm
+ where {
+ ?model rdf:type ot:Model;
+ OPTIONAL {?model dc:title ?title}.
+ OPTIONAL {?model dc:creator ?creator}.
+ OPTIONAL {?model ot:trainingDataset ?trainingDataset}.
+ OPTIONAL {?model ot:algorithm ?algorithm }.
+ FILTER (?model = <#{uri}>)
+ }")
+ end
+ end
+
end
-end
+end \ No newline at end of file
diff --git a/lib/opentox.rb b/lib/opentox.rb
index c76e21a..14704ec 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
@@ -46,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 3921784..b62ac45 100644
--- a/lib/serializer.rb
+++ b/lib/serializer.rb
@@ -1,5 +1,6 @@
require 'spreadsheet'
require 'yajl'
+require 'yajl/json_gem'
module OpenTox
@@ -21,6 +22,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 +71,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 +134,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,20 +219,24 @@ 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
- # 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)
@@ -268,28 +275,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
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'
diff --git a/lib/to-html.rb b/lib/to-html.rb
index 2979062..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 += "<pre><p align=\"right\">"
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+
", <a href="+$url_provider.url_for("/sign_in",:full)+">sign in</a>"
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+
", <a href="+$url_provider.url_for("/sign_out",:full)+">sign out</a>"
end
html += " </p></pre>"
@@ -61,7 +61,7 @@ module OpenTox
html += "<form method='POST' action='"+$url_provider.url_for("/sign_in",:full)+"'>"
html += "<pre><p style=\"padding:15px; border:10px solid \#5D308A\">"
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 += "<table border=0>"
html += "<tr><td>user:</td><td><input type='text' name='user' size='15' /></td></tr>"+
"<tr><td>password:</td><td><input type='password' name='password' size='15' /></td></tr>"+
@@ -111,9 +111,10 @@ 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)
+ content = "Sucessfully signed out from "+$url_provider.request.host.to_s+" ( Back to "+
+ $url_provider.url_for("",:full)+" )"
OpenTox.text_to_html(content)
end
@@ -123,11 +124,11 @@ 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)
+ 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"