From cd90cdd3fb486b550c2d4de65cbd11682e7aefe9 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 26 Mar 2012 16:04:47 +0200 Subject: Initial version --- Gemfile | 4 ++ Gemfile.lock | 103 ++++++++++++++++++++++++++++++++++ README.md | 1 + application.rb | 55 +++++++++--------- bin/algorithm-install | 150 ++++++++++++++++++++++++++++++++------------------ config.ru | 10 ++-- libfminer | 2 +- 7 files changed, 234 insertions(+), 91 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..cbb6d62 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source :gemcutter + +gem 'opentox-server', :path => "~/opentox-ruby/opentox-server" +gem "opentox-client", :path => "~/opentox-ruby/opentox-client" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..a6d93fe --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,103 @@ +PATH + remote: ~/opentox-ruby/opentox-client + specs: + opentox-client (0.0.1pre) + bundler + open4 + rdf + rdf-raptor + rest-client + +PATH + remote: ~/opentox-ruby/opentox-server + specs: + opentox-server (0.0.1pre) + emk-sinatra-url-for + opentox-client + rack + rack-contrib + roo + sinatra + sinatra-contrib + unicorn + +GEM + remote: http://rubygems.org/ + specs: + addressable (2.2.7) + backports (2.5.0) + choice (0.1.5) + emk-sinatra-url-for (0.2.1) + sinatra (>= 0.9.1.1) + eventmachine (0.12.10) + faraday (0.7.6) + addressable (~> 2.2) + multipart-post (~> 1.1) + rack (~> 1.1) + ffi (1.0.11) + google-spreadsheet-ruby (0.1.8) + nokogiri (>= 1.4.3.1) + oauth (>= 0.3.6) + oauth2 (>= 0.5.0) + kgio (2.7.4) + log4r (1.1.10) + mime-types (1.18) + multi_json (1.1.0) + multipart-post (1.1.5) + nokogiri (1.5.2) + oauth (0.4.5) + oauth2 (0.5.2) + faraday (~> 0.7) + multi_json (~> 1.0) + open4 (1.3.0) + rack (1.4.1) + rack-contrib (1.1.0) + rack (>= 0.9.1) + rack-protection (1.2.0) + rack + rack-test (0.6.1) + rack (>= 1.0) + raindrops (0.8.0) + rdf (0.3.5.1) + addressable (>= 2.2.6) + rdf-raptor (0.4.1) + ffi (>= 1.0) + rdf (~> 0.3.0) + rest-client (1.6.7) + mime-types (>= 1.16) + roo (1.10.1) + choice (>= 0.1.4) + google-spreadsheet-ruby (>= 0.1.5) + nokogiri (>= 1.5.0) + rubyzip (>= 0.9.4) + spreadsheet (> 0.6.4) + todonotes (>= 0.1.0) + ruby-ole (1.2.11.3) + rubyzip (0.9.6.1) + sinatra (1.3.2) + rack (~> 1.3, >= 1.3.6) + rack-protection (~> 1.2) + tilt (~> 1.3, >= 1.3.3) + sinatra-contrib (1.3.1) + backports (>= 2.0) + eventmachine + rack-protection + rack-test + sinatra (~> 1.3.0) + tilt (~> 1.3) + spreadsheet (0.6.8) + ruby-ole (>= 1.0) + tilt (1.3.3) + todonotes (0.1.0) + log4r + unicorn (4.2.0) + kgio (~> 2.6) + rack + raindrops (~> 0.7) + +PLATFORMS + ruby + +DEPENDENCIES + opentox-client! + opentox-server! diff --git a/README.md b/README.md index 344f747..a7fd0a4 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ OpenTox Algorithm - Implements the OpenTox algorithm API for - fminer - lazar + - feature selection REST operations --------------- diff --git a/application.rb b/application.rb index f5b331f..b93d9fd 100644 --- a/application.rb +++ b/application.rb @@ -1,35 +1,32 @@ -require 'rubygems' -# AM LAST: can include both libs, no problems -require File.join(File.expand_path(File.dirname(__FILE__)), 'libfminer/libbbrc/bbrc') # has to be included before openbabel, otherwise we have strange SWIG overloading problems -require File.join(File.expand_path(File.dirname(__FILE__)), 'libfminer/liblast/last') # has to be included before openbabel, otherwise we have strange SWIG overloading problems -require File.join(File.expand_path(File.dirname(__FILE__)), 'last-utils/lu.rb') # AM LAST -gem "opentox-ruby", "~> 3" -require 'opentox-ruby' +require 'opentox-server' +require File.join(File.expand_path(File.dirname(__FILE__)), 'libfminer/libbbrc/bbrc') # include before openbabel +require File.join(File.expand_path(File.dirname(__FILE__)), 'libfminer/liblast/last') # +require File.join(File.expand_path(File.dirname(__FILE__)), 'last-utils/lu.rb') -#require 'smarts.rb' -#require 'similarity.rb' -require 'openbabel.rb' -require 'fminer.rb' -require 'lazar.rb' -require 'feature_selection.rb' +#require 'openbabel.rb' +#require 'fminer.rb' +#require 'lazar.rb' +#require 'feature_selection.rb' -set :lock, true +module OpenTox + class Application < Service + helpers do + def uri_list + uris = [ url_for('/lazar', :full), url_for('/fminer/bbrc', :full), url_for('/fminer/last', :full), url_for('/feature_selection/rfe', :full) ] + uris.compact.sort.join("\n") + "\n" + end + end -before do - LOGGER.debug "Request: " + request.path -end + get '/?' do + case @accept + when 'text/uri-list' + response['Content-Type'] = 'text/uri-list' + uri_list + else + response['Content-Type'] = 'application/rdf+xml' + uri_list + end + end -# Get a list of available algorithms -# -# @return [text/uri-list] algorithm URIs -get '/?' do - list = [ url_for('/lazar', :full), url_for('/fminer/bbrc', :full), url_for('/fminer/last', :full), url_for('/feature_selection/rfe', :full) ].join("\n") + "\n" - case request.env['HTTP_ACCEPT'] - when /text\/html/ - content_type "text/html" - OpenTox.text_to_html list,@subjectid - else - content_type 'text/uri-list' - list end end diff --git a/bin/algorithm-install b/bin/algorithm-install index 20bf847..157eeb6 100755 --- a/bin/algorithm-install +++ b/bin/algorithm-install @@ -2,90 +2,130 @@ # # Installs Opentox Webservices. # Author: Christoph Helma, Andreas Maunz. -# - +SELF=$(basename $0 -install) OT_PREFIX="$HOME/opentox-ruby" +OT_CONFIG="$HOME/.opentox" RUBY_VER="1.9.3-p125" RUBY_DWL="http://ftp.ruby-lang.org/pub/ruby/1.9" +RUBY_DIR="$HOME/.rbenv/versions/$RUBY_VER" FMINER_BRANCH="development" -if [ "$(id -u)" = "0" ]; then - echo "This script must be run as non-root." 1>&2 - exit 1 -fi +[ "`id -u`" = "0" ] && echo "This script must be run as non-root." 1>&2 && exit 1 -# Enforce main directory +# check wd is root of service DIR=`pwd` if echo $DIR | grep "algorithm/bin" >/dev/null 2>&1 ; then cd ..; fi +# check main directories present +([ -d $OT_PREFIX ] && [ -d $OT_CONFIG ]) || (echo "Main directories missing." 1>&2 && exit 1) +[ -d $OT_PREFIX/opentox-server ] || (echo "Warning: opentox-server missing." 1>&2) -# Ruby -. $HOME/.opentox/opentox-ui.sh -utils="git rbenv curl" +# load main config +! [ -f $OT_CONFIG/opentox-ui.sh ] && echo "Main config file missing." 1>&2 && exit 1 || . $OT_CONFIG/opentox-ui.sh + +# check utils +utils="git rbenv curl gem make" for u in $utils; do - eval `echo $u | tr "[:lower:]" "[:upper:]"`=`which $u` || (echo "'$u' missing. Install '$u' first." && exit 1) + eval `echo $u | tr "[:lower:]" "[:upper:]"`=`which $u` || (echo "'$u' missing. Install '$u' first." 1>&2 && exit 1) done - -LOG="$OT_PREFIX/tmp/`basename $0`.log" -echo -echo "Installation ('$LOG'):" - +# util functions run_cmd () { local cmd="$1"; local title="$2" - printf "%30s" "'$title'" + printf "%50s" "'$title'" if ! eval $cmd >>$LOG 2>&1 ; then - printf "%50s\n" "FAIL" + printf "%30s\n" "FAIL" echo "Last 10 lines of log:" tail -10 "$LOG" exit 1 fi - printf "%50s\n" "DONE" + printf "%30s\n" "DONE" } - install_ruby() { + printf "\n%50s\n" "RUBY" local DIR=`pwd` - [ -d $DIR/tmp ] || mkdir -p $DIR/tmp && cd $DIR/tmp - ([ -d $DIR/tmp/ruby-$RUBY_VER ] || $CURL $RUBY_DWL/ruby-$RUBY_VER.tar.gz 2>/dev/null | tar xz) && cd ruby-$RUBY_VER - cmd="./configure --prefix=$HOME/.rbenv/versions/$RUBY_VER" && run_cmd "$cmd" "Configure" - cmd="make -j2" && run_cmd "$cmd" "Make" - cmd="make install" && run_cmd "$cmd" "Install" - $RBENV rehash + if ! [ $RBENV versions $RUBY_VER | grep $RUBY_VER>/dev/null ]; then + [ -d $DIR/tmp ] || mkdir -p $DIR/tmp && cd $DIR/tmp + ([ -d $DIR/tmp/ruby-$RUBY_VER ] || $CURL $RUBY_DWL/ruby-$RUBY_VER.tar.gz 2>/dev/null | tar xz) && cd ruby-$RUBY_VER + cmd="./configure --prefix=$RUBY_DIR" && run_cmd "$cmd" "Configure" + cmd="make -j2" && run_cmd "$cmd" "Make" + [ -d $RUBY_DIR ] && rm -rf $RUBY_DIR + cmd="make install" && run_cmd "$cmd" "Install" + fi cd $DIR + cmd="$RBENV rehash" && run_cmd "$cmd" "rbenv rehash" + cmd="$RBENV local $RUBY_VER" && run_cmd "$cmd" "rbenv set ruby" +} +install_ob_ruby() { + printf "\n%50s\n" "OB RUBY BINDINGS" + local DIR=`pwd` + SRC_DIR=$(dirname $(find $OT_PREFIX -name openbabel-ruby.cpp)) + [ -d "$SRC_DIR" ] || (echo "Sources not found." 1>&2 && exit 1) + cd $SRC_DIR + sed -i 's/Init_OpenBabel/Init_openbabel/g' openbabel-ruby.cpp # apply fix + RUBY=`which ruby` + cmd="$RUBY extconf.rb --with-openbabel-include=../../include --with-openbabel-lib=../../src/.libs" && run_cmd "$cmd" "Extconf ruby bindings" + cmd="$MAKE" && run_cmd "$cmd" "Make OB ruby bindings" + cmd="$MAKE install" && run_cmd "$cmd" "Install OB ruby bindings" + cd $DIR + cmd="$RBENV rehash" && run_cmd "$cmd" "rbenv rehash" +} +install_fminer() { + printf "\n%50s\n" "FMINER" + local DIR=`pwd` + eval RUBY_INC="-I`dirname $RUBY_DIR/include/ruby*/*linux/ruby`\ -I`dirname $RUBY_DIR/include/ruby*/ruby`" + eval OPBB_INC="-I`dirname $OT_PREFIX/openbabel*/include/openbabel*/openbabel`" + cmd="$GIT submodule init" && run_cmd "$cmd" "Fminer Init" + cmd="$GIT submodule update" && run_cmd "$cmd" "Fminer Update" + cd "libfminer/libbbrc">>$LOG 2>&1 + $GIT checkout $FMINER_BRANCH>>$LOG 2>&1 + $GIT pull >>$LOG 2>&1 + cd - >>$LOG 2>&1 + cd "libfminer/liblast">>$LOG 2>&1 + $GIT checkout $FMINER_BRANCH>>$LOG 2>&1 + $GIT pull >>$LOG 2>&1 + cd - >>$LOG 2>&1 + for mylib in bbrc last; do + cmd="sed -i 's,^INCLUDE_OB.*,INCLUDE_OB\ =\ $OPBB_INC,g' `pwd`/libfminer/lib$mylib/Makefile" && run_cmd "$cmd" "Makefile $mylib (OB)" + cmd="sed -i 's,^INCLUDE_RB.*,INCLUDE_RB\ =\ $RUBY_INC,g' `pwd`/libfminer/lib$mylib/Makefile" && run_cmd "$cmd" "Makefile $mylib (RB)" + done + cd "libfminer/libbbrc">>$LOG 2>&1 + cmd="make ruby" && run_cmd "$cmd" "Make BBRC" + cd - >>$LOG 2>&1 + cd "libfminer/liblast">>$LOG 2>&1 + cmd="make ruby" && run_cmd "$cmd" "Make LAST" + cd - >>$LOG 2>&1 + cd "last-utils">>$LOG 2>&1 + $GIT checkout $FMINER_BRANCH>>$LOG 2>&1 + $GIT pull >>$LOG 2>&1 + cd $DIR +} +install_bundler() { + $GEM list | grep bundler >/dev/null 2>&1 || (cmd="$GEM install bundler" && run_cmd "$cmd" "Install bundler") + cmd="$RBENV rehash" && run_cmd "$cmd" "rbenv rehash" + BUNDLER=`which bundle` + cmd="$BUNDLER install" && run_cmd "$cmd" "Bundle install" } -[ "`$RBENV local`" = "$RUBY_VER" ] || install_ruby -$RBENV local $RUBY_VER +# # # Install -# fminer etc -eval RUBY_INC="-I`dirname $HOME/.rbenv/versions/$RUBY_VER/include/ruby*/*linux/ruby`\ -I`dirname $HOME/.rbenv/versions/$RUBY_VER/include/ruby*/ruby`" -eval OPBB_INC="-I`dirname $OT_PREFIX/openbabel*/include/openbabel*/openbabel`" -cmd="$GIT submodule init" && run_cmd "$cmd" "Fminer Init" -cmd="$GIT submodule update" && run_cmd "$cmd" "Fminer Update" -cd "libfminer/libbbrc">>$LOG 2>&1 -$GIT checkout $FMINER_BRANCH>>$LOG 2>&1 -$GIT pull >>$LOG 2>&1 -cd - >>$LOG 2>&1 -cd "libfminer/liblast">>$LOG 2>&1 -$GIT checkout $FMINER_BRANCH>>$LOG 2>&1 -$GIT pull >>$LOG 2>&1 -cd - >>$LOG 2>&1 -for mylib in bbrc last; do - cmd="sed -i 's,^INCLUDE_OB.*,INCLUDE_OB\ =\ $OPBB_INC,g' `pwd`/libfminer/lib$mylib/Makefile" && run_cmd "$cmd" "Makefile $mylib (OB)" - cmd="sed -i 's,^INCLUDE_RB.*,INCLUDE_RB\ =\ $RUBY_INC,g' `pwd`/libfminer/lib$mylib/Makefile" && run_cmd "$cmd" "Makefile $mylib (RB)" -done -cd "libfminer/libbbrc">>$LOG 2>&1 -cmd="make ruby" && run_cmd "$cmd" "Make BBRC" -cd - >>$LOG 2>&1 -cd "libfminer/liblast">>$LOG 2>&1 -cmd="make ruby" && run_cmd "$cmd" "Make LAST" -cd - >>$LOG 2>&1 -cd "last-utils">>$LOG 2>&1 -$GIT checkout $FMINER_BRANCH>>$LOG 2>&1 -$GIT pull >>$LOG 2>&1 +LOG="$OT_PREFIX/tmp/`basename $0`.log" +echo +echo "Installation ('$LOG'):" +echo -cd "$DIR" +[ -d $OT_CONFIG/log ] || cmd="mkdir -p $OT_CONFIG/log" && run_cmd "$cmd" "Main log directory" +[ -d $OT_CONFIG/config/$SELF ] || cmd="mkdir -p $OT_CONFIG/config/$SELF" && run_cmd "$cmd" "$SELF config directory" + +[ "`$RBENV local`" = "$RUBY_VER" ] || install_ruby +[ -z `find $RUBY_DIR -name openbabel.so 2>/dev/null` ] && install_ob_ruby +( [ -z `find libfminer/ -name bbrc.so 2>/dev/null` ] || [ -z `find libfminer/ -name last.so 2>/dev/null` ] ) && install_fminer +echo +install_bundler + +# return to wd +cd "$DIR" diff --git a/config.ru b/config.ru index a1aab0d..2e5285d 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,4 @@ -require 'rubygems' -require 'opentox-ruby' -require 'config/config_ru' -run Sinatra::Application -set :raise_errors, false -set :show_exceptions, false \ No newline at end of file +require 'bundler' +Bundler.require +require './application.rb' +run OpenTox::Application diff --git a/libfminer b/libfminer index f9e560d..4577dca 160000 --- a/libfminer +++ b/libfminer @@ -1 +1 @@ -Subproject commit f9e560dc0a7a5d5af439814ab5fa9ce027a025b7 +Subproject commit 4577dcacb352af3fdca925714dc570de9e02582c -- cgit v1.2.3