Module: OpenTox

Included in:
Algorithm, AlgorithmComparisonReport, Compound, Crossvalidation, CrossvalidationReport, Dataset, Feature, Model, QMRFReport, Task, Validation, ValidationReport
Defined in:
lib/task.rb,
lib/error.rb,
lib/model.rb,
lib/utils.rb,
lib/parser.rb,
lib/policy.rb,
lib/r-util.rb,
lib/dataset.rb,
lib/feature.rb,
lib/opentox.rb,
lib/to-html.rb,
lib/compound.rb,
lib/ontology.rb,
lib/algorithm.rb,
lib/transform.rb,
lib/serializer.rb,
lib/validation.rb,
lib/authorization.rb,
lib/rest_client_wrapper.rb

Defined Under Namespace

Modules: Algorithm, Authorization, Model, Ontology, Parser, Serializer, Transform Classes: AlgorithmComparisonReport, BadRequestError, Compound, Crossvalidation, CrossvalidationReport, Dataset, ErrorReport, FakeSubTask, Feature, LazarPrediction, NotAuthorizedError, NotFoundError, Policies, Policy, PostAttribute, PostCommand, QMRFReport, RUtil, RestCallError, RestClientWrapper, ServiceUnavailableError, SubTask, Task, Validation, ValidationReport, WrapperResult

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#metadataObject

Returns the value of attribute metadata.



4
5
6
# File 'lib/opentox.rb', line 4

def 
  
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/opentox.rb', line 3

def uri
  @uri
end

Class Method Details

.all(uri, subjectid = nil) ⇒ Array

Get all objects from a service

Returns:

  • List of available URIs



22
23
24
# File 'lib/opentox.rb', line 22

def self.all(uri, subjectid=nil)
  RestClientWrapper.get(uri,:accept => "text/uri-list", :subjectid => subjectid).to_s.split(/\n/)
end

.sign_in(msg = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/to-html.rb', line 59

def self.( msg=nil )
  html = "<html><title>Login</title><img src="++"><body>"
  html += "<form method='POST' action='"+$url_provider.url_for("/sign_in",:full)+"'>"
  html += "<pre><p style=\"padding:15px; border:10px solid \#5D308A\">"
  html += msg+"\n\n" if msg
  html += "Please sign in to "+$url_provider.request.host.to_s+"\n\n"
  html += "<table border=0>"
  html += "<tr><td>user:</td><td><input type='text' name='user' size='15' /></td></tr>"+
        "<tr><td>password:</td><td><input type='password' name='password' size='15' /></td></tr>"+
        #"<input type=hidden name=back_to value="+back_to.to_s+">"+
        "<tr><td><input type='submit' value='Sign in' /></td></tr>"
  html += "</table></p></pre></form></body></html>"
  html
end

.text_to_html(text, subjectid = nil, related_links = nil, description = nil, post_command = nil) ⇒ String

produces a html page for making web services browser friendly format of text (=string params) is preserved (e.g. line breaks) urls are marked as links

Parameters:

  • this is the actual content,

  • (defaults to: nil)

    info on related resources

  • (defaults to: nil)

    general info

  • infos for the post operation, object defined below

Returns:

  • html page



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/to-html.rb', line 24

def self.text_to_html( text, subjectid=nil, related_links=nil, description=nil, post_command=nil  )
  
  # TODO add title as parameter
  title = nil #$sinatra.url_for($sinatra.request.env['PATH_INFO'], :full) if $sinatra
  html = "<html>"
  html += "<title>"+title+"</title>" if title
  html += "<img src=\""++"\"><\/img><body>"
    
  if AA_SERVER
    user = OpenTox::Authorization.get_user(subjectid) if subjectid
    html +=  "<pre><p align=\"right\">"
    unless user
      html += "You are currently not signed in to "+$url_provider.request.host.to_s+
        ", <a href="+$url_provider.url_for("/sign_in",:full)+">sign in</a>"
    else
      html += "You are signed in as '#{user}' to "+$url_provider.request.host.to_s+
        ", <a href="+$url_provider.url_for("/sign_out",:full)+">sign out</a>"
    end
    html += "  </p></pre>"
  end 
 
  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
  if post_command
    raise "not a post command" unless post_command.is_a?(OpenTox::PostCommand)
    html += "<h3>POST command</h3>"
    html += post_command.to_html
  end
  html += "<h3>Content</h3>" if description || related_links || post_command
  html += "<pre><p style=\"padding:15px; border:10px solid \#5D308A\">"
  html += text.link_urls
  html += "</p></pre></body></html>"
  html
end

Instance Method Details

#add_metadata(metadata) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/opentox.rb', line 33

def ()
  if !.nil?
    .each do |k,v|
      if v.is_a? Array
        [k] = [] unless [k]
        [k] << v
      else
        [k] = v 
      end
    end
  end
end

#delete(subjectid = nil) ⇒ Object

deletes the resource, deletion should have worked when no RestCallError raised



55
56
57
# File 'lib/opentox.rb', line 55

def delete(subjectid=nil)
  RestClientWrapper.delete(uri,:subjectid => subjectid)
end

#initialize(uri = nil) ⇒ Object

Initialize OpenTox object with optional uri

Parameters:



8
9
10
11
# File 'lib/opentox.rb', line 8

def initialize(uri=nil)
   = {}
  self.uri = uri if uri
end

#load_metadata(subjectid = nil) ⇒ Hash

Load (and return) metadata from object URI

Returns:

  • Metadata



28
29
30
31
# File 'lib/opentox.rb', line 28

def (subjectid=nil)
   = Parser::Owl::Generic.new(@uri).(subjectid)
  
end

#to_rdfxmlapplication/rdf+xml

Get OWL-DL representation in RDF/XML format

Returns:

  • RDF/XML representation



48
49
50
51
52
53
54
55
# File 'lib/feature.rb', line 48

def to_rdfxml
  s = Serializer::Owl.new
  s.add_feature(@uri,)
  .values.grep(/model\/\d+$/).each{ |m| s.add_uri(m,OT.Model)}
  .values.grep(/feature/).each{ |f| s.add_uri(f,OT.Feature)}
  #s.add_parameters(@uri,@parameters) if @parameters
  s.to_rdfxml
end