From 4a702262fd96e65703075e7b6e6e7b1c876a51bb Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Tue, 3 Apr 2012 16:54:30 +0200 Subject: Fixed documentation --- application.rb | 15 +++-- feature_generation.rb | 49 ----------------- fs.rb | 18 +++--- openbabel.rb | 148 -------------------------------------------------- pc.rb | 15 ++--- similarity.rb | 26 --------- smarts.rb | 3 - 7 files changed, 29 insertions(+), 245 deletions(-) delete mode 100644 feature_generation.rb delete mode 100644 openbabel.rb delete mode 100644 similarity.rb delete mode 100644 smarts.rb diff --git a/application.rb b/application.rb index 539ac2b..ef123da 100644 --- a/application.rb +++ b/application.rb @@ -1,3 +1,4 @@ +# Java Klimbim ENV["JAVA_HOME"] = "/usr/lib/jvm/java-6-sun" unless ENV["JAVA_HOME"] ENV["JOELIB2"] = File.join File.expand_path(File.dirname(__FILE__)),"java" deps = [] @@ -8,16 +9,20 @@ jars = Dir[ENV["JOELIB2"]+"/*.jar"].collect {|f| File.expand_path(f) } deps = deps + jars ENV["CLASSPATH"] = deps.join(":") - 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 + + +# fminer libs to be included before openbabel, otherwise strange SWIG overloading problems +require File.join(File.expand_path(File.dirname(__FILE__)), 'libfminer/libbbrc/bbrc') +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') + gem "opentox-ruby", "~> 3" require 'opentox-ruby' require 'rjb' + +# main require 'fminer.rb' require 'lazar.rb' require 'fs.rb' diff --git a/feature_generation.rb b/feature_generation.rb deleted file mode 100644 index e822404..0000000 --- a/feature_generation.rb +++ /dev/null @@ -1,49 +0,0 @@ -# Get list if pc descriptor calculation algorithms -# -# @return [text/uri-list] URIs of pc descriptor calculation algorithms -get '/pcdesc' do -algorithm = OpenTox::Algorithm::Generic.new(url_for('/pcdesc',:full)) - algorithm.metadata = { - DC.title => 'Physico-chemical (PC) descriptor calculation', - DC.creator => "andreas@maunz.de, vorgrimmlerdavid@gmx.de", - RDF.type => [OT.Algorithm,OTA.DescriptorCalculation], - OT.parameters => [ - { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" }, - { DC.description => "PC type", OT.paramScope => "mandatory", DC.title => "pc_type" }, - ] - } - case request.env['HTTP_ACCEPT'] - when /text\/html/ - content_type "text/html" - OpenTox.text_to_html algorithm.to_yaml - when /application\/x-yaml/ - content_type "application/x-yaml" - algorithm.to_yaml - else - response['Content-Type'] = 'application/rdf+xml' - algorithm.to_rdfxml - end -end - -# Run pc descriptor calculation algorithm on dataset -# -# @param [String] dataset_uri URI of the training dataset -# @param [String] feature_dataset_uri URI of the feature dataset -# @return [text/uri-list] Task URI -post '/pcdesc' do - response['Content-Type'] = 'text/uri-list' - raise OpenTox::NotFoundError.new "Please submit a dataset_uri." unless params[:dataset_uri] - raise "No PC type given" unless params["pc_type"] - - task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do |task| - types = params[:pc_type].split(",") - if types.include?("joelib") - Rjb.load(nil,["-Xmx64m"]) - s = Rjb::import('JoelibFc') - end - OpenTox::Algorithm.pc_descriptors( { :dataset_uri => params[:dataset_uri], :pc_type => params[:pc_type], :rjb => s, :task => task } ) - end - raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" - halt 202,task.uri.to_s+"\n" -end - diff --git a/fs.rb b/fs.rb index 469fa87..7ee8c30 100644 --- a/fs.rb +++ b/fs.rb @@ -1,7 +1,11 @@ +# fs.rb +# Feature Selection +# Author: Andreas Maunz + + # Get list of feature selection algorithms -# # @return [text/uri-list] URIs of feature selection algorithms -get '/feature_selection/?' do +get '/fs/?' do list = [ url_for('/feature_selection/rfe', :full) ].join("\n") + "\n" case request.env['HTTP_ACCEPT'] when /text\/html/ @@ -13,9 +17,9 @@ get '/feature_selection/?' do end end -# Get RDF/XML representation of feature_selection rfe algorithm -# @return [application/rdf+xml] OWL-DL representation of feature_selection rfe algorithm -get "/feature_selection/rfe/?" do +# Get representation of recursive feature elimination algorithm +# @return [application/rdf+xml] OWL-DL representation of recursive feature elimination algorithm +get "/fs/rfe/?" do algorithm = OpenTox::Algorithm::Generic.new(url_for('/feature_selection/rfe',:full)) algorithm.metadata = { DC.title => 'recursive feature elimination', @@ -44,9 +48,9 @@ get "/feature_selection/rfe/?" do end # Run rfe algorithm on dataset -# # @param [String] dataset_uri URI of the training dataset -# @param [String] feature_dataset_uri URI of the feature dataset +# @param [String] prediction_feature URI +# @param [String] feature_dataset_uri URI # @return [text/uri-list] Task URI post '/feature_selection/rfe/?' do diff --git a/openbabel.rb b/openbabel.rb deleted file mode 100644 index 463663e..0000000 --- a/openbabel.rb +++ /dev/null @@ -1,148 +0,0 @@ -OBMOL_METHODS = { - "NumAtoms" => "Number of atoms", - "NumBonds" => "Number of bonds", - "NumHvyAtoms" => "Number of heavy atoms", - "NumResidues" => "Number of residues", - "NumRotors" => "Number of rotatable bonds", - "GetEnergy" => "Heat of formation for this molecule (in kcal/mol)", - "GetMolWt" => "Standard molar mass given by IUPAC atomic masses (amu)", - "GetExactMass" => "Mass given by isotopes (or most abundant isotope, if not specified)", - "GetTotalCharge" => "Total charge", -} - -OBDESCRIPTOR_METHODS = { - "HBA1" => "Number of hydrogen bond acceptors 1 (JoelLib)", - "HBA2" => "Number of hydrogen bond acceptors 2 (JoelLib)", - "HBD" => "Number of hydrogen bond donors (JoelLib)", - "L5" => "Lipinski rule of five", - "logP" => "Octanol/water partition coefficient", - "MR" => "Molar refractivity", - "MW" => "Molecular weight", - "nF" => "Number of fluorine atoms", - "nHal" => "Number of halogen atoms", - "spinMult" => "Total spin multiplicity", - "TPSA" => "Topological polar surface area", -} - -# Get a list of OpenBabel algorithms -# @return [text/uri-list] URIs of OpenBabel algorithms -get '/openbabel' do - algorithms = OBMOL_METHODS.collect{|name,description| url_for("/openbabel/#{name}",:full)} - algorithms << OBDESCRIPTOR_METHODS.collect{|name,description| url_for("/openbabel/#{name}",:full)} - response['Content-Type'] = 'text/uri-list' - algorithms.join("\n") -end - -# Get RDF/XML representation of OpenBabel algorithm -# @return [application/rdf+xml] OWL-DL representation of OpenBabel algorithm -get '/openbabel/:property' do - description = OBMOL_METHODS[params[:property]] if OBMOL_METHODS.include? params[:property] - description = OBDESCRIPTOR_METHODS[params[:property]] if OBDESCRIPTOR_METHODS.include? params[:property] - if description - algorithm = OpenTox::Algorithm::Generic.new(url_for("/openbabel/#{params[:property]}",:full)) - algorithm.metadata = { - DC.title => params[:property], - DC.creator => "helma@in-silico.ch", - DC.description => description, - RDF.type => [OTA.DescriptorCalculation], - } - response['Content-Type'] = 'application/rdf+xml' - algorithm.to_rdfxml - else - raise OpenTox::NotFoundError.new "Unknown OpenBabel descriptor #{params[:property]}." - end -end - -# Calculate OpenBabel descriptors -# Supports the following OpenBabel methods (see OpenBabel API http://openbabel.org/api/2.2.0/) -# - NumAtoms Number of atoms -# - NumBonds Number of bonds -# - NumHvyAtoms Number of heavy atoms -# - NumResidues Number of residues -# - NumRotors Number of rotatable bonds -# - GetEnergy Heat of formation for this molecule (in kcal/mol) -# - GetMolWt Standard molar mass given by IUPAC atomic masses (amu) -# - GetExactMass Mass given by isotopes (or most abundant isotope, if not specified) -# - GetTotalCharge Total charge -# - HBA1 Number of hydrogen bond acceptors 1 (JoelLib) -# - HBA2 Number of hydrogen bond acceptors 2 (JoelLib) -# - HBD Number of hydrogen bond donors (JoelLib) -# - L5 Lipinski rule of five -# - logP Octanol/water partition coefficient -# - MR Molar refractivity -# - MW Molecular weight -# - nF Number of fluorine atoms -# - nHal Number of halogen atoms -# - spinMult Total spin multiplicity -# - TPSA Topological polar surface area -# @param [String] compound_uri Compound URI -# @return [String] descriptor value -post '/openbabel/:property' do - obconversion = OpenBabel::OBConversion.new - obmol = OpenBabel::OBMol.new - compound = OpenTox::Compound.new params[:compound_uri] - obconversion.set_in_and_out_formats 'inchi', 'can' - obconversion.read_string obmol, compound.to_inchi - if OBMOL_METHODS.keys.include? params[:property] - eval("obmol.#{params[:property].underscore}").to_s - elsif OBDESCRIPTOR_METHODS.keys.include? params[:property] - descriptor = OpenBabel::OBDescriptor.find_type(params[:property]) - descriptor.predict(obmol).to_s - else - raise OpenTox::NotFoundError.new "Cannot calculate property #{params[:property]} with OpenBabel" - end -end - -# Calculate all OpenBabel descriptors for a dataset -# @param [String] dataset_uri Dataset URI -# @return [text/uri-list] Task URI -post '/openbabel' do - task = OpenTox::Task.create("Calculating OpenBabel descriptors for #{params[:dataset_uri]}", url_for('/openbabel',:full)) do - - dataset = OpenTox::Dataset.find(params[:dataset_uri]) - result_dataset = OpenTox::Dataset.create - result_dataset.add_metadata({ - DC.title => "OpenBabel descriptors for " + dataset.metadata[DC.title].to_s, - DC.creator => url_for('/openbabel',:full), - OT.hasSource => url_for('/openbabel', :full), - OT.parameters => [ - { DC.title => "dataset_uri", OT.paramValue => params[:dataset_uri] }, - ] - }) - - obconversion = OpenBabel::OBConversion.new - obmol = OpenBabel::OBMol.new - obconversion.set_in_and_out_formats 'inchi', 'can' - - OBMOL_METHODS.merge(OBDESCRIPTOR_METHODS).each do |name,description| - feature_uri = File.join result_dataset.uri, "feature", "openbabel", name - metadata = { - OT.hasSource => url_for("/openbabel/#{name}", :full), - DC.description => description, - DC.title => name, - } - result_dataset.add_feature feature_uri, metadata - end - - dataset.compounds.each do |compound_uri| - compound = OpenTox::Compound.new(compound_uri) - obconversion.read_string obmol, compound.to_inchi - #result_dataset.add_compound compound_uri - OBMOL_METHODS.keys.each do |name| - feature_uri = File.join result_dataset.uri, "feature", "openbabel", name - value = eval("obmol.#{name.underscore}").to_f - result_dataset.add compound_uri, feature_uri, value - end - OBDESCRIPTOR_METHODS.keys.each do |name| - feature_uri = File.join result_dataset.uri, "feature", "openbabel", name - value = OpenBabel::OBDescriptor.find_type(params[:property]).predict(obmol).to_f - result_dataset.add compound_uri, feature_uri, value - end - end - result_dataset.save - result_dataset.uri - end - response['Content-Type'] = 'text/uri-list' - raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled" - halt 202,task.uri.to_s+"\n" -end diff --git a/pc.rb b/pc.rb index 5c38052..37130dd 100644 --- a/pc.rb +++ b/pc.rb @@ -3,8 +3,8 @@ # Author: Andreas Maunz -# Get a list of pc algorithms -# @return [text/uri-list] URIs of algorithms +# Get a list of descriptor calculation algorithms +# @return [text/uri-list] URIs of descriptor calculation algorithms get '/pc' do algorithms = YAML::load_file File.join(ENV['HOME'], ".opentox", "config", "pc_descriptors.yaml") response['Content-Type'] = 'text/uri-list' @@ -19,8 +19,8 @@ get '/pc' do end end -# Get RDF/XML representation of OpenBabel algorithm -# @return [application/rdf+xml] OWL-DL representation of OpenBabel algorithm +# Get representation of descriptor calculation algorithm +# @return [application/rdf+xml] OWL-DL representation of descriptor calculation algorithm get '/pc/:descriptor' do descriptors = YAML::load_file File.join(ENV['HOME'], ".opentox", "config", "pc_descriptors.yaml") alg_params = [ { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" } ] @@ -65,9 +65,10 @@ get '/pc/:descriptor' do end end -# Run pc descriptor calculation algorithm on dataset -# +# Run pc descriptor calculation algorithm on dataset for a set of descriptors. Can be constrained to types and libraries. # @param [String] dataset_uri URI of the training dataset +# @param optional [String] pc_type Physico-chemical descriptor type to generate, see TODO +# @param optional [String] lib Library to use, see TODO # @return [text/uri-list] Task URI post '/pc' do response['Content-Type'] = 'text/uri-list' @@ -87,7 +88,7 @@ post '/pc' do halt 202,task.uri.to_s+"\n" end -# Run pc descriptor calculation algorithm on dataset +# Run pc descriptor calculation algorithm on dataset for a specific descriptor. # # @param [String] dataset_uri URI of the training dataset # @return [text/uri-list] Task URI diff --git a/similarity.rb b/similarity.rb deleted file mode 100644 index faf43f9..0000000 --- a/similarity.rb +++ /dev/null @@ -1,26 +0,0 @@ -require File.join(File.dirname(__FILE__),'dataset.rb') - -helpers do -def find - # + charges are dropped - uri = uri(params[:splat].first.gsub(/(InChI.*) (.*)/,'\1+\2')) # reinsert dropped '+' signs in InChIs - raise OpenTox::NotFoundError.new "Dataset \"#{uri}\" not found." unless @set = Dataset.find(uri) -end - -def uri(name) - name = URI.encode(name) - uri = File.join Dataset.base_uri, name - end -end - -get '/tanimoto/dataset/*/dataset/*/?' do - find - @set.tanimoto(uri(params[:splat][1])) -end - -get '/weighted_tanimoto/dataset/*/dataset/*/?' do - find - @set.weighted_tanimoto(uri(params[:splat][1])) -end - - diff --git a/smarts.rb b/smarts.rb deleted file mode 100644 index 4ae6949..0000000 --- a/smarts.rb +++ /dev/null @@ -1,3 +0,0 @@ -get '/match/compound/*/smarts/*/?' do - "#{OpenTox::Compound.from_inchi(params[:splat][0]).match?(params[:splat][1])}" -end -- cgit v1.2.3