diff options
author | Christoph Helma <helma@in-silico.ch> | 2013-01-18 13:45:04 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2013-01-18 13:45:04 +0100 |
commit | 29fcbe3990952d61565eafd45d3f00ed9d4f297c (patch) | |
tree | 3e8406cabd4a63c9b45880e466d18582910187ec | |
parent | a4c8201828614b40e01f37aed31727cd60754620 (diff) |
local inchi conversion, url_for removed, gem dependencies in gemspec
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | application.rb | 2 | ||||
-rw-r--r-- | compound.rb | 58 | ||||
-rw-r--r-- | dataset.gemspec | 5 | ||||
-rw-r--r-- | webapp/dataset.rb | 10 | ||||
-rw-r--r-- | webapp/sinatra.rb | 3 |
6 files changed, 67 insertions, 15 deletions
@@ -1,6 +1,4 @@ source :gemcutter -#gemspec +gemspec gem "opentox-server", :path => "../opentox-server" gem "opentox-client", :path => "../opentox-client" -gem "emk-sinatra-url-for", "~>0.2.1" -gem "roo", "~>1.10.1" diff --git a/application.rb b/application.rb index cae6066..dd6a62d 100644 --- a/application.rb +++ b/application.rb @@ -3,7 +3,7 @@ # Author: Christoph Helma, Andreas Maunz require 'roo' -require 'sinatra/url_for' +require './compound.rb' # Library code $logger.debug "Dataset booting: #{$dataset.collect{|k,v| "#{k}: '#{v}'"} }" diff --git a/compound.rb b/compound.rb new file mode 100644 index 0000000..cb194ff --- /dev/null +++ b/compound.rb @@ -0,0 +1,58 @@ +require "openbabel" +module OpenTox + + # Perform OpenBabel conversions locally in order to prevent net overhead + class Compound + + attr_writer :smiles, :inchi + + # Create a compound from smiles string + # @example + # compound = OpenTox::Compound.from_smiles("c1ccccc1") + # @param [String] smiles Smiles string + # @return [OpenTox::Compound] Compound + def self.from_smiles service_uri, smiles, subjectid=nil + inchi = obconversion(smiles,'smi','inchi') + compound = Compound.new(File.join service_uri, inchi) + compound.inchi = inchi + compound.smiles = smiles + compound + end + + # Create a compound from inchi string + # @param [String] smiles InChI string + # @return [OpenTox::Compound] Compound + def self.from_inchi service_uri, inchi, subjectid=nil + compound = Compound.new(File.join service_uri, inchi) + compound.inchi = inchi + compound + end + + # Create a compound from sdf string + # @param [String] smiles SDF string + # @return [OpenTox::Compound] Compound + def self.from_sdf service_uri, sdf, subjectid=nil + inchi = obconversion(sdf,'sdf','inchi') + compound = Compound.new(File.join service_uri, inchi) + compound.inchi = inchi + compound + end + + private + + # Convert identifier from OpenBabel input_format to OpenBabel output_format + def self.obconversion(identifier,input_format,output_format) + obconversion = OpenBabel::OBConversion.new + obmol = OpenBabel::OBMol.new + obconversion.set_in_and_out_formats input_format, output_format + obconversion.read_string obmol, identifier + case output_format + when /smi|can|inchi/ + obconversion.write_string(obmol).gsub(/\s/,'').chomp + else + obconversion.write_string(obmol) + end + end + end + +end diff --git a/dataset.gemspec b/dataset.gemspec index a6a135b..d82e8b3 100644 --- a/dataset.gemspec +++ b/dataset.gemspec @@ -18,8 +18,7 @@ Gem::Specification.new do |s| # specify any dependencies here; for example: s.add_runtime_dependency "opentox-server" - s.add_runtime_dependency 'roo' - #s.add_runtime_dependency 'axlsx' - #s.add_runtime_dependency 'simple_xlsx_writer' + s.add_runtime_dependency 'roo', "~>1.10.1" + s.add_runtime_dependency "openbabel", "~>2.3.1.5" s.post_install_message = "Please configure your service in ~/.opentox/config/dataset.rb" end diff --git a/webapp/dataset.rb b/webapp/dataset.rb index c75b722..5bf8799 100644 --- a/webapp/dataset.rb +++ b/webapp/dataset.rb @@ -12,7 +12,7 @@ module OpenTox get '/dataset/*/pc' do dataset=params["captures"][0] algorithms = YAML::load_file File.join(ENV['HOME'], ".opentox", "config", "pc_descriptors.yaml") - list = (algorithms.keys.sort << "AllDescriptors").collect { |name| url_for("/dataset/#{dataset}/pc/#{name}",:full) }.join("\n") + "\n" + list = (algorithms.keys.sort << "AllDescriptors").collect { |name| to("/dataset/#{dataset}/pc/#{name}",:full) }.join("\n") + "\n" format_output(list) end @@ -43,7 +43,7 @@ module OpenTox if descriptors # Contents - algorithm = OpenTox::Algorithm.new(url_for("/dataset/#{dataset}/pc/#{params[:descriptor]}",:full)) + algorithm = OpenTox::Algorithm.new(to("/dataset/#{dataset}/pc/#{params[:descriptor]}",:full)) mmdata = { DC.title => params[:descriptor], DC.creator => "andreas@maunz.de", @@ -86,7 +86,7 @@ module OpenTox $task[:uri], @subjectid, { RDF::DC.description => "Calculating PC descriptors", - RDF::DC.creator => url_for("/dataset/#{dataset}/pc",:full) + RDF::DC.creator => to("/dataset/#{dataset}/pc",:full) } ) do |task| @@ -105,8 +105,8 @@ module OpenTox { DC.title => key, OT.paramValue => (val.nil? ? "" : val) } } result_ds[DC.title] = single_cmpd_ds[DC.title] - result_ds[DC.creator] = url_for("/dataset/#{dataset}/pc",:full) - result_ds[OT.hasSource] = url_for("/dataset/#{dataset}/pc",:full) + result_ds[DC.creator] = to("/dataset/#{dataset}/pc",:full) + result_ds[OT.hasSource] = to("/dataset/#{dataset}/pc",:full) end result_ds << [ cmpd ] + single_cmpd_ds.data_entries[0] } diff --git a/webapp/sinatra.rb b/webapp/sinatra.rb index a516496..fd0d354 100644 --- a/webapp/sinatra.rb +++ b/webapp/sinatra.rb @@ -5,9 +5,6 @@ module OpenTox class Application < Service - # Get url_for support - helpers Sinatra::UrlForHelper - # Conveniently accessible from anywhere within the Application class, # it negotiates the appropriate output format based on object class # and requested MIME type. |