summaryrefslogtreecommitdiff
path: root/feature_generation.rb
blob: e8224047ee788ed3945226d5ef53ba1808ff915b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
# Get list if pc descriptor calculation algorithms
#
# @return [text/uri-list] URIs of pc descriptor calculation algorithms
get '/pcdesc' do
algorithm = OpenTox::Algorithm::Generic.new(url_for('/pcdesc',:full))
  algorithm.metadata = {
    DC.title => 'Physico-chemical (PC) descriptor calculation',
    DC.creator => "andreas@maunz.de, vorgrimmlerdavid@gmx.de",
    RDF.type => [OT.Algorithm,OTA.DescriptorCalculation],
    OT.parameters => [
      { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" },
      { DC.description => "PC type", OT.paramScope => "mandatory", DC.title => "pc_type" },
  ]
  }
  case request.env['HTTP_ACCEPT']
  when /text\/html/
    content_type "text/html"
    OpenTox.text_to_html algorithm.to_yaml
  when /application\/x-yaml/
    content_type "application/x-yaml"
    algorithm.to_yaml
  else
    response['Content-Type'] = 'application/rdf+xml'  
    algorithm.to_rdfxml
  end
end

# Run pc descriptor calculation algorithm on dataset
#
# @param [String] dataset_uri URI of the training dataset
# @param [String] feature_dataset_uri URI of the feature dataset
# @return [text/uri-list] Task URI
post '/pcdesc' do
  response['Content-Type'] = 'text/uri-list'
  raise OpenTox::NotFoundError.new "Please submit a dataset_uri." unless params[:dataset_uri]
  raise "No PC type given" unless params["pc_type"]

  task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do |task|
    types = params[:pc_type].split(",")
    if types.include?("joelib")
      Rjb.load(nil,["-Xmx64m"]) 
      s = Rjb::import('JoelibFc')
    end
    OpenTox::Algorithm.pc_descriptors( { :dataset_uri => params[:dataset_uri], :pc_type => params[:pc_type], :rjb => s, :task => task } )
  end
  raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled"
  halt 202,task.uri.to_s+"\n"
end