summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2013-06-05 16:37:25 +0200
committergebele <gebele@in-silico.ch>2013-06-05 16:37:25 +0200
commit5dab9d972bedb4319de39ee17253902fb37f8667 (patch)
treedf63afa049f5ddf9873fe0e658a91859db490255 /lib
parent0c20a7e7841c2c85a4d3260d018017d350bc0953 (diff)
parent962773d59d94f8d16dae11b6290fdf30aaf09d7b (diff)
Merge branch 'development' of github.com:opentox/opentox-client into development
Diffstat (limited to 'lib')
-rw-r--r--lib/algorithm.rb4
-rw-r--r--lib/authorization.rb49
-rw-r--r--lib/compound.rb9
-rw-r--r--lib/dataset.rb58
-rw-r--r--lib/model.rb4
-rw-r--r--lib/opentox.rb10
-rw-r--r--lib/overwrite.rb21
-rw-r--r--lib/policy.rb17
-rw-r--r--lib/validation.rb132
9 files changed, 158 insertions, 146 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 530296a..8576681 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -1,11 +1,11 @@
module OpenTox
# Wrapper for OpenTox Algorithms
- class Algorithm
+ class Algorithm
# Execute algorithm with parameters, please consult the OpenTox API and the webservice documentation for acceptable parameters
# @param [optional,Hash] params Algorithm parameters
- # @param [optional,Boolean] set to true if method should wait for task result
+ # @param [optional,Boolean] wait set to true if method should wait for task result
# @return [String] URI of new resource (dataset, model, ...)
def run params=nil, wait=true
uri = RestClientWrapper.post @uri, params, { :content_type => "text/uri-list", :subjectid => @subjectid}
diff --git a/lib/authorization.rb b/lib/authorization.rb
index 469c16c..7f0e840 100644
--- a/lib/authorization.rb
+++ b/lib/authorization.rb
@@ -6,6 +6,7 @@ module OpenTox
# require "opentox-client"
# OpenTox::Authorization::AA = "https://opensso.in-silico.ch" #if not set in .opentox/conf/[SERVICE].rb
# subjectid = OpenTox::Authorization.authenticate("username", "password")
+ # puts OpenTox::Authorization.authorize("http://example.uri/testpath/", "GET", subjectid)
#@see http://www.opentox.org/dev/apis/api-1.2/AA OpenTox A&A API 1.2 specification
module Authorization
@@ -29,7 +30,7 @@ module OpenTox
#Cleans AA Policies and loads default xml file into policy attribute
#set uri and user, returns Policyfile(XML) for open-sso
- # @param [String] URI to create a policy for
+ # @param uri [String] URI to create a policy for
def get_xml(uri)
@policy.drop_policies
@policy.load_default_policy(@user, uri)
@@ -37,7 +38,7 @@ module OpenTox
end
#Loads and sends Policyfile(XML) to open-sso server
- # @param [String] URI to create a policy for
+ # @param uri [String] URI to create a policy for
def send(uri)
xml = get_xml(uri)
ret = false
@@ -57,7 +58,8 @@ module OpenTox
end
#Authentication against OpenSSO. Returns token. Requires Username and Password.
- # @param [String, String]Username,Password
+ # @param user [String] Username
+ # @param pw [String] Password
# @return [String, nil] gives subjectid or nil
def self.authenticate(user, pw)
return nil if !AA
@@ -71,7 +73,7 @@ module OpenTox
end
#Logout on opensso. Make token invalid. Requires token
- # @param [String]subjectid the subjectid
+ # @param [String] subjectid the subjectid
# @return [Boolean] true if logout is OK
def self.logout(subjectid)
begin
@@ -84,7 +86,9 @@ module OpenTox
end
#Authorization against OpenSSO for a URI with request-method (action) [GET/POST/PUT/DELETE]
- # @param [String,String,String]uri,action,subjectid
+ # @param [String] uri URI to request
+ # @param [String] action request method
+ # @param [String] subjectid
# @return [Boolean, nil] returns true, false or nil (if authorization-request fails).
def self.authorize(uri, action, subjectid)
return true if !AA
@@ -118,7 +122,8 @@ module OpenTox
end
#Returns a policy in xml-format
- # @param [String, String]policy,subjectid
+ # @param policy [String] policyname
+ # @param subjectid [String]
# @return [String] XML of the policy
def self.list_policy(policy, subjectid)
begin
@@ -150,7 +155,8 @@ module OpenTox
end
#Returns the owner (who created the first policy) of an URI
- # @param [String, String]uri,subjectid
+ # @param uri [String] URI
+ # @param subjectid [String] subjectid
# return [String, nil]owner,nil returns owner of the URI
def self.get_uri_owner(uri, subjectid)
begin
@@ -161,14 +167,16 @@ module OpenTox
end
#Returns true or false if owner (who created the first policy) of an URI
- # @param [String, String]uri,subjectid
+ # @param uri [String] URI
+ # @param subjectid [String]
# return [Boolean]true,false status of ownership of the URI
def self.uri_owner?(uri, subjectid)
get_uri_owner(uri, subjectid) == get_user(subjectid)
end
#Checks if a policy exists to a URI. Requires URI and token.
- # @param [String, String]uri,subjectid
+ # @param uri [String] URI
+ # @param subjectid [String]
# return [Boolean]
def self.uri_has_policy(uri, subjectid)
owner = get_uri_owner(uri, subjectid)
@@ -177,7 +185,8 @@ module OpenTox
end
#List all policynames for a URI. Requires URI and token.
- # @param [String, String]uri,subjectid
+ # @param uri [String] URI
+ # @param subjectid [String]
# return [Array, nil] returns an Array of policy names or nil if request fails
def self.list_uri_policies(uri, subjectid)
begin
@@ -194,7 +203,8 @@ module OpenTox
end
#Sends a policy in xml-format to opensso server. Requires policy-xml and token.
- # @param [String, String]policyxml,subjectid
+ # @param policy [String] XML string of a policy
+ # @param subjectid [String]
# return [Boolean] returns true if policy is created
def self.create_policy(policy, subjectid)
begin
@@ -206,7 +216,8 @@ module OpenTox
end
#Deletes a policy
- # @param [String, String]policyname,subjectid
+ # @param policy [String] policyname
+ # @param subjectid [String]
# @return [Boolean,nil]
def self.delete_policy(policy, subjectid)
begin
@@ -254,7 +265,8 @@ module OpenTox
end
#Send default policy with Authorization::Helper class
- # @param [String, String]URI,subjectid
+ # @param uri [String] URI
+ # @param subjectid [String]
def self.send_policy(uri, subjectid)
return true if !AA
aa = Authorization::Helper.new(subjectid)
@@ -264,7 +276,8 @@ module OpenTox
end
#Deletes all policies of an URI
- # @param [String, String]URI,subjectid
+ # @param uri [String] URI
+ # @param subjectid [String]
# @return [Boolean]
def self.delete_policies_from_uri(uri, subjectid)
policies = list_uri_policies(uri, subjectid)
@@ -308,9 +321,9 @@ module OpenTox
end
# Check Authorization for a resource (identified via URI) with method and subjectid.
- # @param [String] uri
- # @param [String] request_method, should be GET, POST, PUT, DELETE
- # @param [String] subjectid
+ # @param uri [String] URI
+ # @param request_method [String] GET, POST, PUT, DELETE
+ # @param subjectid [String]
# @return [Boolean] true if access granted, else otherwise
def self.authorized?(uri, request_method, subjectid)
request_method = request_method.to_sym if request_method
@@ -345,7 +358,7 @@ module OpenTox
define_method "#{method}?".to_sym do |uri, request_method|
if $aa["#{method}s".to_sym]
$aa["#{method}s".to_sym].each do |request_methods, uris|
- if request_methods and uris and request_methods.include?(request_method.to_sym)
+ if request_methods and uris and request_methods.include?(request_method.to_sym)
uris.each do |u|
return true if u.match uri
end
diff --git a/lib/compound.rb b/lib/compound.rb
index 2eccdcd..a278244 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -16,14 +16,14 @@ module OpenTox
end
# Create a compound from inchi string
- # @param [String] smiles InChI string
+ # @param inchi [String] smiles InChI string
# @return [OpenTox::Compound] Compound
def self.from_inchi inchi, subjectid=nil
Compound.new RestClientWrapper.post(service_uri, inchi, {:content_type => 'chemical/x-inchi', :subjectid => subjectid})
end
# Create a compound from sdf string
- # @param [String] smiles SDF string
+ # @param sdf [String] smiles SDF string
# @return [OpenTox::Compound] Compound
def self.from_sdf sdf, subjectid=nil
Compound.new RestClientWrapper.post(service_uri, sdf, {:content_type => 'chemical/x-mdl-sdfile', :subjectid => subjectid})
@@ -32,9 +32,8 @@ module OpenTox
# Create a compound from name. Relies on an external service for name lookups.
# @example
# compound = OpenTox::Compound.from_name("Benzene")
- # @param [String] name name can be also an InChI/InChiKey, CAS number, etc
+ # @param name [String] can be also an InChI/InChiKey, CAS number, etc
# @return [OpenTox::Compound] Compound
- #
def self.from_name name, subjectid=nil
@inchi = RestClientWrapper.get File.join(CACTUS_URI,URI.escape(name),"stdinchi")
Compound.new RestClientWrapper.post(service_uri, @inchi, {:content_type => 'chemical/x-inchi', :subjectid => subjectid})
@@ -191,7 +190,7 @@ module OpenTox
# Match an array of smarts strings, returns hash
# Keys: matching smarts, values: number of non-unique hits, or 1
# @param [Array] smarts_array Array with Smarts strings
- # @param [Boolean] Whether non-unique hits or 1 should be produced
+ # @param use_hits [Boolean] Whether non-unique hits or 1 should be produced
# @return [Array] Array with matching Smarts strings
# @example {
# compound = Compound.from_name("Benzene")
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 8d5f5d1..19d05c9 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -3,7 +3,7 @@ require 'csv'
module OpenTox
# Ruby wrapper for OpenTox Dataset Webservices (http://opentox.org/dev/apis/api-1.2/dataset).
- class Dataset
+ class Dataset
attr_writer :features, :compounds, :data_entries
@@ -46,7 +46,7 @@ module OpenTox
end
@compounds
end
-
+
def data_entries force_update=false
if @data_entries.empty? or force_update
sparql = "SELECT ?cidx ?fidx ?value FROM <#{uri}> WHERE {
@@ -55,7 +55,7 @@ module OpenTox
?v <#{RDF::OT.feature}> ?f;
<#{RDF::OT.value}> ?value .
?f <#{RDF::OLO.index}> ?fidx.
- } ORDER BY ?fidx ?cidx"
+ } ORDER BY ?fidx ?cidx"
RestClientWrapper.get(service_uri,{:query => sparql},{:accept => "text/uri-list", :subjectid => @subjectid}).split("\n").each do |row|
r,c,v = row.split("\t")
@data_entries[r.to_i] ||= []
@@ -79,9 +79,9 @@ module OpenTox
@data_entries
end
- # Find data entry values for a given compound and feature
- # @param [OpenTox::Compound] Compound
- # @param [OpenTox::Feature] Feature
+ # Find data entry values for a given compound and feature
+ # @param compound [OpenTox::Compound] OpenTox Compound object
+ # @param feature [OpenTox::Feature] OpenTox Feature object
# @return [Array] Data entry values
def values(compound, feature)
rows = (0 ... compounds.length).select { |r| compounds[r].uri == compound.uri }
@@ -92,14 +92,14 @@ module OpenTox
# Convenience methods to search by compound/feature URIs
# Search a dataset for a feature given its URI
- # @param [String] Feature URI
+ # @param uri [String] Feature URI
# @return [OpenTox::Feature] Feature object, or nil if not present
def find_feature_uri(uri)
features.select{|f| f.uri == uri}.first
end
# Search a dataset for a compound given its URI
- # @param [String] Compound URI
+ # @param uri [String] Compound URI
# @return [OpenTox::Compound] Compound object, or nil if not present
def find_compound_uri(uri)
compounds.select{|f| f.uri == uri}.first
@@ -133,7 +133,7 @@ module OpenTox
def upload filename, wait=true
uri = RestClientWrapper.put(@uri, {:file => File.new(filename)}, {:subjectid => @subjectid})
wait_for_task uri if URI.task?(uri) and wait
- metadata true
+ metadata true
@uri
end
@@ -173,7 +173,7 @@ module OpenTox
end
RDF_FORMATS.each do |format|
-
+
# redefine rdf parse methods for all formats e.g. parse_rdfxml
send :define_method, "parse_#{format}".to_sym do |rdf|
# TODO: parse ordered dataset
@@ -194,13 +194,13 @@ module OpenTox
end
- # redefine rdf serialization methods
+ # redefine rdf serialization methods
send :define_method, "to_#{format}".to_sym do
- @metadata[RDF.type] = RDF::OT.OrderedDataset
+ @metadata[RDF.type] = RDF::OT.OrderedDataset
create_rdf
@features.each_with_index do |feature,i|
- @rdf << [RDF::URI.new(feature.uri), RDF::URI.new(RDF.type), RDF::URI.new(RDF::OT.Feature)]
- @rdf << [RDF::URI.new(feature.uri), RDF::URI.new(RDF::OLO.index), RDF::Literal.new(i)]
+ @rdf << [RDF::URI.new(feature.uri), RDF::URI.new(RDF.type), RDF::URI.new(RDF::OT.Feature)]
+ @rdf << [RDF::URI.new(feature.uri), RDF::URI.new(RDF::OLO.index), RDF::Literal.new(i)]
end
@compounds.each_with_index do |compound,i|
@rdf << [RDF::URI.new(compound.uri), RDF::URI.new(RDF.type), RDF::URI.new(RDF::OT.Compound)]
@@ -246,8 +246,8 @@ module OpenTox
parameter.each { |k,v| ntriples << "#{p_node} <#{k}> '#{v}' .\n" }
end
@features.each_with_index do |feature,i|
- ntriples << "<#{feature.uri}> <#{RDF.type}> <#{RDF::OT.Feature}> .\n"
- ntriples << "<#{feature.uri}> <#{RDF::OLO.index}> '#{i}' .\n"
+ ntriples << "<#{feature.uri}> <#{RDF.type}> <#{RDF::OT.Feature}> .\n"
+ ntriples << "<#{feature.uri}> <#{RDF::OLO.index}> '#{i}' .\n"
end
@compounds.each_with_index do |compound,i|
ntriples << "<#{compound.uri}> <#{RDF.type}> <#{RDF::OT.Compound}> .\n"
@@ -276,21 +276,21 @@ module OpenTox
=end
# Methods for for validation service
-
+
def split( compound_indices, feats, metadata, subjectid=nil)
-
+
bad_request_error "Dataset.split : Please give compounds as indices" if compound_indices.size==0 or !compound_indices[0].is_a?(Fixnum)
bad_request_error "Dataset.split : Please give features as feature objects (given: #{feats})" if feats!=nil and feats.size>0 and !feats[0].is_a?(OpenTox::Feature)
dataset = OpenTox::Dataset.new(nil, subjectid)
dataset.metadata = metadata
dataset.features = (feats ? feats : self.features)
compound_indices.each do |c_idx|
- dataset << [ self.compounds[c_idx] ] + dataset.features.each_with_index.collect{|f,f_idx| self.data_entries[c_idx][f_idx]}
+ dataset << [ self.compounds[c_idx] ] + dataset.features.each_with_index.collect{|f,f_idx| self.data_entries[c_idx][f_idx]}
end
dataset.put
- dataset
+ dataset
end
-
+
# maps a compound-index from another dataset to a compound-index from this dataset
# mapping works as follows:
@@ -299,8 +299,8 @@ module OpenTox
# * c occurs >1 in this dataset?
# ** number of occurences is equal in both datasets? assume order is preserved(!) and map accordingly
# ** number of occurences is not equal in both datasets? cannot map, raise error
- # @param [OpenTox::Dataset] dataset that should be mapped to this dataset (fully loaded)
- # @param [Fixnum] compound_index, corresponding to dataset
+ # @param dataset [OpenTox::Dataset] dataset that should be mapped to this dataset (fully loaded)
+ # @param compound_index [Fixnum], corresponding to dataset
def compound_index( dataset, compound_index )
unless defined?(@index_map) and @index_map[dataset.uri]
map = {}
@@ -308,7 +308,7 @@ module OpenTox
self_indices = compound_indices(compound)
next unless self_indices
dataset_indices = dataset.compound_indices(compound)
- if self_indices.size==1
+ if self_indices.size==1
dataset_indices.size.times do |i|
map[dataset_indices[i]] = self_indices[0]
end
@@ -321,13 +321,13 @@ module OpenTox
raise "cannot map compound #{compound} from dataset #{dataset.uri} to dataset #{uri}, "+
"compound occurs #{dataset_indices.size} times and #{self_indices.size} times"
end
- end
+ end
@index_map = {} unless defined?(@index_map)
@index_map[dataset.uri] = map
end
@index_map[dataset.uri][compound_index]
- end
-
+ end
+
def compound_indices( compound )
unless defined?(@cmp_indices) and @cmp_indices.has_key?(compound)
@cmp_indices = {}
@@ -337,12 +337,12 @@ module OpenTox
@cmp_indices[c] = [i]
else
@cmp_indices[c] = @cmp_indices[c]+[i]
- end
+ end
end
end
@cmp_indices[compound]
end
-
+
def data_entry_value(compound_index, feature_uri)
data_entries(true) if @data_entries.empty?
col = @features.collect{|f| f.uri}.index feature_uri
diff --git a/lib/model.rb b/lib/model.rb
index a354cfa..e49eff3 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -3,8 +3,8 @@ module OpenTox
class Model
# Run a model with parameters
- # @param [Hash] params Parameters for OpenTox model
- # @param [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
+ # @param params [Hash] Parameters for OpenTox model
+ # @param wait [optional,OpenTox::Task] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
# @return [text/uri-list] Task or resource URI
def run params=nil, wait=true
uri = RestClientWrapper.post @uri, params, { :content_type => "text/uri-list", :subjectid => @subjectid}
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 305b5d9..adf0030 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -11,8 +11,8 @@ module OpenTox
# Ruby interface
# Create a new OpenTox object
- # @param [optional,String] URI
- # @param [optional,String] subjectid
+ # @param uri [optional,String] URI
+ # @param subjectid [optional,String]
# @return [OpenTox] OpenTox object
def initialize uri=nil, subjectid=nil
@rdf = RDF::Graph.new
@@ -34,7 +34,7 @@ module OpenTox
end
# Metadata values
- # @param [String] Predicate URI
+ # @param predicate [String] Predicate URI
# @return [Array, String] Predicate value(s)
def [](predicate)
return nil if metadata[predicate].nil?
@@ -42,8 +42,8 @@ module OpenTox
end
# Set a metadata entry
- # @param [String] Predicate URI
- # @param [Array, String] Predicate value(s)
+ # @param predicate [String] Predicate URI
+ # @param values [Array, String] Predicate value(s)
def []=(predicate,values)
@metadata[predicate] = [values].flatten
end
diff --git a/lib/overwrite.rb b/lib/overwrite.rb
index 1579469..fbe8f7d 100644
--- a/lib/overwrite.rb
+++ b/lib/overwrite.rb
@@ -38,19 +38,18 @@ class String
# format of text (=string params) is preserved (e.g. line breaks)
# urls are marked as links
#
- # @param [String] text this is the actual content,
- # @param [optional,String] related_links info on related resources
- # @param [optional,String] description general info
- # @param [optional,Array] post_command, infos for the post operation, object defined below
+ # @param related_links [optional,String] uri on related resources
+ # @param description [optional,String] general info
+ # @param png_image [optional,String] imagename
# @return [String] html page
def to_html(related_links=nil, description=nil, png_image=nil )
-
+
# TODO add title as parameter
title = nil #$sinatra.to($sinatra.request.env['PATH_INFO'], :full) if $sinatra
html = "<html>"
html << "<title>"+title+"</title>" if title
#html += "<img src=\""+OT_LOGO+"\"><\/img><body>"
-
+
html << "<h3>Description</h3><pre><p>"+description.link_urls+"</p></pre>" if description
html << "<h3>Related links</h3><pre><p>"+related_links.link_urls+"</p></pre>" if related_links
html << "<h3>Content</h3>" if description || related_links
@@ -60,7 +59,7 @@ class String
html << "</p></pre></body></html>"
html
end
-
+
def uri?
URI.valid?(self)
end
@@ -76,7 +75,7 @@ module URI
def self.task? uri
uri =~ /task/ and URI.valid? uri
end
-
+
def self.dataset? uri, subjectid=nil
uri =~ /dataset/ and URI.accessible? uri, subjectid=nil
end
@@ -119,7 +118,7 @@ end
class File
# @return [String] mime_type including charset using linux cmd command
- def mime_type
+ def mime_type
`file -ib #{self.path}`.chomp
end
end
@@ -138,12 +137,12 @@ module Kernel
internal_server_error "`" + cmd + "` failed.\n" + stdout + stderr unless status.success?
return stdout
rescue
- internal_server_error $!.message
+ internal_server_error $!.message
end
# @return [String] uri of task result, if task fails, an error according to task is raised
def wait_for_task uri
- if URI.task?(uri)
+ if URI.task?(uri)
t = OpenTox::Task.new uri
t.wait
unless t.completed?
diff --git a/lib/policy.rb b/lib/policy.rb
index 3e7c143..e5676ba 100644
--- a/lib/policy.rb
+++ b/lib/policy.rb
@@ -3,7 +3,7 @@ module OpenTox
#Module for policy-processing
# @see also http://www.opentox.org/dev/apis/api-1.2/AA for opentox API specs
- # Class Policies corresponds to <policies> container of an xml-policy-fle
+ # Class Policies corresponds to <policies> container of an xml-policy-file
class Policies
#Hash for policy objects see {Policy Policy}
@@ -205,12 +205,13 @@ module OpenTox
end
# Subject type LDAPUsers or LDAPGroups
+ # @return [String]
def type
@subject.type
end
# Set subject type <LDAPUsers, LDAPGroups>
- # @param [String],type
+ # @param type [String] the subjecttype
def type=(type)
@subject.type = type
end
@@ -221,19 +222,19 @@ module OpenTox
end
# sets LDAP Distinguished Name (DN) for policy e.g.
- # @param [String],LDAPString
+ # @param value [String] LDAPString
def value=(value)
@subject.value = value
end
# uri affected by policy
- # @return uri affected by policy
+ # @return [String] uri affected by policy
def uri
@rule.uri
end
# sets uri affected by policy
- # @param [String] set URI
+ # @param uri [String] set URI
def uri=(uri)
@rule.uri = uri
end
@@ -251,14 +252,14 @@ module OpenTox
end
# helper method sets value and type to opentox LDAP Distinguished Name (DN) of a user
- # @param [String]Username set a username into LDAP DN
+ # @param username [String] set a username into LDAP DN
def set_ot_user(username)
self.value = "uid=#{username},ou=people,dc=opentox,dc=org"
self.type = "LDAPUsers"
true
end
- # @param [String]Username set a groupname into LDAP DN
+ # @param groupname [String] Username set a groupname into LDAP DN
def set_ot_group(groupname)
self.value = "cn=#{groupname},ou=groups,dc=opentox,dc=org"
self.type = "LDAPGroups"
@@ -277,7 +278,7 @@ module OpenTox
end
#Set Rule attribute for request-method GET
- # @param [String]value (allow,deny,nil)
+ # @param value [String] (allow,deny,nil)
def get=(value)
@get = check_value(value, @get)
end
diff --git a/lib/validation.rb b/lib/validation.rb
index c4f6868..cb73ce6 100644
--- a/lib/validation.rb
+++ b/lib/validation.rb
@@ -2,7 +2,7 @@ require "yaml"
module OldOpenTox
attr_accessor :metadata, :uri
-
+
def initialize(uri=nil)
@metadata = {}
self.uri = uri if uri
@@ -13,17 +13,17 @@ module OldOpenTox
yaml = OpenTox::RestClientWrapper.get(uri,nil,{:subjectid => subjectid, :accept => "application/x-yaml"})
@metadata = YAML.load(yaml)
end
-
+
def delete (subjectid=nil)
OpenTox::RestClientWrapper.delete(@uri.to_s,nil,{:subjectid => subjectid})
end
end
module OpenTox
-
+
class Validation
include OldOpenTox
-
+
# find validation, raises error if not found
# @param [String] uri
# @param [String,optional] subjectid
@@ -33,10 +33,10 @@ module OpenTox
val.load_metadata( subjectid )
val
end
-
+
# returns a filtered list of validation uris
- # @param [Hash,optional] params, validation-params to filter the uris (could be model, training_dataset, ..)
- # @return [Array]
+ # @param params [Hash,optional] validation-params to filter the uris (could be model, training_dataset, ..)
+ # @return [Array]
def self.list( params={} )
filter_string = ""
params.each do |k,v|
@@ -46,7 +46,7 @@ module OpenTox
end
(OpenTox::RestClientWrapper.get($validation[:uri]+filter_string).split("\n"))
end
-
+
# creates a training test split validation, waits until it finishes, may take some time
# @param [Hash] params (required:algorithm_uri,dataset_uri,prediction_feature, optional:algorithm_params,split_ratio(0.67),random_seed(1))
# @param [String,optional] subjectid
@@ -58,7 +58,7 @@ module OpenTox
params,{:content_type => "text/uri-list"},waiting_task )
Validation.new(wait_for_task(uri))
end
-
+
# creates a training test validation, waits until it finishes, may take some time
# @param [Hash] params (required:algorithm_uri,training_dataset_uri,prediction_feature,test_dataset_uri,optional:algorithm_params)
# @param [String,optional] subjectid
@@ -70,7 +70,7 @@ module OpenTox
params,{:content_type => "text/uri-list"},waiting_task )
Validation.new(wait_for_task(uri))
end
-
+
# creates a bootstrapping validation, waits until it finishes, may take some time
# @param [Hash] params (required:algorithm_uri,dataset_uri,prediction_feature, optional:algorithm_params,random_seed(1))
# @param [String,optional] subjectid
@@ -82,7 +82,7 @@ module OpenTox
params,{:content_type => "text/uri-list"},waiting_task )
Validation.new(wait_for_task(uri))
end
-
+
# looks for report for this validation, creates a report if no report is found
# @param [String,optional] subjectid
# @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
@@ -92,20 +92,20 @@ module OpenTox
@report = ValidationReport.create(@uri, {}, subjectid, waiting_task) unless @report
@report.uri
end
-
+
# creates a validation object from crossvaldiation statistics, raise error if not found
# (as crossvaldiation statistics are returned as an average valdidation over all folds)
- # @param [String] crossvalidation uri
+ # @param crossvalidation_uri [String] crossvalidation uri
# @param [String,optional] subjectid
# @return [OpenTox::Validation]
def self.from_cv_statistics( crossvalidation_uri, subjectid=nil )
find( File.join(crossvalidation_uri, 'statistics'),subjectid )
end
-
+
# returns confusion matrix as array, predicted values are in rows
# example:
# [[nil,"active","moderate","inactive"],["active",1,3,99],["moderate",4,2,8],["inactive",3,8,6]]
- # -> 99 inactive compounds have been predicted as active
+ # -> 99 inactive compounds have been predicted as active
def confusion_matrix
raise "no classification statistics, probably a regression valdiation" unless @metadata[RDF::OT.classificationStatistics]
matrix = @metadata[RDF::OT.classificationStatistics][RDF::OT.confusionMatrix][RDF::OT.confusionMatrixCell]
@@ -124,38 +124,38 @@ module OpenTox
end
table
end
-
+
# returns probability-distribution for a given prediction
# it takes all predictions into account that have a confidence value that is >= confidence and that have the same predicted value
# (minimum 12 predictions with the hightest confidence are selected (even if the confidence is lower than the given param)
- #
- # @param [Float] confidence value (between 0 and 1)
- # @param [String] predicted value
- # @param [String,optional] subjectid
+ #
+ # @param confidence [Float] confidence value (between 0 and 1)
+ # @param prediction [String] predicted value
+ # @param subjectid [String,optional]
# @return [Hash] see example
#
# Example 1:
- # validation.probabilities(0.3,"active")
- # -> {:min_confidence=>0.32, :num_predictions=>20, :probs=>{"active"=>0.7, "moderate"=>0.25 "inactive"=>0.05}}
+ # validation.probabilities(0.3,"active")
+ # -> { :min_confidence=>0.32, :num_predictions=>20, :probs=>{"active"=>0.7, "moderate"=>0.25 "inactive"=>0.05 } }
# there have been 20 "active" predictions with confidence >= 0.3, 70 percent of them beeing correct
#
# Example 2:
- # validation.probabilities(0.8,"active")
- # -> {:min_confidence=>0.45, :num_predictions=>12, :probs=>{"active"=>0.9, "moderate"=>0.1 "inactive"=>0}}
+ # validation.probabilities(0.8,"active")
+ # -> { :min_confidence=>0.45, :num_predictions=>12, :probs=>{"active"=>0.9, "moderate"=>0.1 "inactive"=>0 } }
# the given confidence value was to high (i.e. <12 predictions with confidence value >= 0.8)
# the top 12 "active" predictions have a min_confidence of 0.45, 90 percent of them beeing correct
- #
+ #
def probabilities( confidence, prediction, subjectid=nil )
YAML.load(OpenTox::RestClientWrapper.get(@uri+"/probabilities?prediction="+prediction.to_s+"&confidence="+confidence.to_s,nil,
{:subjectid => subjectid, :accept => "application/x-yaml"}))
end
end
-
+
class Crossvalidation
include OldOpenTox
attr_reader :report
-
+
# find crossvalidation, raises error if not found
# @param [String] uri
# @param [String,optional] subjectid
@@ -165,10 +165,10 @@ module OpenTox
cv.load_metadata( subjectid )
cv
end
-
+
# returns a filtered list of crossvalidation uris
- # @param [Hash,optional] params, crossvalidation-params to filter the uris (could be algorithm, dataset, ..)
- # @return [Array]
+ # @param params [Hash,optional] crossvalidation-params to filter the uris (could be algorithm, dataset, ..)
+ # @return [Array]
def self.list( params={} )
filter_string = ""
params.each do |k,v|
@@ -201,29 +201,29 @@ module OpenTox
@report = CrossvalidationReport.create(@uri, subjectid, waiting_task) unless @report
@report.uri
end
-
+
# loads metadata via yaml from crossvalidation object
# fields (like for example the validations) can be acces via validation.metadata[RDF::OT.validation]
def load_metadata( subjectid=nil )
@metadata = YAML.load(OpenTox::RestClientWrapper.get(uri,nil,{:subjectid => subjectid, :accept => "application/x-yaml"}))
end
-
+
# returns a Validation object containing the statistics of the crossavlidation
def statistics( subjectid=nil )
Validation.from_cv_statistics( @uri, subjectid )
end
-
+
# documentation see OpenTox::Validation.probabilities
def probabilities( confidence, prediction, subjectid=nil )
YAML.load(OpenTox::RestClientWrapper.get(@uri+"/statistics/probabilities?prediction="+prediction.to_s+"&confidence="+confidence.to_s,nil,
{:subjectid => subjectid, :accept => "application/x-yaml"}))
end
-
+
end
-
+
class ValidationReport
include OldOpenTox
-
+
# finds ValidationReport via uri, raises error if not found
# @param [String] uri
# @param [String,optional] subjectid
@@ -234,23 +234,23 @@ module OpenTox
rep.load_metadata( subjectid )
rep
end
-
+
# finds ValidationReport for a particular validation
- # @param [String] crossvalidation uri
- # @param [String,optional] subjectid
+ # @param validation_uri [String] crossvalidation uri
+ # @param subjectid [String,optional]
# @return [OpenTox::ValidationReport] nil if no report found
def self.find_for_validation( validation_uri, subjectid=nil )
uris = RestClientWrapper.get(File.join($validation[:uri],
"/report/validation?validation="+validation_uri),nil,{:subjectid => subjectid}).chomp.split("\n")
uris.size==0 ? nil : ValidationReport.new(uris[-1])
end
-
+
# creates a validation report via validation
- # @param [String] validation uri
- # @param [Hash] params addiditonal possible
+ # @param validation_uri [String] validation uri
+ # @param params [Hash] params addiditonal possible
# (min_confidence, params={}, min_num_predictions, max_num_predictions)
- # @param [String,optional] subjectid
- # @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
+ # @param subjectid [String,optional]
+ # @param waiting_task [OpenTox::Task,optional] (can be a OpenTox::Subtask as well), progress is updated accordingly
# @return [OpenTox::ValidationReport]
def self.create( validation_uri, params={}, subjectid=nil, waiting_task=nil )
params = {} if params==nil
@@ -262,12 +262,12 @@ module OpenTox
uri = wait_for_task(uri)
ValidationReport.new(uri)
end
-
+
end
class CrossvalidationReport
include OldOpenTox
-
+
# finds CrossvalidationReport via uri, raises error if not found
# @param [String] uri
# @param [String,optional] subjectid
@@ -278,21 +278,21 @@ module OpenTox
rep.load_metadata( subjectid )
rep
end
-
+
# finds CrossvalidationReport for a particular crossvalidation
- # @param [String] crossvalidation uri
- # @param [String,optional] subjectid
+ # @param crossvalidation_uri [String] crossvalidation uri
+ # @param subjectid [String,optional]
# @return [OpenTox::CrossvalidationReport] nil if no report found
def self.find_for_crossvalidation( crossvalidation_uri, subjectid=nil )
uris = RestClientWrapper.get(File.join($validation[:uri],
"/report/crossvalidation?crossvalidation="+crossvalidation_uri),nil,{:subjectid => subjectid}).chomp.split("\n")
uris.size==0 ? nil : CrossvalidationReport.new(uris[-1])
end
-
+
# creates a crossvalidation report via crossvalidation
- # @param [String] crossvalidation uri
- # @param [String,optional] subjectid
- # @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
+ # @param crossvalidation_uri [String] crossvalidation uri
+ # @param subjectid [String,optional]
+ # @param waiting_task [OpenTox::Task,optional] (can be a OpenTox::Subtask as well), progress is updated accordingly
# @return [OpenTox::CrossvalidationReport]
def self.create( crossvalidation_uri, subjectid=nil, waiting_task=nil )
uri = RestClientWrapper.post(File.join($validation[:uri],"/report/crossvalidation"),
@@ -301,11 +301,11 @@ module OpenTox
CrossvalidationReport.new(uri)
end
end
-
-
+
+
class AlgorithmComparisonReport
include OldOpenTox
-
+
# finds AlgorithmComparisonReport via uri, raises error if not found
# @param [String] uri
# @param [String,optional] subjectid
@@ -316,23 +316,23 @@ module OpenTox
rep.load_metadata( subjectid )
rep
end
-
+
# finds AlgorithmComparisonReport for a particular crossvalidation
- # @param [String] crossvalidation uri
- # @param [String,optional] subjectid
+ # @param crossvalidation_uri [String] crossvalidation uri
+ # @param subjectid [String,optional]
# @return [OpenTox::AlgorithmComparisonReport] nil if no report found
def self.find_for_crossvalidation( crossvalidation_uri, subjectid=nil )
uris = RestClientWrapper.get(File.join($validation[:uri],
"/report/algorithm_comparison?crossvalidation="+crossvalidation_uri),nil,{:subjectid => subjectid}).chomp.split("\n")
uris.size==0 ? nil : AlgorithmComparisonReport.new(uris[-1])
end
-
+
# creates a algorithm comparison report via crossvalidation uris
- # @param [Hash] crossvalidation uri_hash, see example
- # @param [Hash] params addiditonal possible
+ # @param crossvalidation_uri_hash [Hash] crossvalidation uri_hash, see example
+ # @param params [Hash] params addiditonal possible
# (ttest_significance, ttest_attributes, min_confidence, min_num_predictions, max_num_predictions)
- # @param [String,optional] subjectid
- # @param [OpenTox::Task,optional] waiting_task (can be a OpenTox::Subtask as well), progress is updated accordingly
+ # @param subjectid [String,optional]
+ # @param waiting_task [OpenTox::Task,optional] (can be a OpenTox::Subtask as well), progress is updated accordingly
# @return [OpenTox::AlgorithmComparisonReport]
# example for hash:
# { :lazar-bbrc => [ http://host/validation/crossvalidation/x1, http://host/validation/crossvalidation/x2 ],
@@ -355,7 +355,7 @@ module OpenTox
uri = wait_for_task(uri)
AlgorithmComparisonReport.new(uri)
end
- end
-
+ end
+
end