summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin <martin@virtual-machine.(none)>2012-12-06 17:22:06 +0100
committermartin <martin@virtual-machine.(none)>2012-12-06 17:22:06 +0100
commit46761d137dc470c6a4ab6b573bd99713a95103d2 (patch)
treee50e09daa2b9dd3b12d63b98c32426d6ffb471ed
parente4f366398bfbeb8c961183412a15f92923a4e0ae (diff)
first step towards new architecture (4store)
-rw-r--r--.gitignore4
-rwxr-xr-xEXAMPLES341
-rw-r--r--Gemfile8
-rwxr-xr-xRakefile62
-rw-r--r--VERSION1
-rwxr-xr-xapplication.rb51
-rwxr-xr-xbin/validation-install127
-rw-r--r--config.ru12
-rwxr-xr-xexample.rb212
-rwxr-xr-xlib/active_record_setup.rb50
-rw-r--r--lib/data_mapper_util.rb37
-rwxr-xr-xlib/ot_predictions.rb4
-rw-r--r--lib/prediction_data.rb138
-rwxr-xr-xlib/predictions.rb6
-rwxr-xr-xlib/validation_db.rb6
-rwxr-xr-xnightly/nightly.rb218
-rw-r--r--nightly/nightly_application.rb22
-rwxr-xr-xreach_reports/reach_application.rb269
-rwxr-xr-xreach_reports/reach_persistance.rb1216
-rwxr-xr-xreach_reports/reach_service.rb328
-rwxr-xr-xreach_reports/reach_test.rb284
-rwxr-xr-xreport/environment.rb39
-rw-r--r--report/plot_factory.rb13
-rwxr-xr-xreport/report_application.rb2
-rw-r--r--report/report_format.rb2
-rwxr-xr-xreport/report_persistance.rb2
-rwxr-xr-xreport/report_test.rb12
-rw-r--r--report/statistical_test.rb4
-rwxr-xr-xreport/validation_access.rb17
-rwxr-xr-xreport/xml_report.rb2
-rwxr-xr-xtest/test_examples.rb76
-rwxr-xr-xtest/test_examples_util.rb19
-rw-r--r--validation.gemspec28
-rwxr-xr-xvalidation/validation_application.rb18
-rwxr-xr-xvalidation/validation_format.rb2
-rwxr-xr-xvalidation/validation_service.rb170
-rwxr-xr-xvalidation/validation_test.rb31
37 files changed, 414 insertions, 3419 deletions
diff --git a/.gitignore b/.gitignore
index 8e289af..bee53e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,7 @@ reports
public/server.log
nightly/nightly_report.html
nightly/nightly_report.xml
+Gemfile.lock
+redis-2.4.4
+redis-2.4.4 redis-2.4.4.tar.gz
+redis-2.4.4.tar.gz
diff --git a/EXAMPLES b/EXAMPLES
deleted file mode 100755
index a27e33b..0000000
--- a/EXAMPLES
+++ /dev/null
@@ -1,341 +0,0 @@
-API-Definition
-===================================================================
-
-see http://opentox.org/dev/apis/api-1.1/Validation
-
-
-API-Examples Validation
-===================================================================
-
-how to
--------------------------------------------------------------------
-the examples listed below can be performed with the command line tool curl
-
-
-get list of available validations
--------------------------------------------------------------------
-
->>> curl <validation_service>
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/<validation_id>
-<<< <validation_service>/validation_id_i
-<<< <validation_service>/validation_id_j
-
-
-get validation
--------------------------------------------------------------------
-
->>> curl <validation_service>/<validation_id>
-
-supported accept-headers: "text/x-yaml" and "application/rdf+xml"
-
-
-validate model on test-dateset
--------------------------------------------------------------------
-
->>> curl -X POST -d model_uri="<model_uri>" \
- -d test_dataset_uri="<test_dataset_uri>" \
- -d test_target_dataset_uri="<dataset_uri>" \
- <validation_service>/test_set_validation
-
-optional params:
-test_target_dataset_uri, default is test_dataset_uri
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/id_i
-
-
-validate an algorithm on a training- and test-dataset
--------------------------------------------------------------------
-
->>> curl -X POST -d algorithm_uri="<algorithm_uri>" \
- -d training_dataset_uri="<training_dataset_uri>" \
- -d test_dataset_uri="<test_dataset_uri>" \
- -d test_target_dataset_uri="<dataset_uri>" \
- -d prediction_feature="<prediction_feature>" \
- -d algorithm_params="<algorithm_params>" \
- <validation_service>/training_test_validation
-
-optional params:
-algorithm_params, default is empty
-test_target_dataset_uri, default is test_dataset_uri
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/id_i
-
-
-validate an algorithm on a dataset via training-test-split
--------------------------------------------------------------------
-
->>> curl -X POST -d algorithm_uri="<algorithm_uri>" \
- -d dataset_uri="<dataset_uri>" \
- -d prediction_feature="<prediction_feature>" \
- -d algorithm_params="<algorithm_params>" \
- -d split_ratio=0.9 \
- -d random_seed=2 \
- <validation_service>/training_test_split
-
-optional params:
-algorithm_params, default is empty
-split_ratio, default is 0.67
-random_seed, default is 1
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/id_i
-
-
-validate an algorithm on a dataset via bootstrapping
--------------------------------------------------------------------
-
->>> curl -X POST -d algorithm_uri="<algorithm_uri>" \
- -d dataset_uri="<dataset_uri>" \
- -d prediction_feature="<prediction_feature>" \
- -d algorithm_params="<algorithm_params>" \
- -d random_seed=2 \
- <validation_service>/bootstrapping
-
-optional params:
-algorithm_params, default is empty
-random_seed, default is 1
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/id_i
-
-
-get list of available crossvalidations
--------------------------------------------------------------------
-
->>> curl <validation_service>/crossvalidation
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/crossvalidation/<crossvalidation_id>
-<<< <validation_service>/crossvalidation/crossvalidation_id_i
-<<< <validation_service>/crossvalidation/crossvalidation_id_j
-
-
-get crossvalidation
--------------------------------------------------------------------
-
->>> curl <validation_service>/crossvalidation/<crossvalidation_id>
-
-supported accept-headers: "text/x-yaml" and "application/rdf+xml"
-
-
-validate an algorithm on a dataset via crossvalidation
-(may take a couple of minutes)
--------------------------------------------------------------------
-
->>> curl -X POST -d algorithm_uri="<algorithm_uri>" \
- -d dataset_uri="<dataset_uri>" \
- -d prediction_feature="<prediction_feature>" \
- -d algorithm_params="<algorithm_params>" \
- -d num_folds=5 \
- -d random_seed=2 \
- -d stratified=false \
- <validation_service>/crossvalidation
-
-optional params:
-algorithm_params, default is empty
-num_folds, default is 10
-random_seed, default is 1
-stratified, default is false
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/crossvalidation/id_i
-
-
-
-API-Examples Reports
-===================================================================
-
-
-get list of available report types
--------------------------------------------------------------------
-
->>> curl <validation_service>/report
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/report/validation
-<<< <validation_service>/report/crossvalidation
-<<< <validation_service>/report/algorithm_comparison
-
-
-get list of available reports of type validation
--------------------------------------------------------------------
-
->>> curl <validation_service>/report/validation
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/report/validation/<validation_report_id>
-<<< <validation_service>/report/validation/id_i
-<<< <validation_service>/report/validation/id_j
-
-
-get validation report
--------------------------------------------------------------------
-
->>> curl <validation_service>/report/validation/<validation_report_id>
-
-Supported formats (accept-headers):
-* "text/xml" content of report in docbook-article format
-* "text/html" report formated with default docbook-article-xsl
-* "text/x-yaml" returns report object with meta-info (without the actual report content)
-* "application/rdf+xml" returns report object with meta-info (without the actual report content)
-
-Hint: Visit <validation_service>/report/validation/<validation_report_id> with a browser to see the report in html format
-
-
-create validation report from validation
--------------------------------------------------------------------
-
->>> curl -X POST -d validation_uris="<validation_service>/<validation_id>" \
- <validation_service>/report/validation
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/report/validation/id_i
-
-
-get list of available reports of type crossvalidation
--------------------------------------------------------------------
-
->>> curl <validation_service>/report/crossvalidation
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/report/crossvalidation/<crossvalidation_report_id>
-<<< <validation_service>/report/crossvalidation/id_i
-<<< <validation_service>/report/crossvalidation/id_j
-
-
-get crossvalidation report
--------------------------------------------------------------------
-
->>> curl <validation_service>/report/crossvalidation/<crossvalidation_report_id>
-
-Supported formats (accept-headers):
-* "text/xml" content of report in docbook-article format
-* "text/html" report formated with default docbook-article-xsl
-* "text/x-yaml" returns report object with meta-info (without the actual report content)
-* "application/rdf+xml" returns report object with meta-info (without the actual report content)
-
-Hint: Visit <validation_service>/report/crossvalidation/<crossvalidation_report_id> with a browser to see the report in html format
-
-
-create crossvalidation report from crossvalidation
--------------------------------------------------------------------
-
->>> curl -X POST -d validation_uris="<validation_service>/crossvalidation/<crossvalidation_id>" \
- <validation_service>/report/crossvalidation
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/report/crossvalidation/id_i
-
-
-manually format html report
--------------------------------------------------------------------
-
->>> curl -X POST -d css_style_sheet=<css_file> \
- <validation_service>/report/crossvalidation/<crossvalidation_report_id>/format_html
-
-This explicity invokes the report convertion to html, with css-style-sheet as parameter.
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/report/crossvalidation/id_i
-
-
-
-Filter resources
-===================================================================
-
-It is possible to filter the list of available resources (i.e. validations, crossvalidation, reports) according to property-values.
-
-
-filter available validations for a particular training dataset and model
--------------------------------------------------------------------
-
->>> curl <validation_service>?trainingDataset=<training_dataset_uri>\&model=<model_uri>
-
-alternatively, use property names in (internal) yaml format:
-
->>> curl <validation_service>?training_dataset_uri=<training_dataset_uri>\&model_uri=<model_uri>
-
-
-search available validation report for a particular algorithm
--------------------------------------------------------------------
-
->>> curl <validation_service>/report/validation?algorithm=lazar
-
-alternatively, use property names in (internal) yaml format:
-
->>> curl <validation_service>/report/validation?algorithm_uris=lazar
-
-
-
-Reach reporting
-===================================================================
-
-
-get list of available qmrf report
--------------------------------------------------------------------
-
->>> curl <validation_service>/reach_report/qmrf
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/reach_report/qmrf/<qmrf_id>
-<<< <validation_service>/reach_report/qmrf/report_id_i
-<<< <validation_service>/reach_report/qmrf/report_id_j
-
-
-create a QMRF from a model
--------------------------------------------------------------------
-
->>> curl -X POST -d model_uri="<model_uri>" \
- <validation_service>/reach_report/qmrf
-
-result example (accept-header: application/rdf+xml)
-<<< not yet supported
-
-result example (accept-header: text/uri-list)
-<<< <validation_service>/reach_report/qmrf/id \ No newline at end of file
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..fada556
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,8 @@
+source :gemcutter
+gemspec
+gem "opentox-server", :path => "../opentox-server"
+gem "opentox-client", :path => "../opentox-client"
+gem "emk-sinatra-url-for", "~>0.2.1"
+gem "ruby-plot", "~>0.6.0"
+gem "ohm", "=0.1.3"
+gem "ohm-contrib", "=0.1.1" \ No newline at end of file
diff --git a/Rakefile b/Rakefile
index ca9856d..2995527 100755
--- a/Rakefile
+++ b/Rakefile
@@ -1,61 +1 @@
-require 'rubygems'
-require 'rake'
-
-desc "Perform unit tests"
-task :test do
- require 'test/unit_test.rb'
-end
-
-=begin
-
-desc "Installs gems and inits db migration"
-task :init => [:install_gems, :migrate] do
- #do nothing
-end
-
-
-desc "load config"
-task :load_config do
- require 'yaml'
- ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV']
- basedir = File.join(ENV['HOME'], ".opentox")
- config_dir = File.join(basedir, "config")
- config_file = File.join(config_dir, "#{ENV['RACK_ENV']}.yaml")
- if File.exist?(config_file)
- CONFIG = YAML.load_file(config_file)
- raise "could not load config, config file: "+config_file.to_s unless CONFIG
- end
- puts "config loaded"
-end
-
-# USE VERSION 0 instead
-#desc "Clear database"
-#task :clear_db => :load_config do
-# if CONFIG[:database][:adapter]=="mysql"
-# clear = nil
-# IO.popen("locate clear_mysql.sh"){ |f| clear=f.gets.chomp("\n") }
-# raise "clear_mysql.sh not found" unless clear
-# cmd = clear+" "+CONFIG[:database][:username]+" "+CONFIG[:database][:password]+" "+CONFIG[:database][:database]
-# IO.popen(cmd){ |f| puts f.gets }
-# else
-# raise "clear not implemented for database-type: "+CONFIG[:database][:adapter]
-# end
-#end
-
-desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
-task :migrate => :load_config do
- [ 'rubygems', 'active_record', 'logger' ].each{ |l| require l }
- puts "database config: "+@@config[:database].inspect.to_s
- ActiveRecord::Base.establish_connection(
- :adapter => CONFIG[:database][:adapter],
- :host => CONFIG[:database][:host],
- :database => CONFIG[:database][:database],
- :username => CONFIG[:database][:username],
- :password => CONFIG[:database][:password]
- )
- ActiveRecord::Base.logger = Logger.new($stdout)
- ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : 2 )
-end
-
-=end
-
+require "bundler/gem_tasks"
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..3eefcb9
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+1.0.0
diff --git a/application.rb b/application.rb
index 10c8fe6..67771f9 100755
--- a/application.rb
+++ b/application.rb
@@ -1,53 +1,22 @@
require 'rubygems'
-gem "opentox-ruby"
-[ 'sinatra', 'sinatra/url_for', 'opentox-ruby', 'benchmark' ].each do |lib|
+#gem "opentox-ruby"
+[ 'sinatra', 'sinatra/url_for', 'ohm', 'benchmark' ].each do |lib|
require lib
end
+class Sinatra::Base
+ helpers Sinatra::UrlForHelper
+end
+
#unless(defined? LOGGER)
#LOGGER = Logger.new(STDOUT)
#LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
#end
-#require "error_application.rb"
-
-require "example.rb"
-
-
-get '/examples/?' do
- LOGGER.info "list examples"
-
- if request.env['HTTP_ACCEPT'] =~ /text\/html/
- content_type "text/html"
- OpenTox.text_to_html Example.transform_example,@subjectid
- else
- content_type "text/plain"
- Example.transform_example
- end
-end
-
-get '/prepare_examples/?' do
- LOGGER.info "prepare examples"
- content_type "text/plain"
- return_task(Example.prepare_example_resources)
-end
-
-post '/test_examples/?' do
- examples = params[:examples]
- LOGGER.info "test examples "+examples.to_s
- content_type "text/plain"
- Example.test_examples(examples)
-end
-
-require "test/test_application.rb"
-require "nightly/nightly_application.rb"
-
-# order is important, first add example methods and reports, than validation
-# (otherwise sinatra will try to locate a validation with name examples or report)
-
-require "report/report_application.rb"
-require "reach_reports/reach_application.rb"
-require "validation/validation_application.rb"
+require "./test/test_application.rb"
+require "./report/report_application.rb"
+#require "./reach_reports/reach_application.rb"
+require "./validation/validation_application.rb"
diff --git a/bin/validation-install b/bin/validation-install
new file mode 100755
index 0000000..0953c63
--- /dev/null
+++ b/bin/validation-install
@@ -0,0 +1,127 @@
+#!/bin/sh
+
+# Installs Opentox Webservice.
+# Author: Christoph Helma, Andreas Maunz, Martin Gütlein
+
+SELF=$(basename $0 -install)
+[ "`id -u`" = "0" ] && echo "This script must be run as non-root." 1>&2 && exit 1
+
+SILENT=false
+if [ -n "$1" ]
+then
+ if [ "$1" = "silent" ]
+ then
+ SILENT=true
+ fi
+fi
+
+if [ $SILENT = false ]; then
+ echo
+ echo "Welcome to service installation (<Return> to continue)."
+ read delete_me
+fi
+
+# check wd is root of service
+DIR=`pwd`
+if echo $DIR | grep "$SELF/bin" >/dev/null 2>&1 ; then cd ..; fi
+SELF_DIR=`pwd`
+
+
+# # # Boot the script
+
+# load base config, helper funs, environment
+OT_CONFIG_DIR="$HOME/.opentox"
+! [ -f "$OT_CONFIG_DIR/config/install/config.sh" ] && echo "config.sh not found." 1>&2 && exit 1 || . $OT_CONFIG_DIR/config/install/config.sh
+! [ -f "$OT_PREFIX/install/utils.sh" ] && echo "utils.sh not found." 1>&2 && exit 1 || . $OT_PREFIX/install/utils.sh
+[ -f $OT_CONFIG_DIR/opentox-ui.sh ] && . $OT_CONFIG_DIR/opentox-ui.sh # should have been done by user already
+RUBY_DIR="$HOME/.rbenv/versions/$RUBY_NUM_VER"
+
+
+# # # Install
+
+check_utils "rbenv find"
+check_log $SELF
+
+if [ "$OT_BRANCH" = "development" ]; then
+ cmd="test -d $OT_PREFIX/opentox-server" && run_cmd "$cmd" "Opentox-server"
+ cmd="test -d $OT_PREFIX/opentox-client" && run_cmd "$cmd" "Opentox-client"
+fi
+
+
+# log directory for this service
+[ -d $OT_CONFIG_DIR/config/$SELF ] || cmd="mkdir -p $OT_CONFIG_DIR/config/$SELF" && run_cmd "$cmd" "Config directory"
+
+# Adjust ruby version here!
+RUBY_NUM_VER="1.9.3-p194"
+
+# ruby
+install_ruby
+
+# self
+echo
+install_with_bundler
+
+# config
+[ -f $OT_CONFIG_DIR/config/$SELF.rb ] || touch $OT_CONFIG_DIR/config/$SELF.rb
+if ! cat "$OT_CONFIG_DIR/config/$SELF.rb" | grep "four_store">/dev/null 2>&1; then echo '$four_store = { :uri => "http://localhost:9088", :user => "", :password => "" }' >> $OT_CONFIG_DIR/config/$SELF.rb; fi
+if ! cat "$OT_CONFIG_DIR/config/$SELF.rb" | grep "aa">/dev/null 2>&1; then echo '$aa = { :uri => nil }' >> $OT_CONFIG_DIR/config/$SELF.rb; fi
+if ! cat "$OT_DEFAULT_CONF" | grep "$SELF">/dev/null 2>&1; then echo '$validation = { :uri => "http://localhost:8087/validation" }' >> $OT_DEFAULT_CONF; fi
+
+#install redis
+WGET="`which wget`"
+if [ ! -e "$WGET" ]; then
+ echo "'wget' missing. Install 'wget' first. Aborting..."
+ exit 1
+fi
+REDIS_VER="2.4.4"
+REDIS_DEST="$SELF_DIR/redis-$REDIS_VER"
+REDIS_SERVER_CONF="$REDIS_DEST/redis.conf"
+LOG="redis-log.txt"
+echo
+echo "Redis (log: '$LOG', dir: '$REDIS_DEST'):"
+REDIS_DONE=false
+mkdir "$REDIS_DEST" >/dev/null 2>&1
+if [ ! -d "$REDIS_DEST" ]; then
+ echo "Install directory '$REDIS_DEST' is not available! Aborting..."
+ exit 1
+else
+ if ! rmdir "$REDIS_DEST" >/dev/null 2>&1; then # if not empty this will fail
+ REDIS_DONE=true
+ fi
+fi
+if ! $REDIS_DONE; then
+ echo "vm.overcommit_memory = 1" | sudo tee -a /etc/sysctl.conf >>$LOG 2>&1
+ URI="http://redis.googlecode.com/files/redis-$REDIS_VER.tar.gz"
+ if ! [ -d "redis-$REDIS_VER" ]; then
+ cmd="$WGET $URI" && run_cmd "$cmd" "Download"
+ cmd="tar zxf redis-$REDIS_VER.tar.gz" && run_cmd "$cmd" "Unpack"
+ fi
+ cd redis-$REDIS_VER >>$LOG 2>&1
+ cmd="make" && run_cmd "$cmd" "Make"
+ if ! grep "daemonize yes" $REDIS_SERVER_CONF >>$LOG 2>&1 ; then
+ echo "daemonize yes" > $REDIS_SERVER_CONF 2>$LOG
+ fi
+ if ! grep "dir `pwd`" $REDIS_SERVER_CONF >>$LOG 2>&1 ; then
+ echo "dir `pwd`" >> $REDIS_SERVER_CONF 2>$LOG
+ fi
+ if ! grep "save 900 1" $REDIS_SERVER_CONF >>$LOG 2>&1 ; then
+ echo "save 900 1" >> $REDIS_SERVER_CONF 2>$LOG
+ fi
+else
+ echo "redis already installed"
+fi
+if [ ! -f $REDIS_CONF ]; then
+ echo "if ! echo \"\$PATH\" | grep \"$REDIS_DEST\">/dev/null 2>&1; then export PATH=$REDIS_DEST/src:\$PATH; fi" >> "$REDIS_CONF"
+ echo "Redis configuration has been stored in '$REDIS_CONF'."
+ #if ! grep ". \"$REDIS_CONF\"" $OT_UI_CONF; then
+ # echo ". \"$REDIS_CONF\"" >> $OT_UI_CONF
+ #fi
+fi
+
+
+if [ $SILENT = false ]; then
+ notify
+fi
+
+# return to wd
+cd "$DIR"
diff --git a/config.ru b/config.ru
index 305bd9f..e7c5323 100644
--- a/config.ru
+++ b/config.ru
@@ -1,7 +1,5 @@
-require 'rubygems'
-require 'sinatra'
-require 'application.rb'
-require 'config/config_ru'
-run Sinatra::Application
-set :raise_errors, false
-set :show_exceptions, false \ No newline at end of file
+SERVICE = "validation"
+require 'bundler'
+Bundler.require
+require './application.rb'
+run run Sinatra::Application
diff --git a/example.rb b/example.rb
deleted file mode 100755
index 636579e..0000000
--- a/example.rb
+++ /dev/null
@@ -1,212 +0,0 @@
-
-require 'lib/test_util.rb'
-
-class Example
-
- @@file=File.new("data/hamster_carcinogenicity.csv","r")
- @@file_type="text/x-yaml"
- @@model=File.join CONFIG[:services]["opentox-model"],"1"
- #@@feature= URI.encode("http://local-ot/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)")
- @@feature= File.join CONFIG[:services]["opentox-dataset"],"1/feature/Hamster%2520Carcinogenicity"
- #@@predicted_feature= URI.encode("http://local-ot/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)_lazar_classification")
- @@alg = File.join CONFIG[:services]["opentox-algorithm"],"lazar"
- @@alg_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
- @@data=File.join CONFIG[:services]["opentox-dataset"],"1"
- @@train_data=File.join CONFIG[:services]["opentox-dataset"],"2"
- @@test_data=File.join CONFIG[:services]["opentox-dataset"],"3"
- @@prediction_data=File.join CONFIG[:services]["opentox-dataset"],"5"
- @@css_file="http://apps.ideaconsult.net:8080/ToxPredict/style/global.css"
-
- @@summary=""
-
- # replaces placeholdes ( in <> brackets ) in EXAMPLE file with uris and ids
- def self.transform_example
-
- file = File.new("EXAMPLES", "r")
- res = ""
- while (line = file.gets)
- res += line
- end
- file.close
-
- sub = { "validation_service" => CONFIG[:services]["opentox-validation"].chomp("/"),
- "validation_id" => "1",
- "model_uri" => @@model,
- "dataset_uri" => @@data,
- "training_dataset_uri" => @@train_data,
- "test_dataset_uri" => @@test_data,
- "prediction_feature" => @@feature,
- "algorithm_uri" => @@alg,
- "algorithm_params" => @@alg_params,
- "crossvalidation_id" => "1",
- "validation_report_id" => "1",
- "crossvalidation_report_id" => "2",
- "css_file" => @@css_file,
- "prediction_dataset_uri" => @@prediction_data,
- #"predicted_feature" => @@predicted_feature,
- "qmrf_id" => "1"}
-
- sub.each do |k,v|
- res.gsub!(/<#{k}>/,v)
- end
- res
- end
-
- # creates the resources that are requested by the examples
- def self.prepare_example_resources
-
- #TODO
- subjectid = nil
-
- Ohm.flush
-
- task = OpenTox::Task.create("prepare examples", "n/a") do |task|
- @@summary = ""
-
- #delete validations
- #log "delete validations"
- #Lib::Validation.auto_migrate!
- #Lib::Crossvalidation.auto_migrate!
- #ActiveRecord::Base.logger = Logger.new("/dev/null")
- #ActiveRecord::Migrator.migrate('db/migrate', 0 )
- #ActiveRecord::Migrator.migrate('db/migrate', 1 )
- #ActiveRecord::Migrator.migrate('db/migrate', 2 )
-
- #delete all qmrf reports
- ReachReports::QmrfReport.auto_migrate!
-
- #delete_all(CONFIG[:services]["opentox-dataset"])
- log OpenTox::RestClientWrapper.delete CONFIG[:services]["opentox-dataset"]
- task.progress(10)
-
- log "upload dataset"
- raise OpenTox::BadRequestError.new"File not found: "+@@file.path.to_s unless File.exist?(@@file.path)
- #data = File.read(@@file.path)
- #data_uri = OpenTox::RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:content_type => @@file_type},data).chomp("\n")
- dataset = OpenTox::Dataset.create_from_csv_file(@@file.path,nil)
- data_uri = dataset.uri
- log "-> "+data_uri
- task.progress(20)
-
- log "train-test-validation"
- #delete_all(CONFIG[:services]["opentox-model"])
- OpenTox::RestClientWrapper.delete CONFIG[:services]["opentox-model"]
-
- split_params = Validation::Util.train_test_dataset_split(data_uri, URI.decode(@@feature), nil, 0.9, 1)
- v = Validation::Validation.new :training_dataset_uri => split_params[:training_dataset_uri],
- :validation_type => "test_set_validation",
- :test_dataset_uri => split_params[:test_dataset_uri],
- :test_target_dataset_uri => data_uri,
- :prediction_feature => URI.decode(@@feature),
- :algorithm_uri => @@alg
- v.validate_algorithm( @@alg_params, OpenTox::SubTask.new(task, 20, 40) )
-
- log "crossvalidation"
- cv = Validation::Crossvalidation.create({ :dataset_uri => data_uri, :algorithm_uri => @@alg, :num_folds => 5, :stratified => false })
- cv.perform_cv( URI.decode(@@feature), @@alg_params, OpenTox::SubTask.new(task, 40, 70) )
-
- log "create validation report"
- rep = Reports::ReportService.instance(File.join(CONFIG[:services]["opentox-validation"],"report"))
- rep.delete_all_reports("validation", subjectid)
- rep.create_report("validation",v.validation_uri)
- task.progress(80)
-
- log "create crossvalidation report"
- rep.delete_all_reports("crossvalidation", subjectid)
- rep.create_report("crossvalidation",cv.crossvalidation_uri)
- task.progress(90)
-
- log "build qmrf"
- t = ReachReports.create_report("QMRF",{:model_uri=>@@model})
- Lib::TestUtil.wait_for_task(t)
- task.progress(100)
-
- log "done"
- @@summary
- end
- task
- end
-
- # performs all curl calls listed in examples after ">>>", next line is added if line ends with "\"
- def self.test_examples(example_uri=nil)
-
- if (example_uri)
- examples = OpenTox::RestClientWrapper.get(example_uri)
- else
- examples = transform_example # use local examples
- end
-
- lines = examples.split("\n")
- curl_call = false
- curl_calls = []
-
- lines.each do |line|
- if line =~ /^\s*>>>\s*.*/
- line.gsub!(/^\s*>>>\s*/,"")
- if line =~ /.*\s*\\s*$/
- curl_call = true
- line.gsub!(/\s*\\s*$/," ")
- else
- curl_call = false
- end
- curl_calls.push( line )
- elsif curl_call
- if line =~ /.*\s*\\s*$/
- curl_call = true
- line.gsub!(/\s*\\s*$/," ")
- else
- curl_call = false
- end
- curl_calls[-1] = curl_calls[-1]+line
- end
- end
-
- Spork.spork(:logger => LOGGER) do
- @@summary = ""
- num = 0
- suc = 0
- curl_calls.each do |cmd|
- num += 1
- log "testing: "+cmd
- result = ""
- IO.popen(cmd.to_s+" 2> /dev/null") do |f|
- while line = f.gets
- result += line if result.size<50
- end
- end
- result.chomp!
- result.gsub!(/\n/, " \\n ")
- if ($?==0)
- if result.task_uri?
- log "wait for task: "+result
- result = Lib::TestUtil.wait_for_task(result)
- end
- log "ok ( " +result.to_s[0,50]+" )"
- suc += 1
- else
- log "failed ( " +result.to_s[0,50]+" )"
- end
- end
- log suc.to_s+"/"+num.to_s+" curls succeeded"
- @@summary
- end
- "testing in background, check log for results"
- end
-
- private
- # deletes resources listed by service
- def self.delete_all(uri_list_service)
- uri_list = OpenTox::RestClientWrapper.get(uri_list_service)
- LOGGER.debug "deleting: "+uri_list.inspect
- uri_list.split("\n").each do |uri|
- OpenTox::RestClientWrapper.delete(uri)
- end
- end
-
- # logs string and and adds to summary
- def self.log(log_string)
- LOGGER.info "EXAMPLE: "+log_string
- @@summary += log_string+"\n"
- end
-
-end
diff --git a/lib/active_record_setup.rb b/lib/active_record_setup.rb
deleted file mode 100755
index 5f081af..0000000
--- a/lib/active_record_setup.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-
-#gem "activerecord", "= 2.3.8"
-#gem "ar-extensions", "= 0.9.2"
-['rubygems', 'logger', 'active_record', 'opentox-ruby' ].each do |g| #'ar-extensions',
- require g
-end
-
-unless ActiveRecord::Base.connected?
- ActiveRecord::Base.establish_connection(
- :adapter => CONFIG[:database][:adapter],
- :host => CONFIG[:database][:host],
- :database => CONFIG[:database][:database],
- :username => CONFIG[:database][:username],
- :password => CONFIG[:database][:password]
- )
- ActiveRecord::Base.logger = Logger.new("/dev/null")
-end
-
-class ActiveRecord::Base
-
- def self.find_like(filter_params)
-
- raise "find like removed"
-
- #puts "params before "+filter_params.inspect
- filter_params.keys.each do |k|
- key = k.to_s
- unless self.column_names.include?(key)
- key = key.from_rdf_format
- unless self.column_names.include?(key)
- key = key+"_uri"
- unless self.column_names.include?(key)
- key = key+"s"
- unless self.column_names.include?(key)
- err = "no attribute found: '"+k.to_s+"'"
-# if $sinatra
-# $sinatra.raise OpenTox::BadRequestError.newerr
-# else
- raise err
-# end
- end
- end
- end
- end
- filter_params[key+"_like"] = filter_params.delete(k)
- end
- #puts "params after "+filter_params.inspect
- self.find(:all, :conditions => filter_params)
- end
-end
diff --git a/lib/data_mapper_util.rb b/lib/data_mapper_util.rb
deleted file mode 100644
index 23f52f5..0000000
--- a/lib/data_mapper_util.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-
-#DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, 0)
-
-module Lib
- module DataMapperUtil
-
- def self.check_params(model, params)
- prop_names = model.properties.collect{|p| p.name.to_s if p.is_a?DataMapper::Property::Object}
- params.keys.each do |k|
- key = k.to_s
- if (key == "subjectid")
- params.delete(k)
- else
- unless prop_names.include?(key)
- key = key.from_rdf_format
- unless prop_names.include?(key)
- key = key+"_uri"
- unless prop_names.include?(key)
- key = key+"s"
- unless prop_names.include?(key)
- raise OpenTox::BadRequestError.new "no attribute found: '"+k.to_s+"'"
- end
- end
- end
- end
- params[key.to_sym] = params.delete(k)
- end
- end
- params
- end
-
- def self.all(model, filter_params)
- model.all(check_params(model,filter_params))
- end
-
- end
-end \ No newline at end of file
diff --git a/lib/ot_predictions.rb b/lib/ot_predictions.rb
index 2752fcc..8ddf364 100755
--- a/lib/ot_predictions.rb
+++ b/lib/ot_predictions.rb
@@ -1,6 +1,6 @@
-require "lib/prediction_data.rb"
-require "lib/predictions.rb"
+require "./lib/prediction_data.rb"
+require "./lib/predictions.rb"
module Lib
diff --git a/lib/prediction_data.rb b/lib/prediction_data.rb
index d387d24..f42cd9f 100644
--- a/lib/prediction_data.rb
+++ b/lib/prediction_data.rb
@@ -1,6 +1,7 @@
module Lib
+
class PredictionData
CHECK_VALUES = ENV['RACK_ENV'] =~ /debug|test/
@@ -53,17 +54,14 @@ module Lib
@compounds
end
- def self.create( feature_type, test_dataset_uris, test_target_dataset_uris,
- prediction_feature, prediction_dataset_uris, predicted_variables, predicted_confidences,
- subjectid=nil, task=nil )
+ def self.create( feature_type, test_dataset_uris, prediction_feature, prediction_dataset_uris,
+ predicted_variables, predicted_confidences, subjectid=nil, task=nil )
test_dataset_uris = [test_dataset_uris] unless test_dataset_uris.is_a?(Array)
- test_target_dataset_uris = [test_target_dataset_uris] unless test_target_dataset_uris.is_a?(Array)
prediction_dataset_uris = [prediction_dataset_uris] unless prediction_dataset_uris.is_a?(Array)
predicted_variables = [predicted_variables] unless predicted_variables.is_a?(Array)
predicted_confidences = [predicted_confidences] unless predicted_confidences.is_a?(Array)
LOGGER.debug "loading prediction -- test-dataset: "+test_dataset_uris.inspect
- LOGGER.debug "loading prediction -- test-target-datset: "+test_target_dataset_uris.inspect
LOGGER.debug "loading prediction -- prediction-dataset: "+prediction_dataset_uris.inspect
LOGGER.debug "loading prediction -- predicted_variable: "+predicted_variables.inspect
LOGGER.debug "loading prediction -- predicted_confidence: "+predicted_confidences.inspect
@@ -84,7 +82,6 @@ module Lib
test_dataset_uris.size.times do |i|
test_dataset_uri = test_dataset_uris[i]
- test_target_dataset_uri = test_target_dataset_uris[i]
prediction_dataset_uri = prediction_dataset_uris[i]
predicted_variable = predicted_variables[i]
predicted_confidence = predicted_confidences[i]
@@ -94,35 +91,18 @@ module Lib
test_dataset = Lib::DatasetCache.find test_dataset_uri,subjectid
raise "test dataset not found: '"+test_dataset_uri.to_s+"'" unless test_dataset
- if test_target_dataset_uri == nil || test_target_dataset_uri.strip.size==0 || test_target_dataset_uri==test_dataset_uri
- test_target_dataset_uri = test_dataset_uri
- test_target_dataset = test_dataset
- raise "prediction_feature not found in test_dataset, specify a test_target_dataset\n"+
- "prediction_feature: '"+prediction_feature.to_s+"'\n"+
- "test_dataset: '"+test_target_dataset_uri.to_s+"'\n"+
- "available features are: "+test_target_dataset.features.inspect if test_target_dataset.features.keys.index(prediction_feature)==nil
- else
- test_target_dataset = Lib::DatasetCache.find test_target_dataset_uri,subjectid
- raise "test target datset not found: '"+test_target_dataset_uri.to_s+"'" unless test_target_dataset
- if CHECK_VALUES
- test_dataset.compounds.each do |c|
- raise "test compound not found on test class dataset "+c.to_s unless test_target_dataset.compounds.include?(c)
- end
- end
- raise "prediction_feature not found in test_target_dataset\n"+
- "prediction_feature: '"+prediction_feature.to_s+"'\n"+
- "test_target_dataset: '"+test_target_dataset_uri.to_s+"'\n"+
- "available features are: "+test_target_dataset.features.inspect if test_target_dataset.features.keys.index(prediction_feature)==nil
- end
+ raise "prediction_feature not found in test_dataset\n"+
+ "prediction_feature: '"+prediction_feature.to_s+"'\n"+
+ "test_dataset: '"+test_dataset_uri.to_s+"'\n"+
+ "available features are: "+test_dataset.features.inspect if test_dataset.features.keys.index(prediction_feature)==nil
- compounds = test_dataset.compounds
- LOGGER.debug "test dataset size: "+compounds.size.to_s
- raise "test dataset is empty "+test_dataset_uri.to_s unless compounds.size>0
+ LOGGER.debug "test dataset size: "+test_dataset.compounds.size.to_s
+ raise "test dataset is empty "+test_dataset_uri.to_s unless test_dataset.compounds.size>0
if feature_type=="classification"
- av = test_target_dataset.accept_values(prediction_feature)
+ av = test_dataset.accept_values(prediction_feature)
raise "'"+OT.acceptValue.to_s+"' missing/invalid for feature '"+prediction_feature.to_s+"' in dataset '"+
- test_target_dataset_uri.to_s+"', acceptValues are: '"+av.inspect+"'" if av==nil or av.length<2
+ test_dataset_uri.to_s+"', acceptValues are: '"+av.inspect+"'" if av==nil or av.length<2
if accept_values==nil
accept_values=av
else
@@ -131,20 +111,15 @@ module Lib
end
actual_values = []
- tmp_compounds = []
- compounds.each do |c|
+ test_dataset.compounds.size.times do |c_idx|
case feature_type
when "classification"
- vals = classification_vals(test_target_dataset, c, prediction_feature, accept_values)
+ actual_values << classification_val(test_dataset, c_idx, prediction_feature, accept_values)
when "regression"
- vals = regression_vals(test_target_dataset, c, prediction_feature)
- end
- vals.each do |v|
- actual_values << v
- tmp_compounds << c
+ actual_values << numeric_val(test_dataset, c_idx, prediction_feature)
end
+ #raise "WTF #{c_idx} #{test_dataset.compounds[c_idx]} #{actual_values[-1]} #{actual_values[-2]}" if c_idx>0 and test_dataset.compounds[c_idx]==test_dataset.compounds[c_idx-1] and actual_values[-1]!=actual_values[-2]
end
- compounds = tmp_compounds
task.progress( task_status += task_step ) if task # loaded actual values
prediction_dataset = Lib::DatasetCache.find prediction_dataset_uri,subjectid
@@ -160,41 +135,42 @@ module Lib
"prediction_dataset: '"+prediction_dataset_uri.to_s+"'\n"+
"available features are: "+prediction_dataset.features.inspect if predicted_confidence and prediction_dataset.features.keys.index(predicted_confidence)==nil and prediction_dataset.compounds.size>0
- raise "more predicted than test compounds, #test: "+compounds.size.to_s+" < #prediction: "+
+ raise "more predicted than test compounds, #test: "+test_dataset.compounds.size.to_s+" < #prediction: "+
prediction_dataset.compounds.size.to_s+", test-dataset: "+test_dataset_uri.to_s+", prediction-dataset: "+
- prediction_dataset_uri if compounds.size < prediction_dataset.compounds.size
+ prediction_dataset_uri if test_dataset.compounds.size < prediction_dataset.compounds.size
if CHECK_VALUES
prediction_dataset.compounds.each do |c|
raise "predicted compound not found in test dataset:\n"+c+"\ntest-compounds:\n"+
- compounds.collect{|c| c.to_s}.join("\n") if compounds.index(c)==nil
+ test_dataset.compounds.collect{|c| c.to_s}.join("\n") unless test_dataset.compounds.include?(c)
end
end
predicted_values = []
confidence_values = []
- count = 0
- compounds.each do |c|
- if prediction_dataset.compounds.index(c)==nil
+
+ test_dataset.compounds.size.times do |test_c_idx|
+ c = test_dataset.compounds[test_c_idx]
+ pred_c_idx = prediction_dataset.compound_index(test_dataset,test_c_idx)
+ if pred_c_idx==nil
+ raise "internal error: mapping failed" if prediction_dataset.compounds.include?(c)
predicted_values << nil
confidence_values << nil
else
+ raise "internal error: mapping failed" unless c==prediction_dataset.compounds[pred_c_idx]
case feature_type
when "classification"
- vals = classification_vals(prediction_dataset, c, predicted_variable, accept_values)
+ predicted_values << classification_val(prediction_dataset, pred_c_idx, predicted_variable, accept_values)
when "regression"
- vals = regression_vals(prediction_dataset, c, predicted_variable)
+ predicted_values << numeric_val(prediction_dataset, pred_c_idx, predicted_variable)
end
- raise "not yet implemented: more than one prediction for one compound" if vals.size>1
- predicted_values << vals[0]
if predicted_confidence
- confidence_values << confidence_val(prediction_dataset, c, predicted_confidence)
+ confidence_values << numeric_val(prediction_dataset, pred_c_idx, predicted_confidence)
else
confidence_values << nil
end
end
- count += 1
end
- all_compounds += compounds
+ all_compounds += test_dataset.compounds
all_predicted_values += predicted_values
all_actual_values += actual_values
all_confidence_values += confidence_values
@@ -237,61 +213,23 @@ module Lib
end
private
- def self.regression_vals(dataset, compound, feature)
- v_num = []
- values(dataset, compound, feature).each do |v|
- if v==nil or v.is_a?(Numeric)
- v_num << v
- else
- begin
- v_num << v.to_f
- rescue
- LOGGER.warn "no numeric value for regression: '"+v.to_s+"'"
- v_num << nil
- end
- end
- end
- v_num
- end
-
- def self.confidence_val(dataset, compound, confidence)
- v = values(dataset, compound, confidence)
- raise "not yet implemented: duplicate conf value" if v.size>1
+ def self.numeric_val(dataset, compound_index, feature)
+ v = dataset.data_entry_value(compound_index, feature)
begin
- v = v[0]
v = v.to_f unless v==nil or v.is_a?(Numeric)
v
rescue
- LOGGER.warn "no numeric value for confidence '"+v.to_s+"'"
+ LOGGER.warn "no numeric value for feature '#{feature}' : '#{v}'"
nil
end
end
- def self.classification_vals(dataset, compound, feature, accept_values)
- v_indices = []
- values(dataset, compound, feature).each do |v|
- i = accept_values.index(v)
- raise "illegal class_value of prediction (value is '"+v.to_s+"'), accept values are "+
- accept_values.inspect unless v==nil or i!=nil
- v_indices << i
- end
- v_indices
+ def self.classification_val(dataset, compound_index, feature, accept_values)
+ v = dataset.data_entry_value(compound_index, feature)
+ i = accept_values.index(v)
+ raise "illegal class_value of prediction (value is '"+v.to_s+"'), accept values are "+
+ accept_values.inspect unless v==nil or i!=nil
+ i
end
-
- def self.values(dataset, compound, feature)
- return [nil] if dataset.data_entries[compound]==nil
- if feature==nil
- v = dataset.data_entries[compound].values[0]
- else
- v = dataset.data_entries[compound][feature]
- end
- return [nil] if v==nil
- # sanitiy checks
- raise "no array "+v.class.to_s+" : '"+v.to_s+"'" unless v.is_a?(Array)
- v.each{|vv| raise "array-elem is array" if vv.is_a?(Array)}
- # replace empty strings with nil
- v_mod = v.collect{|vv| (vv.to_s().size==0 ? nil : vv)}
- v_mod
- end
end
end
diff --git a/lib/predictions.rb b/lib/predictions.rb
index d929f1a..9f62d31 100755
--- a/lib/predictions.rb
+++ b/lib/predictions.rb
@@ -1,5 +1,5 @@
-require "lib/prediction_data.rb"
+require "./lib/prediction_data.rb"
module Lib
@@ -805,8 +805,8 @@ module Lib
end
def self.test_r_square
- require "rubygems"
- require "opentox-ruby"
+ #require "rubygems"
+ #require "opentox-ruby"
max_deviation = rand * 0.9
avg_deviation = max_deviation * 0.5
diff --git a/lib/validation_db.rb b/lib/validation_db.rb
index 086853e..e486a62 100755
--- a/lib/validation_db.rb
+++ b/lib/validation_db.rb
@@ -2,13 +2,12 @@
#[ 'rubygems', 'datamapper' ].each do |lib|
# require lib
#end
-require "lib/merge.rb"
+require "./lib/merge.rb"
module Validation
VAL_PROPS_GENERAL = [ :validation_uri, :validation_type, :model_uri, :algorithm_uri, :algorithm_params,
- :training_dataset_uri, :prediction_feature, :test_dataset_uri, :test_target_dataset_uri,
- :prediction_dataset_uri, :date ]
+ :training_dataset_uri, :prediction_feature, :test_dataset_uri, :prediction_dataset_uri, :date ]
VAL_PROPS_SUM = [ :num_instances, :num_without_class, :num_unpredicted ]
VAL_PROPS_AVG = [:real_runtime, :percent_without_class, :percent_unpredicted ]
VAL_PROPS = VAL_PROPS_GENERAL + VAL_PROPS_SUM + VAL_PROPS_AVG
@@ -59,7 +58,6 @@ module Validation
attribute :algorithm_uri
attribute :algorithm_params
attribute :training_dataset_uri
- attribute :test_target_dataset_uri
attribute :test_dataset_uri
attribute :prediction_dataset_uri
attribute :prediction_feature
diff --git a/nightly/nightly.rb b/nightly/nightly.rb
deleted file mode 100755
index 07cd11a..0000000
--- a/nightly/nightly.rb
+++ /dev/null
@@ -1,218 +0,0 @@
-
-require 'test/test_examples.rb'
-
-class Nightly
-
- NIGHTLY_REP_DIR = File.join(FileUtils.pwd,"nightly")
- NIGHTLY_REPORT_XML = "nightly_report.xml"
- NIGHTLY_REPORT_HTML = "nightly_report.html"
-
- def self.get_nightly
- LOGGER.info("Accessing nightly report.")
- if File.exist?(File.join(NIGHTLY_REP_DIR,NIGHTLY_REPORT_HTML))
- return File.new(File.join(NIGHTLY_REP_DIR,NIGHTLY_REPORT_HTML))
- else
- return "Nightly report not available, try again later"
- end
- end
-
- def self.build_nightly(select=nil, dry_run=false)
-
- validationExamples = ValidationExamples.select(select)
- return "please \"select\" validation examples:\n"+ValidationExamples.list if validationExamples.size==0
-
- task = OpenTox::Task.create("Build nightly","nightly-validation-test-service") do |task| #,{:select => select, :dry_run => dry_run})
- LOGGER.info("Building nightly report")
-
- benchmarks = validationExamples.collect{ |e| ValidationBenchmark.new(e) }
-
- running = []
- report = Reports::XMLReport.new("Nightly Validation", Time.now.strftime("Created at %m.%d.%Y - %H:%M"))
- count = 1
- benchmarks.each do |b|
- id = "["+count.to_s+"]-"+b.title
- count += 1
- running << id
- Thread.new do
- begin
- b.build()
- rescue => ex
- LOGGER.error "uncaught nightly build error: "+ex.message
- ensure
- running.delete id
- end
- end
- end
- wait = 0
- while running.size>0
- LOGGER.debug "Nightly report waiting for "+running.inspect if wait%60==0
- wait += 1
- sleep 1
- end
- LOGGER.debug "Nightly report, all benchmarks done "+running.inspect
-
- section_about = report.add_section(report.get_root_element, "About this report")
- report.add_paragraph(section_about,
- "This a opentox internal test report. Its purpose is to maintain interoperability between the OT validation web service "+
- "and other OT web services. If you have any comments, remarks, or wish your service/test-case to be added, please email "+
- "to guetlein@informatik.uni-freiburg.de or use the issue tracker at http://opentox.informatik.uni-freiburg.de/simple_ot_stylesheet.css")
-
- benchmarks.each do |b|
- section = report.add_section(report.get_root_element, b.title)
-
- section_info = report.add_section(section, "Info")
- info_table = b.info_table
- report.add_table(section_info, "Validation info", info_table) if info_table
-
- section_results = report.add_section(section, "Results")
- report.add_table(section_results, "Valdation results", b.result_table)
-
- if (b.comparison_report)
- report.add_table(section_results, "Validation comparison report", [[b.comparison_report]], false)
- end
-
- section_errors = report.add_section(section, "Errors")
-
- if b.errors and b.errors.size>0
- b.errors.each do |k,v|
- elem = report.add_section(section_errors,k)
- report.add_paragraph(elem,v,true)
- end
- else
- report.add_paragraph(section_errors,"no errors occured")
- end
-
- end
-
- unless dry_run
- report.write_to(File.new(File.join(NIGHTLY_REP_DIR,NIGHTLY_REPORT_XML), "w"))
- Reports::ReportFormat.format_report_to_html(NIGHTLY_REP_DIR,
- NIGHTLY_REPORT_XML,
- NIGHTLY_REPORT_HTML,
- nil)
- #"http://www.opentox.org/portal_css/Opentox%20Theme/base-cachekey7442.css")
- #"http://apps.ideaconsult.net:8080/ToxPredict/style/global.css")
- LOGGER.info("Nightly report completed")
- else
- LOGGER.info("Nightly report completed - DRY RUN, no report creation")
- end
-
- #benchmarks.collect{|b| b.uris}.join(",")
- File.join(CONFIG[:services]["opentox-validation"],"nightly")
- end
- return_task(task)
- end
-
- class ValidationBenchmark
-
- attr_accessor :errors, :comparison_report
-
- def comparable
- if @comp == nil
- @comp = @validation_examples[0].algorithm_uri==nil ? :model_uri : :algorithm_uri
- end
- @comp
- end
-
- def uris
- @validation_examples.collect{|v| v.validation_uri}.join(",")
- end
-
- def initialize(validationExamples)
- @validation_examples = []
- validationExamples.each do |v|
- example = v.new
- @validation_examples << example
- end
- end
-
- def title
- if @validation_examples.size==0
- @validation_examples[0].class.humanize
- else
- @validation_examples[0].class.superclass.humanize
- end
- end
-
- def result_table
- t = []
- row = [comparable.to_s, "validation", "report"]
- t << row
- @validation_examples.each do |e|
- row = [ e.send(comparable),
- (e.validation_error!=nil ? "error, see below" : e.validation_uri),
- (e.report_error!=nil ? "error, see below" : e.report_uri) ]
- t << row
- end
- t
- end
-
- def info_table
- t = []
- t << ["param", "uri"]
-
- (@validation_examples[0].params+@validation_examples[0].opt_params).each do |p|
- map = {}
- @validation_examples.each{|e| map[e.send(p).to_s]=nil }
-
- if map.size==1 && map.keys[0].size==0
- #omit
- elsif map.size==1 #values equal
- t << [p.to_s, map.keys[0]]
- else
- count = 1
- @validation_examples.each do |e|
- t << [p.to_s+" ["+count.to_s+"]", e.send(p)]
- count += 1
- end
- end
- end
- t
- end
-
- def build()
-
- @errors = {}
-
- running = []
- count = 1
-
- @validation_examples.each do |v|
-
- id = "["+count.to_s+"]-"+v.title
- count += 1
- running << id
- LOGGER.debug "Uploading datasets: "+v.title
- v.upload_files
- v.check_requirements
-
- Thread.new do
-
- LOGGER.debug "Validate: "+v.title
- v.validate
- if v.validation_error!=nil
- @errors["Error validating "+v.title] = v.validation_error
- else
- LOGGER.debug "Building report: "+v.title
- v.report
- if v.report_error!=nil
- @errors["Error building report for "+v.title] = v.report_error
- end
- end
- running.delete(id)
- end
- end
-
- wait = 0
- while running.size>0
- LOGGER.debug self.title+" waiting for "+running.inspect if wait%20==0
- wait += 1
- sleep 1
- end
-
- LOGGER.debug self.class.to_s.gsub(/Nightly::/, "")+": build comparison report"
- @comparison_report = ValidationExamples::Util.build_compare_report(@validation_examples)
- end
- end
-
-end
diff --git a/nightly/nightly_application.rb b/nightly/nightly_application.rb
deleted file mode 100644
index 69b4614..0000000
--- a/nightly/nightly_application.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require "nightly/nightly.rb"
-
-post '/build_nightly/?' do
- dry_run = params[:dry_run]!=nil and params[:dry_run]
- Nightly.build_nightly(params["select"],dry_run)
-end
-
-get '/css_style_sheet/?' do
- perform do |rs|
- "@import \""+params[:css_style_sheet]+"\";"
- end
-end
-
-get '/nightly/?' do
- content_type "text/html"
- rep = Nightly.get_nightly
- if rep.is_a?(File)
- result = body(rep)
- else
- result = rep
- end
-end
diff --git a/reach_reports/reach_application.rb b/reach_reports/reach_application.rb
deleted file mode 100755
index b380c92..0000000
--- a/reach_reports/reach_application.rb
+++ /dev/null
@@ -1,269 +0,0 @@
-
-[ 'rubygems', 'sinatra', 'sinatra/url_for', 'opentox-ruby' ].each do |lib|
- require lib
-end
-
-QMRF_EDITOR_URI = "http://ortona.informatik.uni-freiburg.de/qmrfedit/OT_QMRFEditor.jnlp"
-
-# hack for as long as mysql lite is used
-def mysql_lite_retry( n_times=15 )
- n_times.times do
- begin
- yield
- return
- rescue => ex
- LOGGER.warn "datamapper error, wait and retry : "+ex.message
- sleep(1+rand(3)) # wait 1-3 seconds
- end
- end
- yield # try a last time
-end
-
-require 'reach_reports/reach_persistance.rb'
-require 'reach_reports/reach_service.rb'
-
-require "lib/format_util.rb"
-
-def extract_type(params)
- raise OpenTox::BadRequestError.new "illegal type, neither QMRF nor QPRF: "+params[:type] unless params[:type] && params[:type] =~ /(?i)Q(M|P)RF/
- params.delete("type")
-end
-
-get '/reach_report' do
- uri_list = url_for('/reach_report/QMRF', :full)+"\n"+url_for('/reach_report/QPRF', :full)+"\n"
- if request.env['HTTP_ACCEPT'] =~ /text\/html/
- content_type "text/html"
- related_links =
- "All validations: "+url_for("/",:full)+"\n"+
- "Validation reporting: "+url_for("/report",:full)
- description =
- "A list of all suported REACH reporting types."
- OpenTox.text_to_html uri_list,related_links,description, @subjectid
- else
- content_type "text/uri-list"
- uri_list
- end
-end
-
-get '/reach_report/:type' do
- type = extract_type(params)
- LOGGER.info "list all "+type+" reports"
- uris = ReachReports.list_reports(type,params[:model] || params[:model_uri])
- if request.env['HTTP_ACCEPT'] =~ /text\/html/
- content_type "text/html"
- related_links =
- "All REACH reporting types: "+url_for("/reach_report",:full)
- description =
- "A list of "+type+" reports."
- post_command = nil
- case type
- when /(?i)QMRF/
- related_links += "\n"+
- "OpenTox version of QMRF editor: "+QMRF_EDITOR_URI
- description += "\n"+
- "To create a QMRF report use the POST method."
- post_command = OpenTox::PostCommand.new request.url,"Create QMRF report"
- post_command.attributes << OpenTox::PostAttribute.new("model_uri")
- when /(?i)QPRF/
- #TODO
- end
- OpenTox.text_to_html uris,@subjectid,related_links,description,post_command
- else
- content_type "text/uri-list"
- uris
- end
-end
-
-post '/reach_report/:type' do
-
- type = extract_type(params)
- content_type "text/uri-list"
-
- LOGGER.info "creating "+type+" report "+params.inspect
- raise OpenTox::BadRequestError.new "model_uri missing" if type=~/(?i)QMRF/ and
- params[:model_uri]!=nil and params[:model_uri].to_s.size==0
-
- #puts "creating "+type+" report "+params.inspect
- result_uri = ReachReports.create_report(type,params,@subjectid,request.env["rack.input"])
-
- if result_uri and result_uri.task_uri?
- halt 202,result_uri+"\n"
- else
- result_uri+"\n"
- end
-end
-
-get '/reach_report/:type/:id' do
-
- type = extract_type(params)
- LOGGER.info "get "+type+" report with id '"+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'"
- rep = ReachReports.get_report(type, params[:id])
-
- case request.env['HTTP_ACCEPT'].to_s
- when "application/rdf+xml"
- raise OpenTox::BadRequestError.new "application/rdf+xml not yet supported"
- owl = OpenTox::Owl.create(type+"Report",rep.report_uri)
- owl.set_data( rep.get_content.keys_to_rdf_format )
- owl.rdf
- when "application/qmrf-xml"
- content_type "application/qmrf-xml"
- rep.to_xml
- #f = File.new("/home/martin/info_home/.public_html/qmrf.out.xml","w")
- #f.puts result
- when /text\/html/
- content_type "text/html"
- related_links =
- "Open report in QMRF editor: "+rep.report_uri+"/editor"+"\n"+
- "All "+type+" reports: "+url_for("/reach_report/"+type,:full)
- description =
- "A QMRF report."
- OpenTox.text_to_html rep.to_yaml,@subjectid,related_links,description
- when /application\/x-yaml|\*\/\*|^$/ # matches 'application/x-yaml', '*/*', ''
- content_type "application/x-yaml"
- rep.to_yaml
- else
- raise OpenTox::BadRequestError.new "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\", \"application/x-yaml\", \"application/qmrf-xml\"."
- end
-end
-
-post '/reach_report/:type/:id' do
-
- type = extract_type(params)
- LOGGER.info "Post to "+type+" report with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'"
- rep = ReachReports.get_report(type, params[:id])
-
- input = request.env["rack.input"].read
- raise OpenTox::BadRequestError.new "no xml data specified" unless input && input.to_s.size>0
- LOGGER.debug "size of posted data: "+input.to_s.size.to_s
-
- ReachReports::QmrfReport.from_xml(rep,input)
-
- #f = File.new("/home/martin/info_home/.public_html/qmrf.out.xml","w")
- #f.puts rep.to_xml
-end
-
-delete '/reach_report/:type/:id' do
- type = extract_type(params)
- LOGGER.info "delete "+type+" report with id '"+params[:id].to_s+"'"
- ReachReports.delete_report(type, params[:id], @subjectid)
-end
-
-
-#get '/reach_report/:type/:id/:section' do
-#
-# type = extract_type(params)
-# LOGGER.info "get "+type+" report section '"+params[:section].to_s+"', with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'"
-# ReachReports.get_report(type, params[:id], params[:section]).to_yaml
-#end
-#
-#get '/reach_report/:type/:id/:section/:subsection' do
-#
-# type = extract_type(params)
-# LOGGER.info "get "+type+" report subsection '"+params[:subsection].to_s+"', section '"+params[:section].to_s+"', with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'"
-# ReachReports.get_report(type, params[:id], params[:section], params[:subsection]).to_yaml
-#end
-
-get '/reach_report/:type/:id/editor' do
-
- type = extract_type(params)
- LOGGER.info "editor for "+type+" report with id '"+params[:id].to_s+"' "+params.inspect
-
- jnlp = <<EOF
-<?xml version ="1.0" encoding="utf-8"?>
-<jnlp spec="1.0+" codebase="http://opentox.informatik.uni-freiburg.de/" href="qmrfedit/OT_QMRFEditor.jnlp" >
-<information>
-<title>QMRF Editor</title>
-<vendor>www.opentox.org</vendor>
-<description>(Q)SAR Model Reporting Format Editor</description>
-<description kind="short">(Q)SAR Model Reporting Format Editor</description>
-<icon href="qmrfedit/OTLogo.png" />
-</information>
-<resources>
-<j2se version="1.6+" java-vm-args="-Xincgc"/>
-
-<jar href="qmrfedit/OT_QMRFEditor.jar" download="eager" main="true"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/xercesImpl.jar" download="eager"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/itext-1.4.5.jar" download="lazy"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/poi-3.0.jar" download="lazy"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/poi-contrib.jar" download="lazy"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/poi-scratchpad.jar" download="lazy"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/commons-lang-2.3.jar" download="lazy"/>
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-applications.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-builder3d.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-charges.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-core.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-datadebug.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-data.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-experimental.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-extra.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-forcefield.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-interfaces.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-io.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-jchempaint.applet.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-jchempaint.application.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-jchempaint.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-libio-cml.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-libio-weka.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-nonotify.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-pdb-cml.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-pdb.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-qsar-cml.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-qsar.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/cdk-qsar-pdb.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/commons-cli-1.0.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/commons-io-1.1.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/commons-logging-1.0.4.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/commons-codec-1.3.jar" download="eager" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/fop.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/jai_codec.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/jai_core.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/jgrapht-0.6.0.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/jh.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/l2fprod-common-all.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/libfonts-0.1.4.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/log4j-1.2.8.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/log4j.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/mysql-connector-java-5.0.5-bin.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/naming-factory-dbcp.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/naming-factory.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/naming-resources.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/opsin-big-0.1.0.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/org.restlet.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/swing-layout-1.0.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/xmlgraphics-commons-1.1.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/xom-1.1b2.jar" download="lazy" />
-<jar href="qmrfedit/OT_QMRFEditor_lib/xom-1.1.jar" download="lazy" />
-
-
-</resources>
-<application-desc main-class="ambit.applications.qmrf.QMRFEditor">
-<argument>-x
-EOF
- jnlp.chomp!
- jnlp += File.join(url_for("/reach_report/QMRF",:full),params[:id])
-
- if @subjectid.to_s.size>0
- jnlp += <<EOF
-</argument>
-<argument>--subjectid=
-EOF
- jnlp.chomp!
- jnlp += @subjectid.to_s
- end
-
- jnlp += <<EOF
-</argument>
-<argument>-d http://opentox.informatik.uni-freiburg.de/qmrfedit/qmrf.dtd</argument>
-<argument>-t http://opentox.informatik.uni-freiburg.de/qmrfedit/verdana.ttf</argument>
-
-</application-desc>
-<security>
- <all-permissions/>
-</security>
-</jnlp>
-EOF
-
- content_type "application/x-java-jnlp-file"
- jnlp
-end
-
diff --git a/reach_reports/reach_persistance.rb b/reach_reports/reach_persistance.rb
deleted file mode 100755
index 1226d95..0000000
--- a/reach_reports/reach_persistance.rb
+++ /dev/null
@@ -1,1216 +0,0 @@
-
-['dm-core', 'dm-serializer', 'dm-timestamps', 'dm-types', 'dm-migrations', 'dm-validations' ].each{|lib| require lib }
-db_dir = File.join(File.join(ENV['HOME'], ".opentox"), "db")
-FileUtils.mkdir_p db_dir
-DataMapper::setup(:default, "sqlite3://#{db_dir}/reach_reports.sqlite3")
-
-DataMapper::Model.raise_on_save_failure = true
-
-module REXML
-
- class Element
- def self.find_or_create(parent_node, name)
- if parent_node.elements[name]
- parent_node.elements[name]
- else
- node = Element.new(name)
- parent_node << node
- node
- end
- end
- end
-
- class TextElement < Element
- def initialize(name, text)
- super(name)
- self.text = text
- end
-
- def self.find_or_create(parent_node, name, text)
- elem = Element.find_or_create(parent_node, name)
- elem.text = text
- elem
- end
- end
-end
-
-
-class Symbol
-
- XML_ALIAS = {
- :qsar_identifier => "QSAR_identifier", :qsar_title => "QSAR_title", :qsar_software => "QSAR_software",
- :qsar_models => "QSAR_models", :qsar_general_information => "QSAR_General_information",
- :qsar_endpoint => "QSAR_Endpoint", :qmrf_author => "qmrf_authors", :qsar_algorithm => "QSAR_Algorithm",
- :qsar_applicability_domain => "QSAR_Applicability_domain", :qsar_robustness => "QSAR_Robustness",
- :qsar_predictivity => "QSAR_Predictivity", :qsar_interpretation => "QSAR_Interpretation",
- :qsar_miscellaneous => "QSAR_Miscelaneous", :qmrf_summary => "QMRF_Summary", :qmrf_number => "QMRF_number" }
-
- def xml_alias
- XML_ALIAS[self] ? XML_ALIAS[self] : self.to_s
- end
-end
-
-class DataMapper::Associations::OneToMany::Relationship
- def get_child_model
- @child_model
- end
-end
-
-module DataMapper::Resource
-
- def association_class( property )
- relationship = relationships[property]
- raise "no relationship found for "+property.to_s+" "+relationships.inspect unless relationship
- raise "not a many-to-one or one-to-one association for "+property.to_s+" "+relationship.inspect unless
- relationship.is_a?(DataMapper::Associations::OneToMany::Relationship) or
- relationship.is_a?(DataMapper::Associations::OneToOne::Relationship)
- relationship.get_child_model
- end
-
- def from_xml(node)
-
- raise "node is nil ("+self.class.to_s+".from_xml)" unless node
- #puts "FROM xml: "+self.class.to_s #+", NODE: "+node.to_s
-
- dbg_check = { :attributes => Set.new(), :nodes => Set.new(), :subnodes => Set.new() }
-
- xml_infos.each do |xml_info|
-
- if xml_info.is_a?(ReachReports::TextNodeProperty)
- text_node = node.elements[ xml_info.xml_prop ]
- raise "node not found: "+ xml_info.xml_prop+" ("+self.class.to_s+".from_xml)" unless text_node
- self.send( xml_info.prop.to_s+"=", text_node.text )
- dbg_check[:nodes] << text_node.name
-
- elsif xml_info.is_a?(ReachReports::CatalogReference)
- root_node = node.elements[ xml_info.xml_prop ]
- raise "node not found: "+ xml_info.xml_prop+" ("+self.class.to_s+".from_xml)" unless root_node
- dbg_check[:nodes] << root_node.name
-
- self.send(xml_info.prop).each{ |s| s.destroy } if self.send(xml_info.prop)
- self.send(xml_info.prop).clear() #otherwise the content is tmp still here
-
- catalog_node = $catalogs_node.elements[xml_info.catalog_name]
-
- root_node.each_element(xml_info.catalog_element+"_ref") do |n|
- ref = nil
- catalog_node.each_element_with_attribute("id", n.attribute("idref").to_s) do |e|
- ref = e
- break
- end
- raise "referenced node not found for "+xml_info.xml_prop+" in catalog "+xml_info.catalog_name+" ref-node was "+n.to_s unless ref
- dbg_check[:subnodes] << n
-
- entry = self.association_class(xml_info.prop).new
- entry.from_xml( ref )
- self.send(xml_info.prop) << entry
- end
-
- elsif xml_info.is_a?(ReachReports::AttributeProperty)
- #puts "attr "+xml_info.prop.to_s
- self.send(xml_info.prop.to_s+"=", node.attribute(xml_info.xml_prop))
- dbg_check[:attributes] << xml_info.prop
-
- elsif xml_info.is_a?(ReachReports::TextSubnodeProperty)
- parent_node = node.elements[ xml_info.parent_prop.xml_alias ]
- raise "parent node not found: '"+ xml_info.parent_prop.xml_alias+"' ("+self.class.to_s+".from_xml)" unless parent_node
- text_node = parent_node.elements[ xml_info.xml_prop ]
- raise "node not found: "+ xml_info.xml_prop+" ("+self.class.to_s+".from_xml)" unless text_node
- self.send( xml_info.prop.to_s+"=", text_node.text )
- dbg_check[:nodes] << parent_node.name
- dbg_check[:subnodes] << text_node
-
- elsif xml_info.is_a?(ReachReports::SingleAttributeNodeProperty)
- attr_node = node.elements[ xml_info.xml_prop ]
- self.send(xml_info.prop.to_s+"=", attr_node.attribute(xml_info.attribute))
- dbg_check[:nodes] << attr_node.name
-
- elsif xml_info.is_a?(ReachReports::AttributeNodeProperty)
- attr_node = node.elements[ xml_info.xml_prop ]
- entry = self.association_class( xml_info.prop ).new
- entry.from_xml(attr_node)
- self.send(xml_info.prop.to_s+"=",entry)
- dbg_check[:nodes] << attr_node.name
-
- elsif xml_info.is_a?(ReachReports::AttributeSubNodeListProperty)
-
- parent_node = node.elements[ xml_info.parent_prop.xml_alias ]
- raise "parent node not found: '"+ xml_info.parent_prop.xml_alias+"' ("+self.class.to_s+".from_xml)" unless parent_node
- #puts "parent node "+xml_info.parent_prop.xml_alias
- prop_node = parent_node.elements[ xml_info.xml_prop ]
- if prop_node
- #puts "prop node "+xml_info.xml_prop.to_s
- prop_node.each_element do |n|
- #puts "elem node "+n.name.to_s
- raise "illegal node '"+n.name.to_s+"' should be '"+xml_info.list_element.to_s+"'" unless n.name==xml_info.list_element.to_s
- entry = self.association_class( xml_info.prop ).new
- entry.from_xml( n )
- self.send(xml_info.prop) << entry
- end
- dbg_check[:subnodes] << prop_node
- end
- dbg_check[:nodes] << parent_node.name
-
- else
- raise "type not supported yet: "+xml_info.inspect
- end
- end
-
- ##raise "not a qsar_identifier" unless qsar_identifier.is_a?(QsarIdentifier)
-
- #puts node.elements.inspect
- #puts "there we go: "+qsar_identifier.qsar_software.to_s
- #qsar_identifier.qsar_software = QsarSoftware.new
- #puts "there we go: "+qsar_identifier.qsar_software.to_s
- #exit
-
- # if defined?(self.class.text_properties)
-# self.class.text_properties.each do |p|
-# puts "set "+p.to_s
-# raise "node not found: "+p.xml_alias.to_s+" ("+self.class.to_s+".from_xml)" unless node.elements[p.xml_alias]
-# #puts "set "+p.to_s+" to: "+node.elements[p.xml_alias].text.to_s
-# self.send(p.to_s+"=", node.elements[p.xml_alias].text)
-# #qsar_identifier.qsar_models = node.elements["qsar_models".xml_alias].text
-# dbg_check[:nodes] << node.elements[p.xml_alias].name
-# end
-#
-
-
-# if defined?(self.class.subsection_properties)
-# self.class.subsection_properties.each do |section_p, subsection_p|
-# #puts "set "+p.to_s
-# #raise "node not found: "+p.xml_alias.to_s+" ("+self.class.to_s+".from_xml)" unless node.elements[p.xml_alias]
-# #puts "set "+p.to_s+" to: "+node.elements[p.xml_alias].text.to_s
-# section = node.elements[section_p.xml_alias]
-# subsection = section.elements[subsection_p.xml_alias]
-# self.send(subsection_p.to_s+"=", subsection.text)
-#
-# dbg_check[:nodes] << section.name
-# dbg_check[:subnodes] << subsection
-#
-# #qsar_identifier.qsar_models = node.elements["qsar_models".xml_alias].text
-# #dbg_check[:text_nodes] << node.elements[p.xml_alias].name
-# end
-# end
-
-# if defined?(self.class.attribute_properties)
-# self.class.attribute_properties.each do |p|
-# puts "read attribute "+p.to_s
-# #self.update(p => node.attribute(p.xml_alias))
-# self.send(p.to_s+"=", node.attribute(p.xml_alias))
-# dbg_check[:attributes] << p
-# #qsar_identifier.qsar_models = node.elements["qsar_models".xml_alias].text
-# end
-# end
-
- #qsar_identifier.qsar_title = node.elements["qsar_title".xml_alias].text
- #qsar_identifier.qsar_models = node.elements["qsar_models".xml_alias].text
-
-
-
- ignore_attribs =[ "id", "name", "help", "chapter" ]
- node.attributes.each do |a,v|
- unless (ignore_attribs.include?(a.to_s)) || dbg_check[:attributes].include?(a.to_sym)
- raise "not handled : attribute '"+a.to_s+"' -> '"+v.to_s+"'" +
- "\n("+self.class.to_s+".from_xml)" +
- "\nchecked:\n"+dbg_check[:attributes].to_yaml+
- "\nnode-attribtues:\n"+node.attributes.to_yaml
- end
- end
-
- node.each_element do |n|
-# if n.text!=nil and n.text.to_s.size>0 and
-# !dbg_check[:text_nodes].include?(n.name) and
-# (!dbg_check[:catalog_nodes].has_key?(n.name))
-
- valid = dbg_check[:nodes].include?(n.name)
- if (valid)
- refs = dbg_check[:subnodes]
- #puts "sub "+refs.inspect
- n.each_element do |nn|
- #puts "lookin for ref "+nn.to_s
- unless refs.include?(nn)
- valid = false
- break
- end
- end
- end
-
- unless valid
- raise puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nnot handled node : "+n.to_s+
- "\n("+self.class.to_s+".from_xml)"
-# raise "not handled node : "+n.to_s+
-# "\n("+self.class.to_s+".from_xml)" +
-# "\nchecked text nodes:\n"+dbg_check[:text_nodes].to_yaml+
-# "\nchecked catalog nodes:\n"+dbg_check[:catalog_nodes].to_yaml+
-# "\nnode-attribtues:\n"+n.attributes.to_yaml
- end
- end
-
-
- #self.save!
- #self.reload
-# unless self.save
-# self.errors.each do |e|
-# puts "Error: "+e.to_s
-# end
-# end
- #puts "self id: "+self.id.to_s
-
-# qsar_identifier.qsar_software.each{ |s| s.destroy } if qsar_identifier.qsar_software
-# qsar_identifier.qsar_software.update({}) #otherwise the content is tmp still here
-#
-# catalog_node = $catalogs_node.elements["software_catalog"]
-#
-# node.elements[:qsar_software.xml_alias].each_element do |n|
-#
-# puts "reading software ref "+n.to_s
-# ref = nil
-# catalog_node.each_element_with_attribute("id", n.attribute("idref").to_s) do |e|
-# ref = e
-# break
-# end
-# software = QsarSoftware.new
-# QsarSoftware.from_xml( software, ref )
-# qsar_identifier.qsar_software << software
-# end
-# #qsar_identifier.qsar_software = QsarSoftware.new unless qsar_identifier.qsar_software
-# #QsarSoftware.from_xml( qsar_identifier.qsar_software, node.elements["qsar_software".xml_alias] )
-
- end
-
- def to_XML(node, chapter=nil )
-
- xml_infos.each do |xml_info|
- if xml_info.is_a?(ReachReports::TextNodeProperty)
- new_node = REXML::TextElement.find_or_create(node, xml_info.xml_prop,self.send(xml_info.prop))
-
- elsif xml_info.is_a?(ReachReports::CatalogReference)
-
- new_node = REXML::Element.find_or_create( node, xml_info.xml_prop )
- catalog_node = $catalogs_node.elements[ xml_info.catalog_name ]
-
- self.send(xml_info.prop.to_s+"=",[self.association_class(xml_info.prop).new]) unless self.send(xml_info.prop) and self.send(xml_info.prop).size>0
-
- self.send( xml_info.prop ).each do |elem|
- elem_node = REXML::Element.new(xml_info.catalog_element )
- elem.to_XML( elem_node )
- # if not saved, i.e. the element was only created for a complete xml, count elements in catalog for id
- element_id = xml_info.catalog_element+"_"+(elem.id ? elem.id.to_s : (catalog_node.elements.size+1).to_s)
- elem_node.add_attribute("id",element_id)
- catalog_node << elem_node
-
- ref_node = REXML::Element.new(xml_info.catalog_element+"_ref" )
- ref_node.add_attributes("idref"=>element_id,"catalog"=>xml_info.catalog_name)
- new_node << ref_node
- end
-
- elsif xml_info.is_a?(ReachReports::AttributeProperty)
- node.add_attribute( xml_info.xml_prop, self.send(xml_info.prop).to_s )
-
- elsif xml_info.is_a?(ReachReports::TextSubnodeProperty)
- new_node = REXML::Element.find_or_create( node, xml_info.parent_prop.xml_alias)
- REXML::TextElement.find_or_create( new_node, xml_info.xml_prop,self.send(xml_info.prop))
-
- elsif xml_info.is_a?(ReachReports::SingleAttributeNodeProperty)
- new_node = REXML::Element.find_or_create(node, xml_info.xml_prop)
- new_node.add_attribute(xml_info.attribute, self.send(xml_info.prop).to_s)
-
- elsif xml_info.is_a?(ReachReports::AttributeNodeProperty)
- new_node = REXML::Element.find_or_create(node, xml_info.xml_prop)
- self.send(xml_info.prop.to_s+"=",self.association_class(xml_info.prop).new) unless self.send(xml_info.prop)
- self.send(xml_info.prop).to_XML(new_node)
-
- elsif xml_info.is_a?(ReachReports::AttributeSubNodeListProperty)
- new_node = REXML::Element.find_or_create( node, xml_info.parent_prop.xml_alias )
- #puts "new parent "+xml_info.parent_prop.xml_alias
- prop_node = REXML::Element.find_or_create( new_node, xml_info.xml_prop )
- #puts "new prop "+xml_info.xml_prop
- self.send( xml_info.prop ).each do |elem|
- #puts "elem "+elem.to_yaml
- elem_node = REXML::Element.new( xml_info.list_element.xml_alias )
- elem.to_XML( elem_node )
- prop_node << elem_node
- end
-
- else
- raise "type not supported yet: "+xml_info.inspect
- end
-
- new_node.add_attribute("chapter", chapter.to_s+"."+node.elements.size.to_s) if chapter and new_node and new_node.attribute("chapter")==nil
- end
-
-# if defined?(self.class.text_properties)
-# self.class.text_properties.each do |p|
-# node << REXML::TextElement.new(p.xml_alias,self.send(p))
-# end
-# end
- #node << REXML::TextElement.new(:qsar_title.xml_alias,qsar_title)
- #node << REXML::TextElement.new(:qsar_models.xml_alias,qsar_models)
-
-# if defined?(self.class.catalog_entries)
-# self.class.catalog_entries.each do |p| #,associatedClass|
-#
-# assoc_node = REXML::Element.new( p.xml_alias )
-# self.send(p).each{ |s| s.to_XML( assoc_node ) }
-# node << assoc_node
-# end
-# end
-#
-# if defined?(self.class.catalog_name)
-# catalog_node = $catalogs_node.elements[self.class.catalog_name]
-# node_ref = REXML::Element.new(self.class.catalog_element+"_ref")
-#
-# raise "id is nil" if self.id==nil || self.id.to_s.size==0
-# element_id = self.class.catalog_element+"_"+self.id.to_s
-# node_ref.add_attributes("idref"=>element_id,"catalog"=>self.class.catalog_name)
-#
-# content_node = REXML::Element.new(self.class.catalog_element)
-# content_node.add_attribute("id",element_id)
-# self.class.attribute_properties.each do |p|
-# content_node.add_attribute p.xml_alias,send(p)
-# end
-# catalog_node << content_node
-# node << node_ref
-#
-## def catalog_to_xml(node, catalog_name, element_name, attributes)
-## catalog_node = $catalogs_node.elements[catalog_name]
-## node_ref = REXML::Element.new(element_name+"_ref")
-## attributes["id"] = element_name+"_"+attributes.delete("id").to_s
-## node_ref.add_attributes("idref"=>attributes["id"],"catalog"=>catalog_name)
-## content_node = REXML::Element.new(element_name)
-## #puts "my attribts: "+attributes.inspect
-## attributes.each do |k,v|
-## content_node.add_attribute k,v.to_s
-## end
-## catalog_node << content_node
-## node << node_ref
-## end
-# end
-
-
-# node << REXML::TextElement.new(:qsar_title.xml_alias,qsar_title)
-# node << REXML::TextElement.new(:qsar_models.xml_alias,qsar_models)
-# qsar_software_node = REXML::Element.new(:qsar_software.xml_alias)
-# qsar_software.each{ |s| s.to_xml( qsar_software_node ) }
-# node << qsar_software_node
- end
-
-end
-
-
-module ReachReports
-
- def self.get_uri( report )
- raise "internal error, id not set "+to_yaml if report.id==nil
- return $url_provider.url_for("/"+File.join(report.type,report.id.to_s), :full).to_s
- end
-
-
-
-
-# module CatalogEntry
-#
-# def catalog_to_xml(node, catalog_name, element_name, attributes)
-# catalog_node = $catalogs_node.elements[catalog_name]
-# node_ref = REXML::Element.new(element_name+"_ref")
-# attributes["id"] = element_name+"_"+attributes.delete("id").to_s
-# node_ref.add_attributes("idref"=>attributes["id"],"catalog"=>catalog_name)
-# content_node = REXML::Element.new(element_name)
-# #puts "my attribts: "+attributes.inspect
-# attributes.each do |k,v|
-# content_node.add_attribute k,v.to_s
-# end
-# catalog_node << content_node
-# node << node_ref
-# end
-# end
-
-# class QsarSoftware
-# include DataMapper::Resource #, CatalogEntry
-#
-# property :id, Serial
-# property :contact, String, :length => 255
-# property :description, String, :length => 255
-# property :name, String, :length => 255
-# property :number, String, :length => 255
-# property :url, String, :length => 255
-#
-# def self.attribute_properties
-# [ :contact, :description, :name, :number, :url ]
-# end
-#
-# def self.catalog_name
-# "software_catalog"
-# end
-#
-# def self.catalog_element
-# "software"
-# end
-#
-# belongs_to :qsar_identifier
-# end
-
- class Software
- include DataMapper::Resource #, CatalogEntry
-
- property :id, Serial
- property :contact, String, :length => 255
- property :description, String, :length => 255
- property :name, String, :length => 255
- property :number, String, :length => 255
- property :url, String, :length => 255
-
- def xml_infos
- [ AttributeProperty.new(:contact),
- AttributeProperty.new(:description),
- AttributeProperty.new(:name),
- AttributeProperty.new(:number),
- AttributeProperty.new(:url) ]
- end
- end
-
- class QsarSoftware < Software
- #belongs_to :qsar_identifier, :key => false
- property :qsar_identifier_id, Integer
- end
-
- class XmlInfo
-
- attr_accessor :prop
-
- protected
- def initialize( prop )
- @prop = prop
- end
-
- public
- def xml_prop
- @prop.xml_alias
- end
- end
-
- class TextNodeProperty < XmlInfo
-
- end
-
- class TextSubnodeProperty < XmlInfo
- attr_accessor :parent_prop
-
- def initialize( prop, parent_prop )
- super(prop)
- @parent_prop = parent_prop
- end
- end
-
- class AttributeProperty < XmlInfo
-
- end
-
- class AttributeNodeProperty < XmlInfo
-
- end
-
- class AttributeSubNodeListProperty < XmlInfo
-
- attr_accessor :list_element, :parent_prop
-
- def initialize( prop, list_element, parent_prop )
- super(prop)
- @list_element = list_element
- @parent_prop = parent_prop
- end
- end
-
- class SingleAttributeNodeProperty < XmlInfo
- attr_accessor :attribute
-
- def initialize( prop, attribute )
- super(prop)
- @attribute = attribute
- end
- end
-
- class CatalogReference < XmlInfo
- attr_accessor :catalog_name, :catalog_element
-
- def initialize( prop, catalog_name, catalog_element )
- super(prop)
- @catalog_name = catalog_name
- @catalog_element = catalog_element
- end
- end
-
-
- class QsarIdentifier
- include DataMapper::Resource
-
- property :id, Serial
- property :qsar_title, Text
- property :qsar_models, Text
-
- has n, :qsar_software
-
- def xml_infos
- [ TextNodeProperty.new(:qsar_title),
- TextNodeProperty.new(:qsar_models),
- CatalogReference.new(:qsar_software, "software_catalog", "software") ]
- end
-
- belongs_to :qmrf_report
- end
-
- class Author
- include DataMapper::Resource
-
- property :id, Serial
- property :affiliation, String, :length => 255
- property :contact, String, :length => 255
- property :email, String, :length => 255
- property :name, String, :length => 255
- property :number, String, :length => 255
- property :url, String, :length => 255
-
- def xml_infos
- [ AttributeProperty.new(:affiliation),
- AttributeProperty.new(:contact),
- AttributeProperty.new(:email),
- AttributeProperty.new(:name),
- AttributeProperty.new(:number),
- AttributeProperty.new(:url) ]
- end
-
- belongs_to :qsar_general_information
- end
-
- class QmrfAuthor < Author
- property :type, String, :default => "QmrfAuthor"
- end
-
- class ModelAuthor < Author
- property :type, String, :default => "ModelAuthor"
- end
-
- class Publication
- include DataMapper::Resource
-
- property :id, Serial
- property :title, Text
- property :url, String, :length => 255
-
- def xml_infos
- [ AttributeProperty.new(:title),
- AttributeProperty.new(:url) ]
- end
- end
-
- class Reference < Publication
- #belongs_to :qsar_general_information
- property :qsar_general_information_id, Integer
- end
-
-
- class QsarGeneralInformation
- include DataMapper::Resource
-
- property :id, Serial
- property :qmrf_date, Text #String, :length => 255 #PENDING -> datetime
- property :model_date, Text #String, :length => 255 #PENDING -> datetime
- property :qmrf_date_revision, Text #String, :length => 255 #PENDING -> datetime
- property :qmrf_revision, Text
- property :model_date, Text
- property :info_availability, Text
- property :related_models, Text
-
- # type is needed to distinguish between authors
- # (the datamapper creates a table "Authors", the relation is defined by QsarGeneral.id and Author.id)
- has n, :qmrf_authors, :type => "QmrfAuthor"
- has n, :model_authors, :type => "ModelAuthor"
- has n, :references
-
- def xml_infos
- [ TextNodeProperty.new(:qmrf_date),
- CatalogReference.new(:qmrf_authors, "authors_catalog", "author"),
- TextNodeProperty.new(:qmrf_date_revision),
- TextNodeProperty.new(:qmrf_revision),
- CatalogReference.new(:model_authors, "authors_catalog", "author"),
- TextNodeProperty.new(:model_date),
- CatalogReference.new(:references, "publications_catalog", "publication"),
- TextNodeProperty.new(:info_availability),
- TextNodeProperty.new(:related_models) ]
- end
-
- belongs_to :qmrf_report
- end
-
- class ModelEndpoint
- include DataMapper::Resource
-
- property :id, Serial
- property :group, String, :length => 255
- property :name, String, :length => 255
- property :subgroup, String, :length => 255
-
- def xml_infos
- [ AttributeProperty.new(:group),
- AttributeProperty.new(:name),
- AttributeProperty.new(:subgroup) ]
- end
-
- belongs_to :qsar_endpoint
- end
-
- class QsarEndpoint
- include DataMapper::Resource
-
- property :id, Serial
- property :endpoint_variable, Text
- property :model_species, Text
- property :endpoint_comments, Text
- property :endpoint_units, Text
- property :endpoint_protocol, Text
- property :endpoint_data_quality, Text
-
- has n, :model_endpoint
-
- def xml_infos
- [ TextNodeProperty.new(:model_species),
- CatalogReference.new(:model_endpoint, "endpoints_catalog", "endpoint"),
- TextNodeProperty.new(:endpoint_comments),
- TextNodeProperty.new(:endpoint_units),
- TextNodeProperty.new(:endpoint_variable),
- TextNodeProperty.new(:endpoint_protocol),
- TextNodeProperty.new(:endpoint_data_quality) ]
- end
-
- belongs_to :qmrf_report
- end
-
- class AlgorithmExplicit
- include DataMapper::Resource
-
- property :id, Serial
- property :definition, Text
- property :description, Text
- property :publication_ref, Text
-
- def xml_infos
- [ AttributeProperty.new(:definition),
- AttributeProperty.new(:description),
- AttributeProperty.new(:publication_ref) ]
- end
-
- belongs_to :qsar_algorithm
- end
-
- class AlgorithmsDescriptor
- include DataMapper::Resource
-
- property :id, Serial
- property :description, Text
- property :name, Text
- property :publication_ref, Text
- property :units, Text
-
- def xml_infos
- [ AttributeProperty.new(:description),
- AttributeProperty.new(:name),
- AttributeProperty.new(:publication_ref),
- AttributeProperty.new(:units) ]
- end
-
- belongs_to :qsar_algorithm
- end
-
- class DescriptorsGenerationSoftware < Software
-
- #belongs_to :qsar_algorithm, :key => false
- property :qsar_algorithm_id, Integer
- end
-
- class QsarAlgorithm
- include DataMapper::Resource
-
- property :id, Serial
-
- property :algorithm_type, Text
- property :descriptors_selection, Text
- property :descriptors_generation, Text
- property :descriptors_chemicals_ratio, Text
- property :equation, Text
-
- has n, :algorithm_explicit
- has n, :algorithms_descriptors
- has n, :descriptors_generation_software
-
- def xml_infos
- [ TextNodeProperty.new(:algorithm_type),
- CatalogReference.new(:algorithm_explicit, "algorithms_catalog", "algorithm"),
- TextSubnodeProperty.new(:equation, :algorithm_explicit),
- CatalogReference.new(:algorithms_descriptors, "descriptors_catalog", "descriptor"),
- TextNodeProperty.new(:descriptors_selection),
- TextNodeProperty.new(:descriptors_generation),
- CatalogReference.new(:descriptors_generation_software, "software_catalog", "software"),
- TextNodeProperty.new(:descriptors_chemicals_ratio),
- ]
- end
-
- belongs_to :qmrf_report
- end
-
- class AppDomainSoftware < Software
-
- #belongs_to :qsar_algorithm, :key => false
- property :qsar_applicability_domain_id, Integer
- end
-
- class QsarApplicabilityDomain
- include DataMapper::Resource
-
- property :id, Serial
- property :app_domain_description, Text
- property :app_domain_method, Text
- property :applicability_limits, Text
-
- has n,:app_domain_software
-
- def xml_infos
- [ TextNodeProperty.new(:app_domain_description),
- TextNodeProperty.new(:app_domain_method),
- CatalogReference.new(:app_domain_software, "software_catalog", "software"),
- TextNodeProperty.new(:applicability_limits), ]
- end
-
- belongs_to :qmrf_report
-
- end
-
- class DatasetData
- include DataMapper::Resource
-
- property :id, Serial
- property :chemname, String, :default => "No"
- property :cas, String, :default => "No"
- property :smiles, String, :default => "No"
- property :inchi, String, :default => "No"
- property :mol, String, :default => "No"
- property :formula, String, :default => "No"
-
- def xml_infos
- [ AttributeProperty.new(:chemname),
- AttributeProperty.new(:cas),
- AttributeProperty.new(:smiles),
- AttributeProperty.new(:inchi),
- AttributeProperty.new(:mol),
- AttributeProperty.new(:formula) ]
- end
-
- end
-
- class TrainingSetData < DatasetData
-
- #belongs_to :qsar_robustness
- property :qsar_robustness_id, Integer
- end
-
-
- class QsarRobustness
- include DataMapper::Resource
-
- property :id, Serial
- property :training_set_availability, String, :default => "No"
- property :training_set_descriptors, String, :default => "No"
- property :dependent_var_availability, String, :default => "No"
- property :other_info, Text
- property :preprocessing, Text
- property :goodness_of_fit, Text
- property :loo, Text
- property :lmo, Text
- property :yscrambling, Text
- property :bootstrap, Text
- property :other_statistics, Text
-
- has 1, :training_set_data, :model => "TrainingSetData"
-
- def xml_infos
- [ SingleAttributeNodeProperty.new(:training_set_availability, "answer"),
- AttributeNodeProperty.new(:training_set_data),
- SingleAttributeNodeProperty.new(:training_set_descriptors, "answer"),
- SingleAttributeNodeProperty.new(:dependent_var_availability, "answer"),
- TextNodeProperty.new(:other_info),
- TextNodeProperty.new(:preprocessing),
- TextNodeProperty.new(:goodness_of_fit),
- TextNodeProperty.new(:loo),
- TextNodeProperty.new(:lmo),
- TextNodeProperty.new(:yscrambling),
- TextNodeProperty.new(:bootstrap),
- TextNodeProperty.new(:other_statistics),
- ]
- end
-
- belongs_to :qmrf_report
-
- end
-
-
- class ValidationSetData < DatasetData
-
- #belongs_to :qsar_predictivity
- property :qsar_predictivity_id, Integer
- end
-
- class QsarPredictivity
- include DataMapper::Resource
-
- property :id, Serial
-
- property :validation_set_availability, String, :default => "No"
- property :validation_set_descriptors, String, :default => "No"
- property :validation_dependent_var_availability, String, :default => "No"
- property :validation_other_info, Text
- property :experimental_design, Text
- property :validation_predictivity, Text
- property :validation_assessment, Text
- property :validation_comments, Text
-
- has 1, :validation_set_data, :model => "ValidationSetData"
-
- def xml_infos
- [ SingleAttributeNodeProperty.new(:validation_set_availability, "answer"),
- AttributeNodeProperty.new(:validation_set_data),
- SingleAttributeNodeProperty.new(:validation_set_descriptors, "answer"),
- SingleAttributeNodeProperty.new(:validation_dependent_var_availability, "answer"),
- TextNodeProperty.new(:validation_other_info),
- TextNodeProperty.new(:experimental_design),
- TextNodeProperty.new(:validation_predictivity),
- TextNodeProperty.new(:validation_assessment),
- TextNodeProperty.new(:validation_comments),
- ]
- end
-
- belongs_to :qmrf_report
- end
-
- class QsarInterpretation
- include DataMapper::Resource
-
- property :id, Serial
- property :mechanistic_basis, Text
- property :mechanistic_basis_comments, Text
- property :mechanistic_basis_info, Text
-
- def xml_infos
- [ TextNodeProperty.new(:mechanistic_basis),
- TextNodeProperty.new(:mechanistic_basis_comments),
- TextNodeProperty.new(:mechanistic_basis_info),
- ]
- end
-
- belongs_to :qmrf_report
- end
-
- class Bibliography < Publication
-
- #belongs_to :qsar_miscellaneous
- property :qsar_miscellaneous_id, Integer
- end
-
- class Attachment
- include DataMapper::Resource
-
- property :id, Serial
- property :description, Text
- property :filetype, String
- property :url, String, :length => 255
-
- def xml_infos
- [ AttributeProperty.new(:description),
- AttributeProperty.new(:filetype),
- AttributeProperty.new(:url),
- ]
- end
-
- belongs_to :qsar_miscellaneous
- end
-
- class AttachmentTrainingData < Attachment
- property :type, String, :default => "AttachmentTrainingData"
- end
-
- class AttachmentValidationData < Attachment
- property :type, String, :default => "AttachmentValidationData"
- end
-
- class AttachmentDocument < Attachment
- property :type, String, :default => "AttachmentDocument"
- end
-
-
- class QsarMiscellaneous
- include DataMapper::Resource
-
- property :id, Serial
- property :comments, Text
-
- has n, :bibliography, Text
-
- # type is needed to distinguish between attachments
- # (the datamapper creates a table "Attachments", the relation is defined by QsarMisc.id and Attachment.id)
- has n, :attachment_training_data, :model => "AttachmentValidationData", :type => "AttachmentTrainingData"
- has n, :attachment_validation_data, :model => "AttachmentValidationData", :type => "AttachmentValidationData"
- has n, :attachment_documents, :type => "AttachmentDocument"
-
- def xml_infos
- [ TextNodeProperty.new(:comments),
- CatalogReference.new(:bibliography,"publications_catalog", "publication"),
- AttributeSubNodeListProperty.new(:attachment_training_data, :molecules, :attachments),
- AttributeSubNodeListProperty.new(:attachment_validation_data, :molecules, :attachments),
- AttributeSubNodeListProperty.new(:attachment_documents, :documents, :attachments),
- ]
- end
-
- belongs_to :qmrf_report
- end
-
- class QmrfSummary
- include DataMapper::Resource
-
- property :id, Serial
- property :qmrf_number, Text
- property :date_publication, Text
- property :keywords, Text
- property :summary_comments, Text
-
- def xml_infos
- [ TextNodeProperty.new(:qmrf_number),
- TextNodeProperty.new(:date_publication),
- TextNodeProperty.new(:keywords),
- TextNodeProperty.new(:summary_comments),
- ]
- end
-
- belongs_to :qmrf_report
- end
-
- class QmrfReport
- include DataMapper::Resource, REXML
-
- property :id, Serial
- property :model_uri, String, :length => 255
-
- CHAPTERS = [ :qsar_identifier, :qsar_general_information, :qsar_endpoint, :qsar_algorithm,
- :qsar_applicability_domain, :qsar_robustness, :qsar_predictivity, :qsar_interpretation,
- :qsar_miscellaneous, :qmrf_summary ]
-
- CHAPTERS.each{ |c,clazz| has 1, c }
-
- attr_accessor :subjectid
-
- after :save, :check_policy
- private
- def check_policy
- raise "no id" unless @id
- #raise "no subjectid" unless subjectid
- OpenTox::Authorization.check_policy(report_uri, subjectid)
- end
-
- public
- def to_yaml
- super(:methods => CHAPTERS)
- end
-
- def report_uri
- return $url_provider.url_for("/reach_report/QMRF/"+@id.to_s, :full).to_s
- end
-
- def self.from_xml(report, xml_data)
-
- raise "xml data size < 255, probably no qmrf report : '"+xml_data.to_s+"'" if xml_data.to_s.size<255
- doc = Document.new xml_data
-
- root = doc.elements["QMRF"]
- raise "no QMRF node found" unless root
- chapters = root.elements["QMRF_chapters"]
- raise "no chapter node found" unless chapters
- $catalogs_node = root.elements["Catalogs"]
- raise "catalogs not found" unless $catalogs_node
-
- CHAPTERS.each do |p| #, chapterClass|
- #unless report.send(p)
- report.send(p).destroy if report.send(p)
- c = report.association_class(p).new #chapterClass.new
- #c.save
- report.send(p.to_s+"=",c)
- #end
- report.send(p).from_xml( chapters.elements[p.xml_alias] )
- end
-
- #raise "already exists" if report.qsar_identifier
- #report.qsar_general_information.destroy if report.qsar_general_information
- #report.qsar_identifier.clear
- #report.qsar_general_information = QsarGeneralInformation.new
- #report.qsar_general_information.qmrf_date = "DateTime.now"
- #report.qsar_general_information.model_authors << ModelAuthor.new
- #report.qsar_general_information.qmrf_authors << QmrfAuthor.new
-
- #report.qsar_identifier = QsarIdentifier.new unless report.qsar_identifier
- #report.qsar_identifier.from_xml( chapters.elements[:qsar_identifier.xml_alias] )
-
- #report.qsar_general_information = QsarGeneralInformation.new unless report.qsar_general_information
- #report.qsar_general_information.from_xml( chapters.elements[:qsar_general_information.xml_alias] )
-
-
- #QsarGeneralInformation.from_xml( report.qsar_general_information, chapters.elements["qsar_general_information".xml_alias] )
-
- #puts "set qsar_identifier to "+report.qsar_identifier.class.to_s
-
-# begin
- report.save
-# rescue DataObjects::SQLError => e
-# puts e.message
-# exit
-# rescue DataObjects::DataError => e
-# puts e.message
-# exit
-# rescue DataMapper::SaveFailureError => e
-# puts e.resource.errors.inspect
-# exit
-# end
-
-# puts "XXXXXXXxxxxx"
-#
-# puts "1"
-# puts report.qsar_miscellaneous.attachment_training_data.inspect
-# puts "2"
-# puts report.qsar_miscellaneous.attachment_validation_data.inspect
-# puts "3"
-# puts report.qsar_miscellaneous.attachment_documents.inspect
-#
-#
-# r = QmrfReport.get(report.id)
-#
-# puts "1"
-# puts r.qsar_miscellaneous.attachment_training_data.inspect
-# puts "2"
-# puts r.qsar_miscellaneous.attachment_validation_data.inspect
-# puts "3"
-# puts r.qsar_miscellaneous.attachment_documents.inspect
-#
-# exit
-
-
- end
-
- def to_xml
- #puts "now qsar_identifier is "+self.qsar_identifier.class.to_s
-
- doc = Document.new
- decl = XMLDecl.new
- decl.encoding = "UTF-8"
- doc << decl
- type = DocType.new('QMRF SYSTEM "http://ambit.sourceforge.net/qmrf/jws/qmrf.dtd"')
- doc << type
-
- root = Element.new("QMRF")
- root.add_attributes( "version" => 1.2, "schema_version" => 1.0, "name" => "(Q)SAR Model Reporting Format",
- "author" => "Joint Research Centre, European Commission", "contact" => "Joint Research Centre, European Commission",
- "date" => "July 2007", "email" => "qsardb@jrc.it", "url" => "http://ecb.jrc.ec.europa.eu/qsar/" )
-
- catalogs = Element.new("Catalogs")
- [ "software_catalog", "algorithms_catalog", "descriptors_catalog",
- "endpoints_catalog", "publications_catalog", "authors_catalog"].each do |c|
- catalogs << Element.new(c)
- end
- $catalogs_node = catalogs
-
- chapters = Element.new("QMRF_chapters")
- chapter_count = 1
-
- CHAPTERS.each do |p|
- node = Element.new( p.xml_alias )
- node.add_attribute("chapter",chapter_count)
- self.send(p.to_s+"=", self.association_class(p).new) unless self.send(p) # create empy chapter, as xml must be complete
- self.send(p).to_XML( node, chapter_count )
- chapters << node
- chapter_count += 1
- end
-
-# qsar_identifier_node = Element.new(:qsar_identifier.xml_alias)
-# self.qsar_identifier.to_XML( qsar_identifier_node )
-# chapters << qsar_identifier_node
-#
-# qsar_general_information_node = Element.new(:qsar_general_information.xml_alias)
-# self.qsar_general_information.to_XML( qsar_general_information_node )
-# chapters << qsar_general_information_node
-
-
-
-# [ @qsar_identifier, @qsar_general_information, @qsar_endpoint ].each do |c|
-# n = c.to_xml
-# raise "no node "+n.to_s+" "+n.class.to_s unless n.is_a?(Element)
-# chapters << n
-# end
-
- root << chapters
- root << catalogs
- doc << root
-
- s = ""
- doc.write(s, 2, false, false)
- return s
-
- end
- end
-
-#Profile2.auto_upgrade!
-
-# class QmrfReport < ActiveRecord::Base
-#
-# alias_attribute :date, :created_at
-#
-# QmrfProperties.serialized_properties.each do |p|
-# serialize p
-# end
-#
-# def type
-# "QMRF"
-# end
-#
-# def report_uri
-# ReachReports.get_uri(self)
-# end
-#
-# def get_content
-# hash = {}
-# [ :model_uri, :date ].each{ |p| hash[p] = self.send(p) }
-# QmrfProperties.properties.each{ |p| hash[p] = self.send(p) }
-# return hash
-# end
-# end
-#
-#
-# class QprfReport < ActiveRecord::Base
-#
-# alias_attribute :date, :created_at
-#
-# def report_uri
-# ReachReports.get_uri(self)
-# end
-#
-# def type
-# "QPRF"
-# end
-# end
-
- mysql_lite_retry do
- [ QsarSoftware, QsarIdentifier, QmrfAuthor, ModelAuthor, Reference, QsarGeneralInformation, ModelEndpoint, QsarEndpoint, AlgorithmExplicit,
- AlgorithmsDescriptor, DescriptorsGenerationSoftware, QsarAlgorithm, AppDomainSoftware, QsarApplicabilityDomain, TrainingSetData,
- QsarRobustness, ValidationSetData, QsarPredictivity, QsarInterpretation, Bibliography, AttachmentTrainingData, AttachmentValidationData,
- AttachmentDocument, QsarMiscellaneous, QmrfSummary, QmrfReport ].each do |model|
- model.auto_upgrade!
- model.raise_on_save_failure = true
- end
-
- end
-
-end \ No newline at end of file
diff --git a/reach_reports/reach_service.rb b/reach_reports/reach_service.rb
deleted file mode 100755
index 5dd68e1..0000000
--- a/reach_reports/reach_service.rb
+++ /dev/null
@@ -1,328 +0,0 @@
-
-class Array
-
- def to_html
- return "" unless size>0
- s = "<html>\n<head>\n</head>\n<body>\n"
- s += join(" <br>\n")
- s += "</body>\n</html>\n"
- return s
- end
-end
-
-module ReachReports
-
- def self.list_reports(type, model_uri=nil)
- case type
- when /(?i)QMRF/
- params = {}
- params[:model_uri]=model_uri if model_uri
- ReachReports::QmrfReport.all(params).collect{ |r| r.report_uri }.join("\n")+"\n"
- when /(?i)QPRF/
- ReachReports::QprfReport.all.collect{ |r| r.report_uri }.join("\n")+"\n"
- end
- end
-
- def self.create_report( type, params, subjectid, xml_data=nil )
-
- case type
- when /(?i)QMRF/
- if params[:model_uri]
- task = OpenTox::Task.create( "Create "+type+" report",
- $url_provider.url_for("/reach_report/"+type, :full) ) do |task| #, params
-
- report = ReachReports::QmrfReport.new :model_uri => params[:model_uri]
- report.subjectid = subjectid
- build_qmrf_report(report, task)
- report.report_uri
- end
- result_uri = task.uri
- elsif xml_data and (input = xml_data.read).to_s.size>0
- report = ReachReports::QmrfReport.new
- report.subjectid = subjectid
- ReachReports::QmrfReport.from_xml(report,input)
- result_uri = report.report_uri
- else
- raise OpenTox::BadRequestError.new "illegal parameters for qmrf-report creation, either\n"+
- "* give 'model_uri' as param\n"+
- "* provide xml file\n"+
- "params given: "+params.inspect
- end
- when /(?i)QPRF/
- raise OpenTox::BadRequestError.new "qprf report creation not yet implemented"
- if params[:compound_uri]
- #report = ReachReports::QprfReport.new :compound_uri => params[:compound_uri]
- else
- raise OpenTox::BadRequestError.new "illegal parameters for qprf-report, use either\n"+
- "* compound-uri\n"+
- "params given: "+params.inspect
- end
- end
- result_uri
- end
-
- def self.build_qmrf_report(r, task=nil)
-
- #puts r.model_uri
- model = OpenTox::Model::Generic.find(r.model_uri, r.subjectid)
- feature_type = model.feature_type(r.subjectid)
-
- # chapter 1
- r.qsar_identifier = QsarIdentifier.new
- r.qsar_identifier.qsar_title = model.metadata[DC.title]
- # TODO QSAR_models -> sparql same endpoint
- r.qsar_identifier.qsar_software << QsarSoftware.new( :url => model.uri,
- :name => model.metadata[DC.title], :contact => model.metadata[DC.creator] )
- algorithm = OpenTox::Algorithm::Generic.find(model.metadata[OT.algorithm], r.subjectid) if model.metadata[OT.algorithm]
- r.qsar_identifier.qsar_software << QsarSoftware.new( :url => algorithm.uri, :name => algorithm.metadata[DC.title] )
- task.progress(10) if task
-
- #chpater 2
- r.qsar_general_information = QsarGeneralInformation.new
- r.qsar_general_information.qmrf_date = DateTime.now.to_s
- # EMPTY: qmrf_authors, qmrf_date_revision, qmrf_revision
- # TODO: model_authors ?
- r.qsar_general_information.model_date = model.metadata[DC.date].to_s
- # TODO: references?
- # EMPTY: info_availablity
- # TODO: related_models = find qmrf reports for QSAR_models
- task.progress(20) if task
-
- # chapter 3
- # TODO "model_species" ?
- r.qsar_endpoint = QsarEndpoint.new
- model.metadata[OT.predictedVariables].each do |p|
- r.qsar_endpoint.model_endpoint << ModelEndpoint.new( :name => p )
- end if model.metadata[OT.predictedVariables]
- # TODO "endpoint_comments" => "3.3", "endpoint_units" => "3.4",
- r.qsar_endpoint.endpoint_variable = model.metadata[OT.dependentVariables] if model.metadata[OT.dependentVariables]
- # TODO "endpoint_protocol" => "3.6", "endpoint_data_quality" => "3.7",
- task.progress(30) if task
-
- # chapter 4
- # TODO algorithm_type (='type of model')
- # TODO algorithm_explicit.equation
- # TODO algorithm_explicit.algorithms_catalog
- # TODO algorithms_descriptors, descriptors_selection, descriptors_generation, descriptors_generation_software, descriptors_chemicals_ratio
- task.progress(40) if task
-
- # chapter 5
- # TODO app_domain_description, app_domain_method, app_domain_software, applicability_limits
-
- #training_dataset = model.trainingDataset ? OpenTox::Dataset.find(model.trainingDataset+"/metadata") : nil
- if ( OpenTox::Dataset.exist?(model.metadata[OT.trainingDataset], r.subjectid) )
- training_dataset = OpenTox::Dataset.new( model.metadata[OT.trainingDataset], r.subjectid )
- training_dataset.load_metadata( r.subjectid )
- else
- training_dataset = nil
- LOGGER.warn "build qmrf: training_dataset not found "+model.metadata[OT.trainingDataset].to_s
- end
- task.progress(50) if task
-
- # chapter 6
- r.qsar_robustness = QsarRobustness.new
- if training_dataset
- r.qsar_robustness.training_set_availability = "Yes"
- r.qsar_robustness.training_set_data = TrainingSetData.new(:chemname => "Yes", :cas => "Yes",
- :smiles => "Yes", :inchi => "Yes", :mol => "Yes", :formula => "Yes")
- end
-
- #TODO "training_set_data" => "6.2",
- # "training_set_descriptors" => "6.3",
- # "dependent_var_availability" => "6.4", "other_info" => "6.5", "preprocessing" => "6.6", "goodness_of_fit" => "6.7",
- # "loo" => "6.8",
-
- val_datasets = []
-
- if algorithm
- cvs = Validation::Crossvalidation.find_all_uniq({:algorithm_uri => algorithm.uri, :finished => true},r.subjectid)
- # PENDING: cv classification/regression hack
- cvs = cvs.delete_if do |cv|
- #val = Validation::Validation.first( :all, :conditions => { :crossvalidation_id => cv.id } )
- val = Validation::Validation.find( :crossvalidation_id => cv.id ).first
- raise "should not happen: no validations found for crossvalidation "+cv.id.to_s unless val
- (val.classification_statistics!=nil) != (feature_type=="classification")
- end
-
- lmo = [ "found "+cvs.size.to_s+" crossvalidation/s for algorithm '"+algorithm.uri.to_s+"'" ]
- if cvs.size>0
- cvs_same_data = []
- cvs_other_data = []
- cvs.each do |cv|
- if cv.dataset_uri == model.metadata[OT.trainingDataset]
- cvs_same_data << cv
- else
- cvs_other_data << cv
- end
- end
- lmo << cvs_same_data.size.to_s+" crossvalidations/s where performed on the training dataset of the model ("+
- model.metadata[OT.trainingDataset].to_s+")"
- lmo << cvs_other_data.size.to_s+" crossvalidations/s where performed on the other datasets"
- lmo << ""
-
- {cvs_same_data => "training dataset", cvs_other_data => "other datasets"}.each do |cvs,desc|
- next if cvs.size==0
- lmo << "crossvalidation/s on "+desc
- cvs.each do |cv|
- begin
- lmo << "crossvalidation: "+cv.crossvalidation_uri
- lmo << "dataset (see 9.3 Validation data): "+cv.dataset_uri
- val_datasets << cv.dataset_uri
- lmo << "settings: num-folds="+cv.num_folds.to_s+", random-seed="+cv.random_seed.to_s+", stratified:"+cv.stratified.to_s
-
- val = YAML.load( OpenTox::RestClientWrapper.get(File.join(cv.crossvalidation_uri,"statistics"),{:subjectid => r.subjectid}) )
- case feature_type
- when "classification"
- lmo << "percent_correct: "+val[OT.classificationStatistics][OT.percentCorrect].to_s
- lmo << "weighted AUC: "+val[OT.classificationStatistics][OT.weightedAreaUnderRoc].to_s
- when "regression"
- lmo << "root_mean_squared_error: "+val[OT.regressionStatistics][OT.rootMeanSquaredError].to_s
- lmo << "r_square "+val[OT.regressionStatistics][OT.rSquare].to_s
- end
- reports = OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"],
- "report/crossvalidation?crossvalidation_uris="+cv.crossvalidation_uri),{:subjectid => r.subjectid})
- if reports and reports.chomp.size>0
- lmo << "for more info see report: "+reports.split("\n")[0]
- else
- lmo << "for more info see report: not yet created for '"+cv.crossvalidation_uri+"'"
- end
- rescue => ex
- LOGGER.warn "could not add cv "+cv.crossvalidation_uri+" : "+ex.message
- end
- end
- lmo << ""
- end
- end
- else
- lmo = [ "no prediction algortihm for model found, crossvalidation not possible" ]
- end
- r.qsar_robustness.lmo = lmo.to_html
- # "lmo" => "6.9", "yscrambling" => "6.10", "bootstrap" => "6.11", "other_statistics" => "6.12",
-
- LOGGER.debug "looking for validations with "+{:model_uri => model.uri}.inspect
- #vals = Lib::Validation.find(:all, :conditions => {:model_uri => model.uri})
- vals = Validation::Validation.find({:model_uri => model.uri})
- uniq_vals = []
- vals.each do |val|
- match = false
- uniq_vals.each do |val2|
- if val.test_dataset_uri == val2.test_dataset_uri
- match = true
- break
- end
- end
- uniq_vals << val unless match
- end
-
- r.qsar_predictivity = QsarPredictivity.new
- if uniq_vals.size > 0
- r.qsar_predictivity.validation_set_availability = "Yes"
- r.qsar_predictivity.validation_set_data = ValidationSetData.new(:chemname => "Yes", :cas => "Yes",
- :smiles => "Yes", :inchi => "Yes", :mol => "Yes", :formula => "Yes")
-
- v = [ "found '"+uniq_vals.size.to_s+"' test-set validations of model '"+model.uri+"'" ]
- v << ""
- uniq_vals.each do |validation|
- v << "validation: "+validation.validation_uri
- v << "dataset (see 9.3 Validation data): "+validation.test_dataset_uri
- val_datasets << validation.test_dataset_uri
- case feature_type
- when "classification"
- v << "percent_correct: "+validation.classification_statistics[:percent_correct].to_s
- v << "average AUC: "+validation.classification_statistics[:average_area_under_roc].to_s
- when "regression"
- v << "root_mean_squared_error: "+validation.regression_statistics[:root_mean_squared_error].to_s
- v << "r_square "+validation.regression_statistics[:r_square].to_s
- end
- report = OpenTox::ValidationReport.find_for_validation(validation.validation_uri,r.subjectid)
- #reports = OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"],
- # "report/validation?validation_uris="+validation.validation_uri),{:subjectid => r.subjectid})
- if report
- v << "for more info see report: "+report.uri
- else
- v << "for more info see report: not yet created for '"+validation.validation_uri+"'"
- end
- v << ""
- end
- else
- v = [ "no validation for model '"+model.uri+"' found" ]
- end
- r.qsar_predictivity.validation_predictivity = v.to_html
- task.progress(60) if task
-
- # chapter 7
- # "validation_set_availability" => "7.1", "validation_set_data" => "7.2", "validation_set_descriptors" => "7.3",
- # "validation_dependent_var_availability" => "7.4", "validation_other_info" => "7.5", "experimental_design" => "7.6",
- # "validation_predictivity" => "7.7", "validation_assessment" => "7.8", "validation_comments" => "7.9",
- task.progress(70) if task
-
- # chapter 8
- # "mechanistic_basis" => "8.1", "mechanistic_basis_comments" => "8.2", "mechanistic_basis_info" => "8.3",
- task.progress(80) if task
-
- # chapter 9
- # "comments" => "9.1", "bibliography" => "9.2", "attachments" => "9.3",
-
- r.qsar_miscellaneous = QsarMiscellaneous.new
-
- r.qsar_miscellaneous.attachment_training_data << AttachmentTrainingData.new(
- { :description => training_dataset.title,
- :filetype => "owl-dl",
- :url => training_dataset.uri} ) if training_dataset
-
- val_datasets.each do |data_uri|
- if OpenTox::Dataset.exist?(data_uri, r.subjectid)
- d = OpenTox::Dataset.new(data_uri, r.subjectid)
- d.load_metadata( r.subjectid)
- r.qsar_miscellaneous.attachment_validation_data << AttachmentValidationData.new(
- { :description => d.title,
- :filetype => "owl-dl",
- :url => data_uri} )
- end
- end
- task.progress(90) if task
-
- mysql_lite_retry do
- r.save
- end
- task.progress(100) if task
- end
-
-# def self.get_report_content(type, id, *keys)
-#
-# report_content = get_report(type, id).get_content
-# keys.each do |k|
-# $sinatra.raise OpenTox::BadRequestError.new type+" unknown report property '#{key}'" unless report_content.is_a?(Hash) and report_content.has_key?(k)
-# report_content = report_content[k]
-# end
-# report_content
-# end
-
- def self.get_report(type, id)
- report = nil
- mysql_lite_retry(3) do
- case type
- when /(?i)QMRF/
- report = ReachReports::QmrfReport.get(id)
- when /(?i)QPRF/
- report = ReachReports::QprfReport.get(id)
- end
- raise OpenTox::NotFoundError.new type+" report with id '#{id}' not found." unless report
- end
- return report
- end
-
- def self.delete_report(type, id, subjectid=nil)
-
- case type
- when /(?i)QMRF/
- report = ReachReports::QmrfReport.get(id)
- when /(?i)QPRF/
- report = ReachReports::QprfReport.get(id)
- end
- raise OpenTox::NotFoundError.new type+" report with id '#{id}' not found." unless report
- OpenTox::Authorization.delete_policies_from_uri(report.report_uri, subjectid) if subjectid
- return report.destroy
- end
-
-end
diff --git a/reach_reports/reach_test.rb b/reach_reports/reach_test.rb
deleted file mode 100755
index 43aec28..0000000
--- a/reach_reports/reach_test.rb
+++ /dev/null
@@ -1,284 +0,0 @@
-
-require "rubygems"
-require "sinatra"
-before {
- request.env['HTTP_HOST']="local-ot/validation"
- request.env["REQUEST_URI"]=request.env["PATH_INFO"]
-}
-
-require "uri"
-require "yaml"
-ENV['RACK_ENV'] = 'test'
-require 'application.rb'
-require 'test/unit'
-require 'rack/test'
-require 'lib/test_util.rb'
-require 'test/test_examples.rb'
-
-LOGGER = OTLogger.new(STDOUT)
-LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
-LOGGER.formatter = Logger::Formatter.new
-
-if AA_SERVER
- #TEST_USER = "mgtest"
- #TEST_PW = "mgpasswd"
- TEST_USER = "guest"
- TEST_PW = "guest"
- SUBJECTID = OpenTox::Authorization.authenticate(TEST_USER,TEST_PW)
- raise "could not log in" unless SUBJECTID
- puts "logged in: "+SUBJECTID.to_s
-else
- puts "AA disabled"
- SUBJECTID = nil
-end
-
-#Rack::Test::DEFAULT_HOST = "local-ot/validation"
-module Sinatra
- module UrlForHelper
- BASE = "http://local-ot/validation"
- def url_for url_fragment, mode=:path_only
- case mode
- when :path_only
- raise "not impl"
- when :full
- end
- "#{BASE}#{url_fragment}"
- end
- end
- set :raise_errors, false
- set :show_exceptions, false
-end
-
-
-#DataMapper::Model.raise_on_save_failure = true
-#
-#class TestResourceX
-# include DataMapper::Resource
-#
-# property :id, Serial
-#
-# has 1, :test_resource
-#end
-#
-#class DataMapper::Associations::ManyToOne::Relationship
-# def get_parent_model
-# @parent_model
-# end
-#end
-#
-#class TestResource
-# include DataMapper::Resource
-#
-# property :id, Serial
-# property :time, DateTime
-# property :body, Text
-#
-# def self.info
-# relationships.each do |k,v|
-# puts k
-# puts v.inspect
-# puts v.get_parent_model
-#
-# end
-# end
-# #validates_format_of :time
-# #validates_length_of :body, :minimum => 1000
-#
-# belongs_to :test_resource_x
-#end
-#
-#TestResourceX.auto_upgrade!
-#TestResource.auto_upgrade!
-
-class ReachTest < Test::Unit::TestCase
- include Rack::Test::Methods
- include Lib::TestUtil
-
- def app
- Sinatra::Application
- end
-
- def test_it
-
- begin
-
- # delete '/reach_report/QMRF/3'
- # puts last_response.body
-
- #exit
-# testResource = TestResource.new
-#
-# TestResource.info
-# exit
-
-# p = nil
-# #puts TestResource.properties.inspect
-# TestResource.properties.each do |pp|
-# p = pp if pp.name==:time
-# end
-# #puts p
-# val = "no time" #DateTime.new
-# testResource.time = val
-# #puts p.valid?(val)
-#
-# #puts "test restource: "+testResource.valid?.to_s
-#
-# #puts testResource.time.to_s + " " + testResource.time.class.to_s
-# begin
-# testResource.save
-# rescue DataMapper::SaveFailureError => e
-# puts e.message
-# puts e.resource.errors.inspect
-# end
-# exit
-
- #$test_case = self
-
-# #file = File.new("qmrf-report.xml")
-# file = File.new("/home/martin/win/home/test2.xml")
-# raise "File not found: "+file.path.to_s unless File.exist?(file.path)
-# data = File.read(file.path)
-# #puts "data found "+data.to_s[0..1000]
-# puts OpenTox::RestClientWrapper.post("http://local-ot/validation/reach_report/qmrf/20",{:content_type => "application/qmrf-xml"},data).to_s.chomp
-
-# post "/reach_report/qmrf/8"
-# puts last_response.body
-
- #model_uri = "http://ambit.uni-plovdiv.bg:8080/ambit2/model/173393"
-
- #model_uri = "http://local-ot/majority/class/model/58"
-
-
- #model_uri = "http://local-ot/model/104"
- model_uri = "http://local-ot/model/72"
-
-
-# m = OpenTox::Model::Generic.find(model_uri)
-# puts m.metadata[OT.algorithm] if m
-# a = OpenTox::Algorithm::Generic.find(m.metadata[OT.algorithm])
-# puts a.metadata.inspect
-# exit
-
- puts SUBJECTID
-
-# model_uri = "http://local-ot/model/1"
- #http://local-ot/majority/class/model/15
- #model_uri = "http://local-ot/majority/class/model/15"
- # model_uri = "http://local-ot/majority/class/model/91"
- #model_uri = "http://apps.ideaconsult.net:8080/ambit2/model/2"
- post '/reach_report/qmrf',{:model_uri=>model_uri, :subjectid => SUBJECTID} #http://local-ot/model/1"
- ##post '/reach_report/qprf',:compound_uri=>"http://local-ot/compound/XYZ"
- uri = last_response.body
- puts "task: "+uri.to_s
- uri = Lib::TestUtil.wait_for_task(uri)
- if uri
- id = uri.split("/")[-1]
- puts uri
- end
-
-# id = "8"
-
- #get '/reach_report/qmrf'
- #puts last_response.body
-
-# get '/reach_report/qmrf/'+id.to_s,nil,'HTTP_ACCEPT'=>"application/x-yaml"
-# puts "YAML"
-# puts last_response.body
-
-# get '/reach_report/qmrf/'+id.to_s,nil,'HTTP_ACCEPT'=>"application/rdf+xml"
-# puts "RDF"
-# puts last_response.body
-
- #get '/reach_report/qmrf/'+id,nil,'HTTP_ACCEPT' => "application/qmrf-xml"
- #puts "XML"
- #puts last_response.body
-
-
- #r = ReachReports::QmrfReport.find_like( :QSAR_title => "Hamster")
- #puts r.collect{|rr| "report with id:"+rr.id.to_s}.inspect
-
- #File.new("/home/martin/tmp/qmr_rep_del_me.xml","w").puts last_response.body
- #File.new("/home/martin/win/home/qmr_rep_del_me.xml","w").puts last_response.body
- #File.new("/home/martin/info_home/.public_html/qmr_rep_del_me.xml","w").puts last_response.body
-
- rescue => ex
- rep = OpenTox::ErrorReport.create(ex, "")
- puts rep.to_yaml
- end
-
-
- end
-end
-
-
-# query = <<EOF
-#PREFIX ot:<http://www.opentox.org/api/1.1#>
-#PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
-#select ?model
-#where {
-#?model rdf:type ot:Model
-#}
-#EOF
-# puts OpenTox::RestClientWrapper.post("http://apps.ideaconsult.net:8080/ontology/",{:accept => "application/rdf+xml", :query => query})
-# exit
-
-#class Person
-# include DataMapper::Resource
-#
-# property :id, Serial
-#
-# has 1, :profile
-# has 1, :profile2
-# end
-#
-# class Profile
-# include DataMapper::Resource
-#
-# property :id, Serial
-# property :val, Text
-#
-# belongs_to :person
-# end
-#
-# class Profile2
-# include DataMapper::Resource
-#
-# property :id, Serial
-# property :val, Text
-#
-# belongs_to :person
-# end
-#
-#Person.auto_upgrade!
-#Profile.auto_upgrade!
-#Profile2.auto_upgrade!
-#
-# A.auto_upgrade!
-# ValTest.auto_upgrade!
- #A.auto_migrate!
- #ValTest.auto_migrate!
-
-# class ReachTest < Test::Unit::TestCase
-# include Rack::Test::Methods
-# include Lib::TestUtil
-#
-#
-# def app
-# Sinatra::Application
-# end
-#
-# def test_datamapper
-#
-# # Assigning a resource to a one-to-one relationship
-# puts Person.all.collect{|v| v.id}.inspect
-#
-# person = Person.create
-# person.profile = Profile.new
-# person.profile2 = Profile2.new
-# person.profile2.val = "bla"
-# person.save
-#
-# p = Person.get(11)
-## puts p.profile2
-# puts p.profile2.val
-
diff --git a/report/environment.rb b/report/environment.rb
index 7addc45..58c3b2b 100755
--- a/report/environment.rb
+++ b/report/environment.rb
@@ -1,9 +1,8 @@
['rubygems', 'logger', 'fileutils', 'sinatra', 'sinatra/url_for', 'rest_client',
'yaml', 'fileutils', 'mime/types', 'abbrev',
- 'rexml/document', 'ruby-plot', 'opentox-ruby' ].each do |g|
+ 'rexml/document', 'ruby-plot' ].each do |g|
require g
end
-gem 'ruby-plot', "~>0.6.0"
module Reports
@@ -21,24 +20,24 @@ module Reports
end
-require "lib/ot_predictions.rb"
-require "lib/ohm_util.rb"
-
-require "report/plot_factory.rb"
-require "report/xml_report.rb"
-require "report/xml_report_util.rb"
-require "report/report_persistance.rb"
-require "report/report_content.rb"
-require "report/report_factory.rb"
-require "report/report_service.rb"
-require "report/report_format.rb"
-require "report/validation_access.rb"
-require "report/validation_data.rb"
-require "report/util.rb"
-require "report/statistical_test.rb"
-
-ICON_ERROR = File.join(CONFIG[:services]["opentox-validation"],"resources/error.png")
-ICON_OK = File.join(CONFIG[:services]["opentox-validation"],"resources/ok.png")
+require "./lib/ot_predictions.rb"
+require "./lib/ohm_util.rb"
+
+require "./report/plot_factory.rb"
+require "./report/xml_report.rb"
+require "./report/xml_report_util.rb"
+require "./report/report_persistance.rb"
+require "./report/report_content.rb"
+require "./report/report_factory.rb"
+require "./report/report_service.rb"
+require "./report/report_format.rb"
+require "./report/validation_access.rb"
+require "./report/validation_data.rb"
+require "./report/util.rb"
+require "./report/statistical_test.rb"
+
+ICON_ERROR = File.join($validation[:uri],"resources/error.png")
+ICON_OK = File.join($validation[:uri],"resources/ok.png")
diff --git a/report/plot_factory.rb b/report/plot_factory.rb
index 6e90dbc..6c90594 100644
--- a/report/plot_factory.rb
+++ b/report/plot_factory.rb
@@ -106,14 +106,13 @@ module Reports
train = []
test = []
validation_set.validations.each do |v|
- [[v.test_dataset_uri, test, v.test_target_dataset_uri],
- [v.training_dataset_uri, train, v.training_dataset_uri]].each do |uri,array,uri2|
+ [[v.test_dataset_uri, test],
+ [v.training_dataset_uri, train]].each do |uri,array|
d = Lib::DatasetCache.find(uri, validation_set.validations[0].subjectid)
- d2 = Lib::DatasetCache.find((uri2 ? uri2 : uri), validation_set.validations[0].subjectid)
d.compounds.each do |c|
- d2.data_entries[c][v.prediction_feature].each do |val|
+ d.data_entries[c][v.prediction_feature].each do |val|
array << val
- end if d2.data_entries[c] and d2.data_entries[c][v.prediction_feature]
+ end if d.data_entries[c] and d.data_entries[c][v.prediction_feature]
end
end
end
@@ -671,8 +670,8 @@ module Reports
end
end
-#require "rubygems"
-#require "ruby-plot"
+#require "./rubygems"
+#require "./ruby-plot"
###Reports::PlotFactory::demo_ranking_plot
#class Array
# def sum
diff --git a/report/report_application.rb b/report/report_application.rb
index 5fec6d1..f7528b6 100755
--- a/report/report_application.rb
+++ b/report/report_application.rb
@@ -1,4 +1,4 @@
-require "report/environment.rb"
+require "./report/environment.rb"
def perform
@@report_service = Reports::ReportService.instance( url_for("/report", :full) ) unless defined?@@report_service
diff --git a/report/report_format.rb b/report/report_format.rb
index d64bf57..d216782 100644
--- a/report/report_format.rb
+++ b/report/report_format.rb
@@ -4,7 +4,7 @@ ENV['JAVA_HOME'] = "/usr/bin" unless ENV['JAVA_HOME']
ENV['PATH'] = ENV['JAVA_HOME']+":"+ENV['PATH'] unless ENV['PATH'].split(":").index(ENV['JAVA_HOME'])
ENV['SAXON_JAR'] = "saxonhe9-2-0-3j/saxon9he.jar" unless ENV['SAXON_JAR']
-OT_STYLESHEET = File.join(CONFIG[:services]["opentox-validation"],"resources/simple_ot_stylesheet.css")
+OT_STYLESHEET = File.join($validation[:uri],"resources/simple_ot_stylesheet.css")
# = Reports::ReportFormat
#
diff --git a/report/report_persistance.rb b/report/report_persistance.rb
index ccdebad..447ea16 100755
--- a/report/report_persistance.rb
+++ b/report/report_persistance.rb
@@ -1,6 +1,6 @@
REPORT_DIR = File.join(Dir.pwd,'/reports')
-require "lib/format_util.rb"
+require "./lib/format_util.rb"
# = Reports::ReportPersistance
#
diff --git a/report/report_test.rb b/report/report_test.rb
index 571d6d8..6989896 100755
--- a/report/report_test.rb
+++ b/report/report_test.rb
@@ -1,9 +1,9 @@
require "fileutils"
ENV['RACK_ENV'] = 'test'
-require 'report/report_application.rb'
+require './report/report_application.rb'
require 'test/unit'
require 'rack/test'
-require "lib/test_util.rb"
+require "./lib/test_util.rb"
LOGGER = Logger.new(STDOUT)
LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
@@ -129,12 +129,12 @@ end
#class Reports::ReportServiceTest < Test::Unit::TestCase
# include Lib::TestUtil
#
-# WS_VAL = CONFIG[:services]["opentox-validation"]
-# WS_DATA=CONFIG[:services]["opentox-dataset"]
+# WS_VAL = $validation[:uri]
+# WS_DATA=$dataset[:uri]
# FILE=File.new("data/hamster_carcinogenicity.owl","r")
#
-# WS_CLASS_ALG=File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
-# WS_FEATURE_ALG=File.join(CONFIG[:services]["opentox-algorithm"],"fminer")
+# WS_CLASS_ALG=File.join($algorithm[:uri],"lazar")
+# WS_FEATURE_ALG=File.join($algorithm[:uri],"fminer")
#
# #WS_CLASS_ALG_2="local-ot:4008/algorithm"
# #WS_FEATURE_ALG_2=nil
diff --git a/report/statistical_test.rb b/report/statistical_test.rb
index da46f6b..4b65f0a 100644
--- a/report/statistical_test.rb
+++ b/report/statistical_test.rb
@@ -1,5 +1,5 @@
-#require "rubygems"
-#require "rinruby"
+#require "./rubygems"
+#require "./rinruby"
module Reports
diff --git a/report/validation_access.rb b/report/validation_access.rb
index e2a3978..a14b397 100755
--- a/report/validation_access.rb
+++ b/report/validation_access.rb
@@ -1,4 +1,4 @@
-require "lib/validation_db.rb"
+require "./lib/validation_db.rb"
# = Reports::ValidationDB
#
@@ -187,8 +187,8 @@ class Reports::ValidationDB
def get_predictions(validation, filter_params, subjectid, task)
# we need compound info, cannot reuse stored prediction data
data = Lib::PredictionData.create( validation.feature_type, validation.test_dataset_uri,
- validation.test_target_dataset_uri, validation.prediction_feature, validation.prediction_dataset_uri,
- validation.predicted_variable, validation.predicted_confidence, subjectid, OpenTox::SubTask.create(task, 0, 80 ) )
+ validation.prediction_feature, validation.prediction_dataset_uri, validation.predicted_variable,
+ validation.predicted_confidence, subjectid, OpenTox::SubTask.create(task, 0, 80 ) )
data = Lib::PredictionData.filter_data( data.data, data.compounds,
filter_params[:min_confidence], filter_params[:min_num_predictions], filter_params[:max_num_predictions] ) if filter_params!=nil
task.progress(100) if task
@@ -197,14 +197,13 @@ class Reports::ValidationDB
def get_accept_values( validation, subjectid=nil )
# PENDING So far, one has to load the whole dataset to get the accept_value from ambit
- test_target_datasets = validation.test_target_dataset_uri
- test_target_datasets = validation.test_dataset_uri unless test_target_datasets
+ test_datasets = validation.test_dataset_uri
res = nil
- test_target_datasets.split(";").each do |test_target_dataset|
- d = Lib::DatasetCache.find( test_target_dataset, subjectid )
- raise "cannot get test target dataset for accept values, dataset: "+test_target_dataset.to_s unless d
+ test_datasets.split(";").each do |test_dataset|
+ d = Lib::DatasetCache.find( test_dataset, subjectid )
+ raise "cannot get test target dataset for accept values, dataset: "+test_dataset.to_s unless d
accept_values = d.accept_values(validation.prediction_feature)
- raise "cannot get accept values from dataset "+test_target_dataset.to_s+" for feature "+
+ raise "cannot get accept values from dataset "+test_dataset.to_s+" for feature "+
validation.prediction_feature+":\n"+d.features[validation.prediction_feature].to_yaml unless accept_values!=nil
raise "different accept values" if res && res!=accept_values
res = accept_values
diff --git a/report/xml_report.rb b/report/xml_report.rb
index 5be5fdc..f610677 100755
--- a/report/xml_report.rb
+++ b/report/xml_report.rb
@@ -2,7 +2,7 @@
# require g
#end
-require "report/xml_report_util.rb"
+require "./report/xml_report_util.rb"
ENV['DOCBOOK_DIRECTORY'] = "docbook-xml-4.5" unless ENV['DOCBOOK_DIRECTORY']
ENV['REPORT_DTD'] = "docbookx.dtd" unless ENV['REPORT_DTD']
diff --git a/test/test_examples.rb b/test/test_examples.rb
index 2b95cf2..813d0b0 100755
--- a/test/test_examples.rb
+++ b/test/test_examples.rb
@@ -1,5 +1,5 @@
-require 'test/test_examples_util.rb'
+require './test/test_examples_util.rb'
class Class
def humanize
@@ -26,8 +26,8 @@ module ValidationExamples
class LazarIrisCrossvalidation < IrisCrossvalidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer")
super
end
end
@@ -43,8 +43,8 @@ module ValidationExamples
class LazarIrisSplit < IrisSplit
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer")
super
end
end
@@ -68,8 +68,8 @@ module ValidationExamples
class LazarEPAFHMSplit < EPAFHMSplit
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -77,7 +77,7 @@ module ValidationExamples
class LazarLastEPAFHMSplit < LazarEPAFHMSplit
def initialize
super
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/last")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/last")
end
end
@@ -124,8 +124,8 @@ module ValidationExamples
class LazarEPAFHMCrossvalidation < EPAFHMCrossvalidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -144,8 +144,8 @@ module ValidationExamples
class LazarHamsterSplit < HamsterSplit
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -153,7 +153,7 @@ module ValidationExamples
class LazarLastHamsterSplit < LazarHamsterSplit
def initialize
super
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/last")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/last")
end
end
@@ -186,8 +186,8 @@ module ValidationExamples
class LazarHamsterBootstrapping < HamsterBootstrapping
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -203,11 +203,9 @@ module ValidationExamples
class HamsterTrainingTest < TrainingTestValidation
def initialize
-# @test_target_dataset_file = File.new("data/hamster_carcinogenicity.yaml","r")
# @training_dataset_file = File.new("data/hamster_carcinogenicity.train.yaml","r")
# @test_dataset_file = File.new("data/hamster_carcinogenicity.test.yaml","r")
- @test_target_dataset_file = File.new("data/hamster_carcinogenicity.csv","r")
@training_dataset_file = File.new("data/hamster_carcinogenicity.train.csv","r")
@test_dataset_file = File.new("data/hamster_carcinogenicity.test.csv","r")
@@ -226,8 +224,8 @@ module ValidationExamples
class LazarHamsterTrainingTest < HamsterTrainingTest
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -261,8 +259,8 @@ module ValidationExamples
class LazarHamsterCrossvalidation < HamsterCrossvalidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -270,7 +268,7 @@ module ValidationExamples
class LazarLastHamsterCrossvalidation < LazarHamsterCrossvalidation
def initialize
super
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/last")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/last")
end
end
@@ -284,8 +282,8 @@ module ValidationExamples
class LazarHamsterLooCrossvalidation < HamsterLooCrossvalidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -294,8 +292,8 @@ module ValidationExamples
class LazarHamsterMiniCrossvalidation < CrossValidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
@dataset_file = File.new("data/hamster_carcinogenicity.mini.csv","r")
@num_folds = 2
end
@@ -303,8 +301,8 @@ module ValidationExamples
class ISSCANStratifiedCrossvalidation < CrossValidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
@dataset_file = File.new("data/ISSCAN_v3a_canc-red.csv","r")
@stratified = true
@num_folds = 10
@@ -313,8 +311,8 @@ module ValidationExamples
class ISSCAN2StratifiedCrossvalidation < CrossValidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
@dataset_file = File.new("data/ISSCAN_v3a_sal.csv","r")
@stratified = true
@num_folds = 10
@@ -340,8 +338,8 @@ module ValidationExamples
class LazarISTHamsterCrossvalidation < ISTHamsterCrossvalidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer")
super
end
end
@@ -544,8 +542,8 @@ module ValidationExamples
class LazarVsNtuaCrossvalidation < CrossValidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
@dataset_uri = "http://apps.ideaconsult.net:8080/ambit2/dataset/R545"
@prediction_feature="http://apps.ideaconsult.net:8080/ambit2/feature/22200"
@num_folds=3
@@ -667,11 +665,9 @@ module ValidationExamples
class HamsterTrainingTest < TrainingTestValidation
def initialize
-# @test_target_dataset_file = File.new("data/hamster_carcinogenicity.yaml","r")
# @training_dataset_file = File.new("data/hamster_carcinogenicity.train.yaml","r")
# @test_dataset_file = File.new("data/hamster_carcinogenicity.test.yaml","r")
- @test_target_dataset_file = File.new("data/hamster_carcinogenicity.csv","r")
@training_dataset_file = File.new("data/hamster_carcinogenicity.train.csv","r")
@test_dataset_file = File.new("data/hamster_carcinogenicity.test.csv","r")
@@ -698,8 +694,8 @@ module ValidationExamples
class LazarRepdoseSplit < RepdoseSplit
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
@@ -721,8 +717,8 @@ module ValidationExamples
class LazarRepdoseCrossValidation < RepdoseCrossValidation
def initialize
- @algorithm_uri = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- @algorithm_params = "feature_generation_uri="+File.join(CONFIG[:services]["opentox-algorithm"],"fminer/bbrc")
+ @algorithm_uri = File.join($algorithm[:uri],"lazar")
+ @algorithm_params = "feature_generation_uri="+File.join($algorithm[:uri],"fminer/bbrc")
super
end
end
diff --git a/test/test_examples_util.rb b/test/test_examples_util.rb
index 82c4c48..a323703 100755
--- a/test/test_examples_util.rb
+++ b/test/test_examples_util.rb
@@ -17,7 +17,7 @@ module ValidationExamples
@@dataset_uris = {}
@@prediction_features = {}
- def self.upload_dataset(file, subjectid=nil, dataset_service=CONFIG[:services]["opentox-dataset"]) #, file_type="application/x-yaml")
+ def self.upload_dataset(file, subjectid=nil, dataset_service=$dataset[:uri]) #, file_type="application/x-yaml")
raise "File not found: "+file.path.to_s unless File.exist?(file.path)
if @@dataset_uris[file.path.to_s]==nil
LOGGER.debug "uploading file: "+file.path.to_s
@@ -26,7 +26,7 @@ module ValidationExamples
#data_uri = OpenTox::RestClientWrapper.post(dataset_service,{:content_type => file_type},data).to_s.chomp
#@@dataset_uris[file.path.to_s] = data_uri
#LOGGER.debug "uploaded dataset: "+data_uri
- d = OpenTox::Dataset.create(CONFIG[:services]["opentox-dataset"], subjectid)
+ d = OpenTox::Dataset.create($dataset[:uri], subjectid)
d.load_yaml(data)
d.save( subjectid )
@@dataset_uris[file.path.to_s] = d.uri
@@ -36,7 +36,7 @@ module ValidationExamples
@@prediction_features[file.path.to_s] = d.features.keys[0]
@@dataset_uris[file.path.to_s] = d.uri
elsif (file.path =~ /rdf$/)
- d = OpenTox::Dataset.create(CONFIG[:services]["opentox-dataset"], subjectid)
+ d = OpenTox::Dataset.create($dataset[:uri], subjectid)
d.load_rdfxml_file(file, subjectid)
d.save(subjectid)
@@dataset_uris[file.path.to_s] = d.uri
@@ -77,7 +77,7 @@ module ValidationExamples
$test_case.post uri,params
return wait($test_case.last_response.body)
else
- return OpenTox::RestClientWrapper.post(File.join(CONFIG[:services]["opentox-validation"],uri),params,nil,waiting_task).to_s
+ return OpenTox::RestClientWrapper.post(File.join($validation[:uri],uri),params,nil,waiting_task).to_s
end
end
@@ -90,7 +90,7 @@ module ValidationExamples
return wait($test_case.last_response.body)
else
params[:accept] = accept_header
- return OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"],uri),params)
+ return OpenTox::RestClientWrapper.get(File.join($validation[:uri],uri),params)
end
end
@@ -100,7 +100,7 @@ module ValidationExamples
$test_case.delete uri,{:subjectid => SUBJECTID},'HTTP_ACCEPT' => accept_header
return wait($test_case.last_response.body)
else
- return OpenTox::RestClientWrapper.delete(File.join(CONFIG[:services]["opentox-validation"],uri),{:accept => accept_header,:subjectid => SUBJECTID})
+ return OpenTox::RestClientWrapper.delete(File.join($validation[:uri],uri),{:accept => accept_header,:subjectid => SUBJECTID})
end
end
@@ -238,8 +238,6 @@ module ValidationExamples
:model_uri,
:test_dataset_uri,
:test_dataset_file,
- :test_target_dataset_uri,
- :test_target_dataset_file,
:training_dataset_uri,
:training_dataset_file,
:dataset_uri,
@@ -258,7 +256,6 @@ module ValidationExamples
def upload_files
[[:test_dataset_uri, :test_dataset_file],
- [:test_target_dataset_uri, :test_target_dataset_file],
[:training_dataset_uri, :training_dataset_file],
[:dataset_uri, :dataset_file]].each do |a|
uri = a[0]
@@ -438,7 +435,7 @@ module ValidationExamples
end
def opt_params
- [ :prediction_feature, :test_target_dataset_uri ]
+ [ :prediction_feature ]
end
def validation_type
@@ -452,7 +449,7 @@ module ValidationExamples
end
def opt_params
- [ :algorithm_params, :test_target_dataset_uri ]
+ [ :algorithm_params ]
end
def validation_type
diff --git a/validation.gemspec b/validation.gemspec
new file mode 100644
index 0000000..2e12eed
--- /dev/null
+++ b/validation.gemspec
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "opentox-validation"
+ s.version = File.read("./VERSION")
+ s.authors = ["Martin Gütlein"]
+ s.email = ["martin.guetlein@gmail.com"]
+ s.homepage = "http://github.com/OpenTox/validation"
+ s.summary = %q{opentox validation service}
+ s.description = %q{opentox validation service}
+ s.license = 'GPL-3'
+ #s.platform = Gem::Platform::CURRENT
+
+ s.rubyforge_project = "validation"
+
+ s.files = `git ls-files`.split("\n")
+ #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ #s.require_paths = ["lib"]
+ s.required_ruby_version = '>= 1.9.2'
+
+ # specify any dependencies here; for example:
+ s.add_runtime_dependency "opentox-server"
+ s.post_install_message = "Please configure your service in ~/.opentox/config/validation.rb"
+end
+
+
diff --git a/validation/validation_application.rb b/validation/validation_application.rb
index 1bc55f6..37fea1e 100755
--- a/validation/validation_application.rb
+++ b/validation/validation_application.rb
@@ -1,10 +1,10 @@
-[ 'rubygems', 'sinatra', 'sinatra/url_for', 'opentox-ruby' ].each do |lib|
+[ 'rubygems', 'sinatra', 'sinatra/url_for' ].each do |lib|
require lib
end
-require 'lib/dataset_cache.rb'
-require 'validation/validation_service.rb'
+require './lib/dataset_cache.rb'
+require './validation/validation_service.rb'
helpers do
def check_stratified(params)
@@ -308,7 +308,6 @@ post '/test_set_validation' do
v = Validation::Validation.create :validation_type => "test_set_validation",
:model_uri => params[:model_uri],
:test_dataset_uri => params[:test_dataset_uri],
- :test_target_dataset_uri => params[:test_target_dataset_uri],
:prediction_feature => params[:prediction_feature]
v.subjectid = @subjectid
v.validate_model( task )
@@ -340,7 +339,6 @@ get '/test_set_validation' do
post_command = OpenTox::PostCommand.new request.url,"Perform test-set-validation"
post_command.attributes << OpenTox::PostAttribute.new("model_uri")
post_command.attributes << OpenTox::PostAttribute.new("test_dataset_uri")
- post_command.attributes << OpenTox::PostAttribute.new("test_target_dataset_uri",false,nil,"Specify if target endpoint values are not available in test dataset.")
post_command.attributes << OpenTox::PostAttribute.new("prediction_feature",false,nil,"Default is 'dependentVariables' of the model.")
content_type "text/html"
OpenTox.text_to_html uri_list,@subjectid,related_links,description,post_command
@@ -360,7 +358,6 @@ post '/training_test_validation/?' do
:algorithm_params => params[:algorithm_params],
:training_dataset_uri => params[:training_dataset_uri],
:test_dataset_uri => params[:test_dataset_uri],
- :test_target_dataset_uri => params[:test_target_dataset_uri],
:prediction_feature => params[:prediction_feature]
v.subjectid = @subjectid
v.validate_algorithm( task )
@@ -392,7 +389,6 @@ get '/training_test_validation' do
post_command.attributes << OpenTox::PostAttribute.new("algorithm_uri")
post_command.attributes << OpenTox::PostAttribute.new("training_dataset_uri")
post_command.attributes << OpenTox::PostAttribute.new("test_dataset_uri")
- post_command.attributes << OpenTox::PostAttribute.new("test_target_dataset_uri",false,nil,"Specify if target endpoint values are not available in test dataset.")
post_command.attributes << OpenTox::PostAttribute.new("prediction_feature")
post_command.attributes << OpenTox::PostAttribute.new("algorithm_params",false,nil,"Params used for model building, separate with ';', example: param1=v1;param2=v2")
content_type "text/html"
@@ -414,7 +410,6 @@ post '/bootstrapping' do
params[:random_seed], OpenTox::SubTask.create(task,0,33)) )
LOGGER.info "params after bootstrapping: "+params.inspect
v = Validation::Validation.create :validation_type => "bootstrapping",
- :test_target_dataset_uri => params[:dataset_uri],
:prediction_feature => params[:prediction_feature],
:algorithm_uri => params[:algorithm_uri],
:algorithm_params => params[:algorithm_params],
@@ -470,12 +465,11 @@ post '/training_test_split' do
raise OpenTox::BadRequestError.new "prediction_feature missing" unless params[:prediction_feature].to_s.size>0
check_stratified(params)
task = OpenTox::Task.create( "Perform training test split validation", url_for("/training_test_split", :full) ) do |task| #, params
- params.merge!( Validation::Util.train_test_dataset_split(params[:dataset_uri], params[:prediction_feature],
+ params.merge!( Validation::Util.train_test_dataset_split(params[:dataset_uri], (params[:stratified].to_s=~/true/ ? params[:prediction_feature] : nil),
@subjectid, params[:stratified], params[:split_ratio], params[:random_seed], OpenTox::SubTask.create(task,0,33)))
v = Validation::Validation.create :validation_type => "training_test_split",
:training_dataset_uri => params[:training_dataset_uri],
:test_dataset_uri => params[:test_dataset_uri],
- :test_target_dataset_uri => params[:dataset_uri],
:prediction_feature => params[:prediction_feature],
:algorithm_uri => params[:algorithm_uri],
:algorithm_params => params[:algorithm_params]
@@ -543,7 +537,6 @@ post '/cleanup_datasets/?' do
end
Validation::Validation.all.each do |val|
used_datasets << val.training_dataset_uri
- used_datasets << val.test_target_dataset_uri
used_datasets << val.test_dataset_uri
used_datasets << val.prediction_dataset_uri
end
@@ -595,7 +588,8 @@ post '/validate_datasets' do
feature_type = "regression" if params.delete("regression")!=nil
v = Validation::Validation.create params
v.subjectid = @subjectid
- v.compute_validation_stats(feature_type,predicted_variable,predicted_confidence,nil,nil,false,task)
+ v.compute_prediction_data(feature_type,predicted_variable,predicted_confidence,v.prediction_feature,nil,task)
+ v.compute_validation_stats()#feature_type,predicted_variable,predicted_confidence,nil,nil,false,task)
end
v.validation_uri
end
diff --git a/validation/validation_format.rb b/validation/validation_format.rb
index 3c9a8ef..0594629 100755
--- a/validation/validation_format.rb
+++ b/validation/validation_format.rb
@@ -1,5 +1,5 @@
-require "lib/format_util.rb"
+require "./lib/format_util.rb"
module Validation
diff --git a/validation/validation_service.rb b/validation/validation_service.rb
index 8c8b11f..de583f6 100755
--- a/validation/validation_service.rb
+++ b/validation/validation_service.rb
@@ -1,9 +1,9 @@
-require "lib/validation_db.rb"
-require "lib/ot_predictions.rb"
+require "./lib/validation_db.rb"
+require "./lib/ot_predictions.rb"
-require "validation/validation_format.rb"
+require "./validation/validation_format.rb"
class Array
@@ -64,20 +64,20 @@ module Validation
# PENDING: model and referenced datasets are deleted as well, keep it that way?
def delete_validation( delete_all=true )
if (delete_all)
- to_delete = [:model_uri, :training_dataset_uri, :test_dataset_uri, :test_target_dataset_uri, :prediction_dataset_uri ]
+ to_delete = [:model_uri, :training_dataset_uri, :test_dataset_uri, :prediction_dataset_uri ]
case self.validation_type
when "test_set_validation"
- to_delete -= [ :model_uri, :training_dataset_uri, :test_dataset_uri, :test_target_dataset_uri ]
+ to_delete -= [ :model_uri, :training_dataset_uri, :test_dataset_uri ]
when "bootstrapping"
- to_delete -= [ :test_target_dataset_uri ]
+ to_delete -= []
when "training_test_validation"
- to_delete -= [ :training_dataset_uri, :test_dataset_uri, :test_target_dataset_uri ]
+ to_delete -= [ :training_dataset_uri, :test_dataset_uri ]
when "training_test_split"
- to_delete -= [ :test_target_dataset_uri ]
+ to_delete -= []
when "validate_datasets"
to_delete = []
when "crossvalidation"
- to_delete -= [ :test_target_dataset_uri ]
+ to_delete -= []
when "crossvalidation_statistics"
to_delete = []
else
@@ -189,12 +189,11 @@ module Validation
models = cv_vals.collect{|v| OpenTox::Model::Generic.find(v.model_uri, subjectid)}
feature_type = models.first.feature_type(subjectid)
test_dataset_uris = cv_vals.collect{|v| v.test_dataset_uri}
- test_target_dataset_uris = cv_vals.collect{|v| v.test_target_dataset_uri}
prediction_feature = cv_vals.first.prediction_feature
prediction_dataset_uris = cv_vals.collect{|v| v.prediction_dataset_uri}
predicted_variables = models.collect{|m| m.predicted_variable(subjectid)}
predicted_confidences = models.collect{|m| m.predicted_confidence(subjectid)}
- p_data = Lib::PredictionData.create( feature_type, test_dataset_uris, test_target_dataset_uris, prediction_feature,
+ p_data = Lib::PredictionData.create( feature_type, test_dataset_uris, prediction_feature,
prediction_dataset_uris, predicted_variables, predicted_confidences, subjectid, waiting_task )
self.prediction_data = p_data.data
p_data.data
@@ -225,7 +224,7 @@ module Validation
LOGGER.debug "computing prediction stats"
p_data = Lib::PredictionData.create( feature_type,
- self.test_dataset_uri, self.test_target_dataset_uri, self.prediction_feature,
+ self.test_dataset_uri, self.prediction_feature,
self.prediction_dataset_uri, predicted_variable, predicted_confidence, self.subjectid,
OpenTox::SubTask.create(task, 0, 80) )
self.prediction_data = p_data.data
@@ -418,7 +417,6 @@ module Validation
tmp_val << { :validation_type => "crossvalidation",
:training_dataset_uri => v.training_dataset_uri,
:test_dataset_uri => v.test_dataset_uri,
- :test_target_dataset_uri => self.dataset_uri,
:crossvalidation_id => self.id,
:crossvalidation_fold => v.crossvalidation_fold,
:prediction_feature => prediction_feature,
@@ -448,39 +446,38 @@ module Validation
case stratified
when "false"
if self.loo=="true"
- shuffled_compounds = orig_dataset.compounds
+ shuffled_compound_indices = (0..(orig_dataset.compounds.size-1)).to_a
else
- shuffled_compounds = orig_dataset.compounds.shuffle( self.random_seed )
+ shuffled_compound_indices = (0..(orig_dataset.compounds.size-1)).to_a.shuffle( self.random_seed )
end
- split_compounds = shuffled_compounds.chunk( self.num_folds.to_i )
- LOGGER.debug "cv: num instances for each fold: "+split_compounds.collect{|c| c.size}.join(", ")
+ split_compound_indices = shuffled_compound_indices.chunk( self.num_folds.to_i )
+ LOGGER.debug "cv: num instances for each fold: "+split_compound_indices.collect{|c| c.size}.join(", ")
self.num_folds.to_i.times do |n|
- test_compounds = []
- train_compounds = []
+ test_compound_indices = []
+ train_compound_indices = []
self.num_folds.to_i.times do |nn|
- compounds = split_compounds[nn]
+ compound_indices = split_compound_indices[nn]
if n == nn
- compounds.each{ |compound| test_compounds << compound}
+ compound_indices.each{ |compound| test_compound_indices << compound}
else
- compounds.each{ |compound| train_compounds << compound}
+ compound_indices.each{ |compound| train_compound_indices << compound}
end
end
raise "internal error, num test compounds not correct,"+
- " is '#{test_compounds.size}', should be '#{(shuffled_compounds.size/self.num_folds.to_i)}'" unless
- (shuffled_compounds.size/self.num_folds.to_i - test_compounds.size).abs <= 1
- raise "internal error, num train compounds not correct, should be '"+(shuffled_compounds.size-test_compounds.size).to_s+
- "', is '"+train_compounds.size.to_s+"'" unless shuffled_compounds.size - test_compounds.size == train_compounds.size
+ " is '#{test_compound_indices.size}', should be '#{(shuffled_compound_indices.size/self.num_folds.to_i)}'" unless
+ (shuffled_compound_indices.size/self.num_folds.to_i - test_compound_indices.size).abs <= 1
+ raise "internal error, num train compounds not correct, should be '"+(shuffled_compound_indices.size-test_compound_indices.size).to_s+
+ "', is '"+train_compound_indices.size.to_s+"'" unless shuffled_compound_indices.size - test_compound_indices.size == train_compound_indices.size
datasetname = 'dataset fold '+(n+1).to_s+' of '+self.num_folds.to_s
meta[DC.title] = "training "+datasetname
- LOGGER.debug "training set: "+datasetname+"_train, compounds: "+train_compounds.size.to_s
- train_dataset_uri = orig_dataset.split( train_compounds, orig_dataset.features.keys,
+ LOGGER.debug "training set: "+datasetname+"_train, compounds: "+train_compound_indices.size.to_s
+ train_dataset_uri = orig_dataset.split( train_compound_indices, orig_dataset.features.keys,
meta, self.subjectid ).uri
train_dataset_uris << train_dataset_uri
meta[DC.title] = "test "+datasetname
- LOGGER.debug "test set: "+datasetname+"_test, compounds: "+test_compounds.size.to_s
- test_features = orig_dataset.features.keys.dclone - [self.prediction_feature]
- test_dataset_uri = orig_dataset.split( test_compounds, test_features,
+ LOGGER.debug "test set: "+datasetname+"_test, compounds: "+test_compound_indices.size.to_s
+ test_dataset_uri = orig_dataset.split( test_compound_indices, orig_dataset.features.keys,
meta, self.subjectid ).uri
test_dataset_uris << test_dataset_uri
end
@@ -505,7 +502,6 @@ module Validation
tmp_validation = { :validation_type => "crossvalidation",
:training_dataset_uri => train_dataset_uris[n],
:test_dataset_uri => test_dataset_uris[n],
- :test_target_dataset_uri => self.dataset_uri,
:crossvalidation_id => self.id, :crossvalidation_fold => (n+1),
:prediction_feature => self.prediction_feature,
:algorithm_uri => self.algorithm_uri,
@@ -537,25 +533,20 @@ module Validation
LOGGER.warn "no prediciton feature given, all features included in test dataset"
end
- compounds = orig_dataset.compounds
- raise OpenTox::NotFoundError.new "Cannot split datset, num compounds in dataset < 2 ("+compounds.size.to_s+")" if compounds.size<2
-
- compounds.each do |c|
- raise OpenTox::NotFoundError.new "Bootstrapping not yet implemented for duplicate compounds" if
- orig_dataset.data_entries[c][prediction_feature].size > 1
- end
+ compound_indices = (0..(orig_dataset.compounds.size-1)).to_a
+ raise OpenTox::NotFoundError.new "Cannot split datset, num compounds in dataset < 2 ("+compound_indices.size.to_s+")" if compound_indices.size<2
srand random_seed.to_i
while true
- training_compounds = []
- compounds.size.times do
- training_compounds << compounds[rand(compounds.size)]
+ training_compound_indices = []
+ compound_indices.size.times do
+ training_compound_indices << compound_indices[rand(compound_indices.size)]
end
- test_compounds = []
- compounds.each do |c|
- test_compounds << c unless training_compounds.include?(c)
+ test_compound_indices = []
+ compound_indices.each do |idx|
+ test_compound_indices << idx unless training_compound_indices.include?(idx)
end
- if test_compounds.size > 0
+ if test_compound_indices.size > 0
break
else
srand rand(10000)
@@ -563,47 +554,26 @@ module Validation
end
LOGGER.debug "bootstrapping on dataset "+orig_dataset_uri+
- " into training ("+training_compounds.size.to_s+") and test ("+test_compounds.size.to_s+")"+
- ", duplicates in training dataset: "+test_compounds.size.to_s
+ " into training ("+training_compound_indices.size.to_s+") and test ("+test_compound_indices.size.to_s+")"+
+ ", duplicates in training dataset: "+test_compound_indices.size.to_s
task.progress(33) if task
result = {}
-# result[:training_dataset_uri] = orig_dataset.create_new_dataset( training_compounds,
-# orig_dataset.features,
-# "Bootstrapping training dataset of "+orig_dataset.title.to_s,
-# $sinatra.url_for('/bootstrapping',:full) )
- result[:training_dataset_uri] = orig_dataset.split( training_compounds,
+ result[:training_dataset_uri] = orig_dataset.split( training_compound_indices,
orig_dataset.features.keys,
{ DC.title => "Bootstrapping training dataset of "+orig_dataset.title.to_s,
DC.creator => $url_provider.url_for('/bootstrapping',:full) },
subjectid ).uri
task.progress(66) if task
-# result[:test_dataset_uri] = orig_dataset.create_new_dataset( test_compounds,
-# orig_dataset.features.dclone - [prediction_feature],
-# "Bootstrapping test dataset of "+orig_dataset.title.to_s,
-# $sinatra.url_for('/bootstrapping',:full) )
- result[:test_dataset_uri] = orig_dataset.split( test_compounds,
- orig_dataset.features.keys.dclone - [prediction_feature],
+ result[:test_dataset_uri] = orig_dataset.split( test_compound_indices,
+ orig_dataset.features.keys,
{ DC.title => "Bootstrapping test dataset of "+orig_dataset.title.to_s,
DC.creator => $url_provider.url_for('/bootstrapping',:full)} ,
subjectid ).uri
task.progress(100) if task
- if ENV['RACK_ENV'] =~ /test|debug/
- training_dataset = Lib::DatasetCache.find result[:training_dataset_uri],subjectid
- raise OpenTox::NotFoundError.new "Training dataset not found: '"+result[:training_dataset_uri].to_s+"'" unless training_dataset
- training_dataset.load_all
- value_count = 0
- training_dataset.compounds.each do |c|
- value_count += training_dataset.data_entries[c][prediction_feature].size
- end
- raise "training compounds error" unless value_count==training_compounds.size
- raise OpenTox::NotFoundError.new "Test dataset not found: '"+result[:test_dataset_uri].to_s+"'" unless
- Lib::DatasetCache.find result[:test_dataset_uri], subjectid
- end
LOGGER.debug "bootstrapping done, training dataset: '"+result[:training_dataset_uri].to_s+"', test dataset: '"+result[:test_dataset_uri].to_s+"'"
-
return result
end
@@ -620,12 +590,17 @@ module Validation
orig_dataset = Lib::DatasetCache.find orig_dataset_uri, subjectid
orig_dataset.load_all subjectid
raise OpenTox::NotFoundError.new "Dataset not found: "+orig_dataset_uri.to_s unless orig_dataset
+
if prediction_feature
- raise OpenTox::NotFoundError.new "Prediction feature '"+prediction_feature.to_s+
- "' not found in dataset, features are: \n"+
- orig_dataset.features.keys.inspect unless orig_dataset.features.include?(prediction_feature)
- else
- LOGGER.warn "no prediciton feature given, all features will be included in test dataset"
+ if stratified==/true/
+ raise OpenTox::NotFoundError.new "Prediction feature '"+prediction_feature.to_s+
+ "' not found in dataset, features are: \n"+orig_dataset.features.keys.inspect unless orig_dataset.features.include?(prediction_feature)
+ else
+ LOGGER.warn "prediction_feature argument is ignored for non-stratified splits" if prediction_feature
+ prediction_feature=nil
+ end
+ elsif stratified==/true/
+ raise OpenTox::BadRequestError.new "prediction feature required for stratified splits" unless prediction_feature
end
meta = { DC.creator => $url_provider.url_for('/training_test_split',:full) }
@@ -633,10 +608,8 @@ module Validation
case stratified
when /true|super/
if stratified=="true"
- raise OpenTox::BadRequestError.new "prediction feature required for stratified splits" unless prediction_feature
features = [prediction_feature]
else
- LOGGER.warn "prediction feature is ignored for super-stratified splits" if prediction_feature
features = nil
end
r_util = OpenTox::RUtil.new
@@ -644,39 +617,36 @@ module Validation
r_util.quit_r
result = {:training_dataset_uri => train.uri, :test_dataset_uri => test.uri}
when "false"
- compounds = orig_dataset.compounds
- raise OpenTox::BadRequestError.new "Cannot split datset, num compounds in dataset < 2 ("+compounds.size.to_s+")" if compounds.size<2
- split = (compounds.size*split_ratio).to_i
+ compound_indices = (0..(orig_dataset.compounds.size-1)).to_a
+ raise OpenTox::BadRequestError.new "Cannot split datset, num compounds in dataset < 2 ("+compound_indices.size.to_s+")" if compound_indices.size<2
+ split = (compound_indices.size*split_ratio).round
split = [split,1].max
- split = [split,compounds.size-2].min
+ split = [split,compound_indices.size-2].min
LOGGER.debug "splitting dataset "+orig_dataset_uri+
- " into train:0-"+split.to_s+" and test:"+(split+1).to_s+"-"+(compounds.size-1).to_s+
+ " into train:0-"+split.to_s+" and test:"+(split+1).to_s+"-"+(compound_indices.size-1).to_s+
" (shuffled with seed "+random_seed.to_s+")"
- compounds.shuffle!( random_seed )
- training_compounds = compounds[0..split]
- test_compounds = compounds[(split+1)..-1]
+ compound_indices.shuffle!( random_seed )
+ training_compound_indices = compound_indices[0..(split-1)]
+ test_compound_indices = compound_indices[split..-1]
task.progress(33) if task
meta[DC.title] = "Training dataset split of "+orig_dataset.uri
result = {}
- result[:training_dataset_uri] = orig_dataset.split( training_compounds,
- orig_dataset.features.keys, meta, subjectid ).uri
+ train_data = orig_dataset.split( training_compound_indices,
+ orig_dataset.features.keys, meta, subjectid )
+ raise "Train dataset num coumpounds != "+(orig_dataset.compounds.size*split_ratio).round.to_s+", instead: "+train_data.compounds.size.to_s unless
+ train_data.compounds.size==(orig_dataset.compounds.size*split_ratio).round
+ result[:training_dataset_uri] = train_data.uri
task.progress(66) if task
meta[DC.title] = "Test dataset split of "+orig_dataset.uri
- result[:test_dataset_uri] = orig_dataset.split( test_compounds,
- orig_dataset.features.keys.dclone - [prediction_feature], meta, subjectid ).uri
+ test_data = orig_dataset.split( test_compound_indices,
+ orig_dataset.features.keys, meta, subjectid )
+ raise "Test dataset num coumpounds != "+(orig_dataset.compounds.size*(1-split_ratio)).round.to_s+", instead: "+test_data.compounds.size.to_s unless
+ test_data.compounds.size==(orig_dataset.compounds.size*(1-split_ratio)).round
+ result[:test_dataset_uri] = test_data.uri
task.progress(100) if task
- if ENV['RACK_ENV'] =~ /test|debug/
- raise OpenTox::NotFoundError.new "Training dataset not found: '"+result[:training_dataset_uri].to_s+"'" unless
- Lib::DatasetCache.find(result[:training_dataset_uri],subjectid)
- test_data = Lib::DatasetCache.find result[:test_dataset_uri],subjectid
- raise OpenTox::NotFoundError.new "Test dataset not found: '"+result[:test_dataset_uri].to_s+"'" unless test_data
- test_data.load_compounds subjectid
- raise "Test dataset num coumpounds != "+(compounds.size-split-1).to_s+", instead: "+
- test_data.compounds.size.to_s+"\n"+test_data.to_yaml unless test_data.compounds.size==(compounds.size-1-split)
- end
LOGGER.debug "split done, training dataset: '"+result[:training_dataset_uri].to_s+"', test dataset: '"+result[:test_dataset_uri].to_s+"'"
else
raise OpenTox::BadRequestError.new "stratified != false|true|super, is #{stratified}"
diff --git a/validation/validation_test.rb b/validation/validation_test.rb
index 70f3ca4..77a5415 100755
--- a/validation/validation_test.rb
+++ b/validation/validation_test.rb
@@ -9,11 +9,11 @@ before {
require "uri"
require "yaml"
ENV['RACK_ENV'] = 'production'
-require 'application.rb'
+require './application.rb'
require 'test/unit'
require 'rack/test'
-require 'lib/test_util.rb'
-require 'test/test_examples.rb'
+require './lib/test_util.rb'
+require './test/test_examples.rb'
LOGGER = OTLogger.new(STDOUT)
LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
@@ -59,6 +59,22 @@ class ValidationTest < Test::Unit::TestCase
def test_it
begin
$test_case = self
+
+ post '/validate_datasets',{:test_dataset_uri=>"http://local-ot/dataset/14111",
+ :prediction_dataset_uri=>"http://local-ot/dataset/14113",
+ :prediction_feature=>"http://local-ot/dataset/14109/feature/Hamster%20Carcinogenicity",
+ :predicted_variable=>"http://local-ot/model/21/predicted/value",
+ :predicted_confidence=>"http://local-ot/model/21/predicted/confidence",
+ :classification=>"true"}
+
+#D, [2012-11-07T12:38:11.291069 #31035] DEBUG -- : validation :: loading prediction -- test-dataset: ["http://local-ot/dataset/14099"] :: /validation_service.rb:227:in `compute_prediction_data'
+# D, [2012-11-07T12:38:11.291174 #31035] DEBUG -- : validation :: loading prediction -- test-target-datset: ["http://local-ot/dataset/14097"] :: /validation_service.rb:227:in `compute_prediction_data'
+# D, [2012-11-07T12:38:11.291281 #31035] DEBUG -- : validation :: loading prediction -- prediction-dataset: ["http://local-ot/dataset/14101"] :: /validation_service.rb:227:in `compute_prediction_data'
+# D, [2012-11-07T12:38:11.291398 #31035] DEBUG -- : validation :: loading prediction -- predicted_variable: ["http://local-ot/model/19/predicted/value"] :: /validation_service.rb:227:in `compute_prediction_data'
+# D, [2012-11-07T12:38:11.291506 #31035] DEBUG -- : validation :: loading prediction -- predicted_confidence: ["http://local-ot/model/19/predicted/confidence"] :: /validation_service.rb:227:in `compute_prediction_data'
+# D, [2012-11-07T12:38:11.291611 #31035] DEBUG -- : validation :: loading prediction -- prediction_feature: http://local-ot/dataset/14097/feature/Hamster%20Carcinogenicity :: /validation_service.rb:227:in `compute_prediction_data'
+
+ exit
# dataset_uri = "http://apps.ideaconsult.net:8080/ambit2/dataset/603206?pagesize=250&page=0"
# test_dataset_uri = "http://apps.ideaconsult.net:8080/ambit2/dataset/603206?pagesize=250&page=1"
@@ -117,7 +133,6 @@ class ValidationTest < Test::Unit::TestCase
# post "/validate_datasets",{
# :test_dataset_uri=>"http://local-ot/dataset/6907",
# :prediction_dataset_uri=>"http://local-ot/dataset/6909",
-# :test_target_dataset_uri=>"http://local-ot/dataset/6905",
# :prediction_feature=>"http://local-ot/dataset/6905/feature/Hamster%20Carcinogenicity",
# #:model_uri=>"http://local-ot/model/1078",
# :predicted_variable=>"http://local-ot/dataset/6909/feature/prediction/Hamster%20Carcinogenicity/value",
@@ -351,7 +366,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://apps.deaconsult.net:8080/ambit2/dataset/R3924",
# :prediction_dataset_uri=>"http://apps.ideaconsult.net:8080/ambit2/dataset/R3924?feature_uris[]=http%3A%2F%2Fapps.ideaconsult.net%3A8080%2Fambit2%2Fmodel%2F52%2Fpredicted",
- # #:test_target_dataset_uri=>"http://local-ot/dataset/202",
# :prediction_feature=>"http://apps.ideaconsult.net:8080/ambit2/feature/21715",
# :predicted_feature=>"http://apps.ideaconsult.net:8080/ambit2/feature/28944",
# :regression=>"true"}
@@ -363,7 +377,6 @@ end
#get "/crossvalidation/19/predictions",nil,'HTTP_ACCEPT' => "application/x-yaml" #/statistics"
# post "",:model_uri=>"http://local-ot/model/1",:test_dataset_uri=>"http://local-ot/dataset/3",
- # :test_target_dataset_uri=>"http://local-ot/dataset/1"
# get "/crossvalidation/2",nil,'HTTP_ACCEPT' => "application/rdf+xml"
#puts last_response.body
@@ -384,7 +397,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://local-ot/dataset/204",
# :prediction_dataset_uri=>"http://local-ot/dataset/206",
- # :test_target_dataset_uri=>"http://local-ot/dataset/202",
# :prediction_feature=>"http://ot-dev.in-silico.ch/toxcreate/feature#IRIS%20unit%20risk",
# :predicted_feature=>"http://ot-dev.in-silico.ch/toxcreate/feature#IRIS%20unit%20risk_lazar_regression",
# :regression=>"true"}
@@ -394,7 +406,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://apps.ideaconsult.net:8080/ambit2/dataset/9?max=10",
# :prediction_dataset_uri=>"http://apps.ideaconsult.net:8080/ambit2/dataset/9?max=10",
-# #:test_target_dataset_uri=>"http://local-ot/dataset/202",
# :prediction_feature=>"http://apps.ideaconsult.net:8080/ambit2/feature/21573",
# :predicted_feature=>"http://apps.ideaconsult.net:8080/ambit2/feature/21573",
# #:regression=>"true"}
@@ -406,7 +417,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://local-ot/dataset/89",
# :prediction_dataset_uri=>"http://local-ot/dataset/91",
- # :test_target_dataset_uri=>"http://local-ot/dataset/87",
# :prediction_feature=>"http://local-ot/dataset/1/feature/hamster_carcinogenicity",
# :predicted_feature=>"",
## :regression=>"true"}
@@ -419,7 +429,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://local-ot/dataset/390",
# :prediction_dataset_uri=>"http://local-ot/dataset/392",
-# :test_target_dataset_uri=>"http://local-ot/dataset/388",
# :prediction_feature=>"http://local-ot/dataset/388/feature/repdose_classification",
# :model_uri=>"http://local-ot/model/31"}
# #:regression=>"true"}
@@ -432,7 +441,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://opentox.informatik.uni-freiburg.de/dataset/409",
# :prediction_dataset_uri=>"http://opentox.informatik.uni-freiburg.de/dataset/410",
-# :test_target_dataset_uri=>"https://ambit.uni-plovdiv.bg:8443/ambit2/dataset/R401560",
# :prediction_feature=>"https://ambit.uni-plovdiv.bg:8443/ambit2/feature/22190",
# :predicted_feature=>"https://ambit.uni-plovdiv.bg:8443/ambit2/feature/218304",
# :regression=>"true",
@@ -453,7 +461,6 @@ end
# post "/validate_datasets",{
# :test_dataset_uri=>"http://local-ot/dataset/94",
# :prediction_dataset_uri=>'http://local-ot/dataset/96',
-# :test_target_dataset_uri=>'http://local-ot/dataset/92',
# :prediction_feature=>'http://local-ot/dataset/92/feature/Hamster%20Carcinogenicity',
# :predicted_feature=>"",
# :classification=>"true",