summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-01-31 11:55:57 +0100
committermr <mr@mrautenberg.de>2011-01-31 11:55:57 +0100
commit7ac05a889f1c7f3bb43ef764564920ce0cd84f34 (patch)
tree2ee5a2aa87e31035a4abf2e8a295a1b708c62a5f
parent4100a87f3784006687a2c8787b57936c96218f79 (diff)
merge with helma/development
-rw-r--r--Rakefile12
-rw-r--r--config.ru2
m---------last-utils0
-rw-r--r--lazar.rb4
m---------libfminer0
-rw-r--r--openbabel.rb170
6 files changed, 155 insertions, 33 deletions
diff --git a/Rakefile b/Rakefile
index d52f60d..e60ffc7 100644
--- a/Rakefile
+++ b/Rakefile
@@ -30,10 +30,10 @@ namespace "fminer" do
end
puts `make ruby`
Dir.chdir('../../last-utils')
- puts `git fetch`
+ #puts `git fetch`
# AM LAST: need branch 'experimental' until merged to master in last-utils
- puts `git checkout -f -b experimental origin/experimental`
- puts `git checkout experimental`
+ #puts `git checkout -f -b experimental origin/experimental`
+ puts `git checkout master`
puts `git pull`
end
@@ -63,10 +63,10 @@ namespace "fminer" do
end
puts `make ruby`
Dir.chdir('../../last-utils')
- puts `git fetch`
+ #puts `git fetch`
# AM LAST: need branch 'experimental' until merged to master in last-utils
- puts `git checkout -f -b experimental origin/experimental`
- puts `git checkout experimental`
+ #puts `git checkout -f -b experimental origin/experimental`
+ puts `git checkout master`
puts `git pull`
end
end
diff --git a/config.ru b/config.ru
index 67d8493..a1aab0d 100644
--- a/config.ru
+++ b/config.ru
@@ -2,3 +2,5 @@ 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
diff --git a/last-utils b/last-utils
-Subproject 9bba490c02a5fea57d65b61e7f68e88ed72893c
+Subproject 324a179b992c7b8b6f52963d4912ce5f92fe81c
diff --git a/lazar.rb b/lazar.rb
index fc037a9..c8cf6ea 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -25,8 +25,8 @@ end
# @param [String] dataset_uri Training dataset URI
# @param [optional,String] prediction_feature URI of the feature to be predicted
# @param [optional,String] feature_generation_uri URI of the feature generation algorithm
-# @param [optional] - further parameters for the feature generation service
-# @ return [text/uri-list] Task URI
+# @param [optional,String] - further parameters for the feature generation service
+# @return [text/uri-list] Task URI
post '/lazar/?' do
halt 404, "No dataset_uri parameter." unless params[:dataset_uri]
diff --git a/libfminer b/libfminer
-Subproject c72bb7d99bb7f583f009e44be426910fb44cd4f
+Subproject e0eee431ecb954328ff64e3cc48840c7003a276
diff --git a/openbabel.rb b/openbabel.rb
index a261866..3a873c0 100644
--- a/openbabel.rb
+++ b/openbabel.rb
@@ -1,28 +1,148 @@
-get '/openbabel/:smiles/:property/?' do
+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,
+ OT.isA => OTA.DescriptorCalculation,
+ }
+ response['Content-Type'] = 'application/rdf+xml'
+ algorithm.to_rdfxml
+ else
+ halt 404, "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
- obconversion.set_in_and_out_formats 'smi', 'can'
- case params[:property]
- when 'logP'
- #logP = OpenBabel::OBLogP.new
- #logP.predict(obmol)
- "not yet implemented"
- when 'psa'
- #psa = OpenBabel::OBPSA.new
- "not yet implemented"
- when 'mr'
- #mr = OpenBabel::OBMR.new
- "not yet implemented"
- else
- begin
- obconversion.read_string obmol, params[:smiles]
- rescue
- halt 404, "Incorrect Smiles string #{params[:smiles]}"
- end
- begin
- eval("obmol.#{params[:property]}").to_s
- rescue
- halt 404, "Could not calculate property #{params[:property]}"
- end
- end
+ 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
+ halt 404, "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'
+ halt 503,task.uri+"\n" if task.status == "Cancelled"
+ halt 202,task.uri.to_s+"\n"
end