Module: OpenTox::Algorithm

Includes:
OpenTox
Included in:
Dataset, Fminer, Generic, Lazar, Similarity, Substructure, Model::Lazar
Defined in:
lib/algorithm.rb

Overview

Wrapper for OpenTox Algorithms

Defined Under Namespace

Modules: Dataset, Fminer, Neighbors, Similarity, Substructure Classes: Generic, Lazar

Instance Attribute Summary

Attributes included from OpenTox

#metadata, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenTox

#add_metadata, all, #delete, #initialize, #load_metadata, login, text_to_html

Class Method Details

.gauss(x, sigma = 0.3) ⇒ Float

Gauss kernel

Returns:

  • (Float)


249
250
251
252
# File 'lib/algorithm.rb', line 249

def self.gauss(x, sigma = 0.3) 
  d = 1.0 - x
  Math.exp(-(d*d)/(2*sigma*sigma))
end

.median(array) ⇒ Float

Median of an array

Parameters:

  • Array (Array)

    with values

Returns:

  • (Float)

    Median



257
258
259
260
261
262
# File 'lib/algorithm.rb', line 257

def self.median(array)
  return nil if array.empty?
  array.sort!
  m_pos = array.size / 2
  return array.size % 2 == 1 ? array[m_pos] : (array[m_pos-1] + array[m_pos])/2
end

Instance Method Details

#run(params = nil, waiting_task = nil) ⇒ String

Execute algorithm with parameters, please consult the OpenTox API and the webservice documentation for acceptable parameters

Parameters:

  • params (optional, Hash) (defaults to: nil)

    Algorithm parameters

  • waiting_task (optional, OpenTox::Task) (defaults to: nil)

    (can be a OpenTox::Subtask as well), progress is updated accordingly

Returns:

  • (String)

    URI of new resource (dataset, model, …)



18
19
20
# File 'lib/algorithm.rb', line 18

def run(params=nil, waiting_task=nil)
  RestClientWrapper.post(@uri, params, {:accept => 'text/uri-list'}, waiting_task).to_s
end

#to_rdfxmlapplication/rdf+xml

Get OWL-DL representation in RDF/XML format

Returns:

  • (application/rdf+xml)

    RDF/XML representation



24
25
26
27
28
# File 'lib/algorithm.rb', line 24

def to_rdfxml
  s = Serializer::Owl.new
  s.add_algorithm(@uri,@metadata)
  s.to_rdfxml
end