lazar-gui 1.3.1 → 1.4.0.pre.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/FAQ.md +9 -6
  4. data/Gemfile +2 -2
  5. data/README.md +19 -8
  6. data/VERSION +1 -1
  7. data/api/api.json +1000 -0
  8. data/application.rb +269 -206
  9. data/config.ru +7 -2
  10. data/docker/Dockerfile +73 -0
  11. data/docker/start.sh +12 -0
  12. data/docker/swagger.html +107 -0
  13. data/helper.rb +46 -1
  14. data/lazar-gui.gemspec +6 -6
  15. data/lib/api.rb +29 -0
  16. data/lib/compound.rb +68 -0
  17. data/lib/dataset.rb +33 -0
  18. data/lib/endpoint.rb +23 -0
  19. data/lib/feature.rb +29 -0
  20. data/lib/model.rb +152 -0
  21. data/lib/report.rb +29 -0
  22. data/lib/substance.rb +34 -0
  23. data/lib/swagger.rb +3 -0
  24. data/lib/validation.rb +67 -0
  25. data/public/fonts/FontAwesome.otf +0 -0
  26. data/public/fonts/fontawesome-webfont.eot +0 -0
  27. data/public/fonts/fontawesome-webfont.svg +2671 -0
  28. data/public/fonts/fontawesome-webfont.ttf +0 -0
  29. data/public/fonts/fontawesome-webfont.woff +0 -0
  30. data/public/fonts/fontawesome-webfont.woff2 +0 -0
  31. data/public/images/orn-logo.jpg +0 -0
  32. data/public/javascripts/bootstrap.js +3944 -0
  33. data/public/javascripts/google_analytics_lazar.js +2 -2
  34. data/public/javascripts/jquery.min.js +2 -0
  35. data/public/javascripts/lazar-gui.js +313 -0
  36. data/public/javascripts/pagination.min.js +11 -0
  37. data/public/javascripts/popper.min.js +5 -0
  38. data/public/stylesheets/bootstrap.min.css +7 -0
  39. data/public/stylesheets/bootstrap.min.css.map +1 -0
  40. data/public/stylesheets/font-awesome.min.css +4 -0
  41. data/public/stylesheets/pagination.css +1 -0
  42. data/qmrf_report.rb +64 -14
  43. data/task.rb +68 -0
  44. data/unicorn.rb +0 -1
  45. data/views/batch.haml +48 -107
  46. data/views/details.haml +10 -2
  47. data/views/error.haml +4 -5
  48. data/views/faq.haml +6 -2
  49. data/views/help.haml +68 -0
  50. data/views/info.haml +3 -2
  51. data/views/layout.haml +68 -78
  52. data/views/model_details.haml +179 -144
  53. data/views/neighbors.haml +98 -80
  54. data/views/predict.haml +43 -178
  55. data/views/prediction.haml +109 -102
  56. data/views/style.scss +44 -37
  57. data/views/upload.haml +28 -0
  58. metadata +51 -105
  59. data/public/css/bootstrap-theme.min.css +0 -5
  60. data/public/css/bootstrap.min.css +0 -5
  61. data/public/css/bootstrap.vertical-tabs.min.css +0 -1
  62. data/public/css/images/black-asc.gif +0 -0
  63. data/public/css/images/black-desc.gif +0 -0
  64. data/public/css/images/black-unsorted.gif +0 -0
  65. data/public/css/images/bootstrap-black-unsorted.png +0 -0
  66. data/public/css/images/bootstrap-white-unsorted.png +0 -0
  67. data/public/css/images/dragtable-handle.png +0 -0
  68. data/public/css/images/dragtable-handle.svg +0 -7
  69. data/public/css/images/dropbox-asc-hovered.png +0 -0
  70. data/public/css/images/dropbox-asc.png +0 -0
  71. data/public/css/images/dropbox-desc-hovered.png +0 -0
  72. data/public/css/images/dropbox-desc.png +0 -0
  73. data/public/css/images/first.png +0 -0
  74. data/public/css/images/green-asc.gif +0 -0
  75. data/public/css/images/green-desc.gif +0 -0
  76. data/public/css/images/green-header.gif +0 -0
  77. data/public/css/images/green-unsorted.gif +0 -0
  78. data/public/css/images/ice-asc.gif +0 -0
  79. data/public/css/images/ice-desc.gif +0 -0
  80. data/public/css/images/ice-unsorted.gif +0 -0
  81. data/public/css/images/last.png +0 -0
  82. data/public/css/images/loading.gif +0 -0
  83. data/public/css/images/metro-black-asc.png +0 -0
  84. data/public/css/images/metro-black-desc.png +0 -0
  85. data/public/css/images/metro-loading.gif +0 -0
  86. data/public/css/images/metro-unsorted.png +0 -0
  87. data/public/css/images/metro-white-asc.png +0 -0
  88. data/public/css/images/metro-white-desc.png +0 -0
  89. data/public/css/images/next.png +0 -0
  90. data/public/css/images/prev.png +0 -0
  91. data/public/css/images/white-asc.gif +0 -0
  92. data/public/css/images/white-desc.gif +0 -0
  93. data/public/css/images/white-unsorted.gif +0 -0
  94. data/public/css/jquery-ui.css +0 -1225
  95. data/public/css/jquery-ui.theme.min.css +0 -5
  96. data/public/css/theme.bootstrap.css +0 -158
  97. data/public/css/theme.bootstrap.min.css +0 -1
  98. data/public/css/theme.default.min.css +0 -1
  99. data/public/fonts/glyphicons-halflings-regular.eot +0 -0
  100. data/public/fonts/glyphicons-halflings-regular.svg +0 -288
  101. data/public/fonts/glyphicons-halflings-regular.ttf +0 -0
  102. data/public/fonts/glyphicons-halflings-regular.woff +0 -0
  103. data/public/fonts/glyphicons-halflings-regular.woff2 +0 -0
  104. data/public/images/Email.png +0 -0
  105. data/public/images/Facebook.png +0 -0
  106. data/public/images/Google+.png +0 -0
  107. data/public/images/LinkedIn.png +0 -0
  108. data/public/images/OpenToxEuro2013_small.png +0 -0
  109. data/public/images/Twitter.png +0 -0
  110. data/public/images/arrow_down_float.png +0 -0
  111. data/public/images/arrow_left_float.png +0 -0
  112. data/public/images/arrow_right_float.png +0 -0
  113. data/public/images/arrow_up_float.png +0 -0
  114. data/public/images/asc.gif +0 -0
  115. data/public/images/bg.gif +0 -0
  116. data/public/images/desc.gif +0 -0
  117. data/public/images/gray_jean.png +0 -0
  118. data/public/images/info_white.png +0 -0
  119. data/public/javascripts/bootstrap.min.js +0 -7
  120. data/public/javascripts/jquery-1.11.2.min.js +0 -4
  121. data/public/javascripts/jquery-1.8.3.min.js +0 -2
  122. data/public/javascripts/jquery-ui-1.10.3.custom.min.js +0 -6
  123. data/public/javascripts/jquery.bpopup.min.js +0 -7
  124. data/public/javascripts/jquery.tablesorter.min.js +0 -2
  125. data/public/javascripts/jquery.tablesorter.widgets.js +0 -2678
  126. data/public/javascripts/jquery.tools.min.js +0 -5
  127. data/public/rect.png +0 -0
  128. data/test/lazarweb.rb +0 -193
  129. data/test/setup.rb +0 -7
  130. data/views/significant_fragments.haml +0 -66
data/config.ru CHANGED
@@ -1,6 +1,11 @@
1
+ ENV["BATCH_MODE"] = "true"
1
2
  ENV["LAZAR_ENV"] = "production"
2
- require 'bundler'
3
- Bundler.require
3
+ require "lazar"
4
+ require "qsar-report"
5
+ require "sinatra"
6
+ require "haml"
7
+ require "sass"
8
+ require "rdiscount"
4
9
  require File.expand_path './application.rb'
5
10
  require "sinatra/reloader" if development?
6
11
  run Sinatra::Application
data/docker/Dockerfile ADDED
@@ -0,0 +1,73 @@
1
+ FROM archlinux/base
2
+ MAINTAINER in-silico toxicology Gmbh
3
+
4
+ RUN pacman-db-upgrade
5
+ RUN pacman -Syyu --noconfirm
6
+ RUN pacman -S --noconfirm \
7
+ base-devel \
8
+ boost-libs \
9
+ cmake \
10
+ eigen3 \
11
+ fontconfig \
12
+ gcc-fortran \
13
+ git \
14
+ gsl \
15
+ jre10-openjdk-headless \
16
+ r \
17
+ ruby \
18
+ swig \
19
+ python-pip \
20
+ catdoc \
21
+ wget
22
+ RUN pacman -Scc --noconfirm
23
+
24
+ RUN R -e "install.packages('Rserve', repos='http://rforge.net/')"
25
+ RUN pip install xlsx2csv
26
+ RUN useradd -ms /bin/bash ist
27
+
28
+ # mongodb has been removed from main repositories
29
+ USER ist
30
+ WORKDIR /home/ist
31
+ RUN mkdir data
32
+ RUN mkdir src
33
+ WORKDIR /home/ist/src
34
+ RUN wget https://aur.archlinux.org/cgit/aur.git/snapshot/mongodb-bin.tar.gz
35
+ RUN tar -xvzf mongodb-bin.tar.gz
36
+ WORKDIR /home/ist/src/mongodb-bin
37
+ RUN makepkg -s --noconfirm
38
+
39
+ # installation requires root
40
+ USER root
41
+ RUN pacman -U --noconfirm /home/ist/src/mongodb-bin/mongodb-bin*.pkg.tar.xz
42
+
43
+ # install lazar-gui gem
44
+ RUN echo 'gem: --no-document' > /etc/gemrc
45
+
46
+ #RUN gem install lazar-gui
47
+ RUN gem install lazar
48
+ RUN gem install qsar-report
49
+ RUN gem install sinatra haml sass rdiscount unicorn
50
+
51
+ USER ist
52
+ WORKDIR /home/ist
53
+ RUN rm -r src
54
+
55
+ # lazar-gui
56
+ RUN git clone https://git.in-silico.ch/lazar-gui
57
+ WORKDIR lazar-gui
58
+ RUN git checkout prerelease
59
+
60
+ # SWAGGER for API
61
+ WORKDIR /home/ist
62
+ RUN git clone https://github.com/swagger-api/swagger-ui.git
63
+ COPY swagger.html /home/ist/swagger-ui/dist/index.html
64
+
65
+ # TODO adjust to lazar-gui gem path
66
+ RUN ln -s /home/ist/swagger-ui/dist/swagger-ui-bundle.js /home/ist/lazar-gui/public/swagger-ui-bundle.js
67
+ RUN ln -s /home/ist/swagger-ui/dist/swagger-ui-standalone-preset.js /home/ist/lazar-gui/public/swagger-ui-standalone-preset.js
68
+ RUN ln -s /home/ist/swagger-ui/dist/swagger-ui.css /home/ist/lazar-gui/public/swagger-ui.css
69
+
70
+ # start script
71
+ COPY start.sh /home/ist/start.sh
72
+
73
+ ENTRYPOINT ["/home/ist/start.sh"]
data/docker/start.sh ADDED
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+
3
+ # start basic services
4
+ mongod --bind_ip 127.0.0.1 --dbpath ~/data &
5
+ R CMD Rserve --vanilla &
6
+
7
+ # import data
8
+ ruby -e "require 'lazar'; include OpenTox; Import.public_data"
9
+
10
+ # start lazar service
11
+ cd $HOME/lazar-gui
12
+ unicorn -p 8088 -E production
@@ -0,0 +1,107 @@
1
+ <!-- HTML for static distribution bundle build -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>Swagger UI</title>
7
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
8
+ <link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
9
+ <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
10
+ <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
11
+ <style>
12
+ html
13
+ {
14
+ box-sizing: border-box;
15
+ overflow: -moz-scrollbars-vertical;
16
+ overflow-y: scroll;
17
+ }
18
+
19
+ *,
20
+ *:before,
21
+ *:after
22
+ {
23
+ box-sizing: inherit;
24
+ }
25
+
26
+ body
27
+ {
28
+ margin:0;
29
+ background: #fafafa;
30
+ }
31
+ </style>
32
+ </head>
33
+
34
+ <body>
35
+ <div id="swagger-ui"></div>
36
+
37
+ <script src="./swagger-ui-bundle.js"> </script>
38
+ <script src="./swagger-ui-standalone-preset.js"> </script>
39
+ <script>
40
+ window.onload = function() {
41
+
42
+ // Build a system
43
+ var base_url = window.location.origin;
44
+ var swagger_url = base_url + "/api/api.json";
45
+ const ui = SwaggerUIBundle({
46
+ url: swagger_url,
47
+ dom_id: '#swagger-ui',
48
+ deepLinking: true,
49
+ presets: [
50
+ SwaggerUIBundle.presets.apis,
51
+ SwaggerUIStandalonePreset
52
+ ],
53
+ plugins: [
54
+ SwaggerUIBundle.plugins.DownloadUrl
55
+ ],
56
+ layout: "StandaloneLayout"
57
+ })
58
+
59
+ window.ui = ui;
60
+ document.getElementsByClassName('topbar')[0].style.backgroundColor = "#fafafa";
61
+ document.getElementsByClassName('topbar-wrapper')[0].getElementsByTagName('img')[0].alt = "IST";
62
+ document.getElementsByClassName('topbar-wrapper')[0].getElementsByTagName('img')[0].src = "./IST_logo_s.png";
63
+ document.getElementsByClassName('topbar-wrapper')[0].getElementsByTagName('img')[0].width = "90";
64
+ document.getElementsByClassName('topbar-wrapper')[0].getElementsByTagName('img')[0].height = "35";
65
+ document.getElementsByClassName('topbar-wrapper')[0].getElementsByTagName('img')[0].style.marginRight = "20px";
66
+ document.getElementsByClassName('topbar-wrapper')[0].getElementsByTagName('span')[0].innerHTML = "lazar-rest-api";
67
+ };
68
+
69
+ // add link for docs
70
+ setTimeout(function() {
71
+ var base_url = window.location.origin;
72
+ var section = document.getElementsByClassName("info")[0];
73
+ var node = document.createElement("docs");
74
+ var heading = document.createElement('h2');
75
+ var headingtext = document.createTextNode("Documentation");
76
+ var link = document.createElement('a');
77
+ var linktext = document.createTextNode("See curl examples for a typical workflow.");
78
+ heading.appendChild(headingtext);
79
+ link.appendChild(linktext);
80
+ link.title = "curl examples";
81
+ link.href = "https://github.com/OpenRiskNet/home/blob/master/openshift/deployments/lazar#curl-examples";
82
+ link.target = "javascript:void(0);";
83
+ node.appendChild(heading);
84
+ node.appendChild(link);
85
+ section.appendChild(node);
86
+ }, 1000);
87
+ // add link for gui
88
+ setTimeout(function() {
89
+ var base_url = window.location.origin;
90
+ var section = document.getElementsByClassName("info")[0];
91
+ var node = document.createElement("gui");
92
+ var heading = document.createElement('h2');
93
+ var headingtext = document.createTextNode("Lazar Graphical User Interface");
94
+ var link = document.createElement('a');
95
+ var linktext = document.createTextNode("Lazar (GUI)");
96
+ heading.appendChild(headingtext);
97
+ link.appendChild(linktext);
98
+ link.title = "GUI link";
99
+ link.href = base_url = "/predict";
100
+ link.target = "javascript:void(0);";
101
+ node.appendChild(heading);
102
+ node.appendChild(link);
103
+ section.appendChild(node);
104
+ }, 1000);
105
+ </script>
106
+ </body>
107
+ </html>
data/helper.rb CHANGED
@@ -1,3 +1,48 @@
1
1
  helpers do
2
-
2
+
3
+ def embedded_svg image, options={}
4
+ doc = Nokogiri::HTML::DocumentFragment.parse image
5
+ svg = doc.at_css 'svg'
6
+ title = doc.at_css 'title'
7
+ if options[:class].present?
8
+ svg['class'] = options[:class]
9
+ end
10
+ if options[:title].present?
11
+ if options[:title] == "x"
12
+ title.children.remove
13
+ else
14
+ title.children.remove
15
+ text_node = Nokogiri::XML::Text.new(options[:title], doc)
16
+ title.add_child(text_node)
17
+ end
18
+ end
19
+ doc.to_html.html_safe
20
+ end
21
+
22
+ def is_mongoid?
23
+ self.match(/^[a-f\d]{24}$/i) ? true : false
24
+ end
25
+
26
+ def remove_task_data(pid)
27
+ task = Task.find_by(:pid => pid)
28
+ if task and !task.subTasks.blank?
29
+ task.subTasks.each_with_index do |task_id,idx|
30
+ t = Task.find task_id
31
+ predictionDataset = Dataset.find t.dataset_id if t.dataset_id
32
+ if predictionDataset && idx == 0
33
+ trainingDataset = Dataset.find predictionDataset.source
34
+ predictionDataset.delete
35
+ # delete training dataset unless it is one used for prediction models
36
+ models = Model::Validation.all
37
+ training_datasets = models.collect{|m| m.training_dataset.id.to_s}
38
+ trainingDataset.delete unless training_datasets.include?(trainingDataset.id.to_s)
39
+ elsif predictionDataset
40
+ predictionDataset.delete
41
+ end
42
+ t.delete
43
+ end
44
+ end
45
+ task.delete if task
46
+ end
47
+
3
48
  end
data/lazar-gui.gemspec CHANGED
@@ -5,23 +5,23 @@ Gem::Specification.new do |s|
5
5
  s.version = File.read("./VERSION")
6
6
  s.authors = ["Christoph Helma","Denis Gebele"]
7
7
  s.email = ["helma@in-silico.ch","gebele@in-silico.ch"]
8
- s.homepage = "http://github.com/opentox/lazar-gui"
8
+ s.homepage = "http://git.in-silico.ch/lazar-gui"
9
9
  s.summary = %q{lazar-gui}
10
- s.description = %q{Graphical User Interface for Lazar Toxicology Predictions}
10
+ s.description = %q{Graphical User Interface for Lazar Toxicity Predictions}
11
11
  s.license = 'GPL-3.0'
12
12
  s.executables = ["lazar-start", "lazar-stop"]
13
13
  s.rubyforge_project = "lazar-gui"
14
14
  s.files = `git ls-files`.split("\n")
15
15
 
16
- s.add_runtime_dependency "lazar"
16
+ s.add_runtime_dependency "lazar", "~> 1.1"
17
+ s.add_runtime_dependency "qsar-report", "~> 1.0"
17
18
  s.add_runtime_dependency "sinatra"
18
- s.add_runtime_dependency "sinatra-reloader"
19
19
  s.add_runtime_dependency "rdiscount"
20
20
  s.add_runtime_dependency "haml"
21
21
  s.add_runtime_dependency "sass"
22
22
  s.add_runtime_dependency "unicorn"
23
- s.add_runtime_dependency "qsar-report"
24
- s.add_runtime_dependency "gem-path"
23
+ s.add_development_dependency "sinatra-reloader"
24
+ #s.add_runtime_dependency "gem-path"
25
25
 
26
26
  s.post_install_message = %q{
27
27
  Service commands:
data/lib/api.rb ADDED
@@ -0,0 +1,29 @@
1
+ get "/api" do
2
+ api_file = File.join("api", "api.json")
3
+ `sed -i 's/SERVER_URI/#{request.env['HTTP_HOST']}/' #{api_file}`
4
+ halt 400, "API Documentation in Swagger JSON is not implemented." unless File.exists?(api_file)
5
+ case @accept
6
+ when "text/html"
7
+ response['Content-Type'] = "text/html"
8
+ index_file = File.join(ENV['HOME'],"swagger-ui/dist/index.html")
9
+ return File.read(index_file)
10
+ when "application/json"
11
+ redirect("/api/api.json")
12
+ else
13
+ halt 400, "unknown MIME type '#{@accept}'"
14
+ end
15
+ end
16
+
17
+ get "/api/api.json" do
18
+ api_file = File.join("api", "api.json")
19
+ `sed -i 's/SERVER_URI/#{request.env['HTTP_HOST']}/' #{api_file}`
20
+ case @accept
21
+ when "text/html"
22
+ response['Content-Type'] = "application/json"
23
+ return File.read(api_file)
24
+ when "application/json"
25
+ return File.read(api_file)
26
+ else
27
+ halt 400, "unknown MIME type '#{@accept}'"
28
+ end
29
+ end
data/lib/compound.rb ADDED
@@ -0,0 +1,68 @@
1
+ # Get a list of a single or all descriptors
2
+ # @param [Header] Accept one of text/plain, application/json
3
+ # @param [Path] Descriptor name or descriptor ID (e.G.: Openbabel.HBA1, 5755f8eb3cf99a00d8fedf2f)
4
+ # @return [text/plain, application/json] list of all prediction models
5
+ get "/api/compound/descriptor/?:descriptor?" do
6
+ case @accept
7
+ when "application/json"
8
+ return "#{JSON.pretty_generate PhysChem::DESCRIPTORS} " unless params[:descriptor]
9
+ return PhysChem.find_by(:name => params[:descriptor]).to_json if PhysChem::DESCRIPTORS.include?(params[:descriptor])
10
+ return PhysChem.find(params[:descriptor]).to_json if PhysChem.find(params[:descriptor])
11
+ else
12
+ return PhysChem::DESCRIPTORS.collect{|k, v| "#{k}: #{v}\n"} unless params[:descriptor]
13
+ return PhysChem::DESCRIPTORS[params[:descriptor]] if PhysChem::DESCRIPTORS.include?(params[:descriptor])
14
+ return "#{PhysChem.find(params[:descriptor]).name}: #{PhysChem.find(params[:descriptor]).description}" if PhysChem.find(params[:descriptor])
15
+ end
16
+ end
17
+
18
+ post "/api/compound/descriptor/?" do
19
+ bad_request_error "Missing Parameter " unless params[:identifier] && params[:descriptor]
20
+ descriptors = params['descriptor'].split(',')
21
+ compound = Compound.from_smiles params[:identifier]
22
+ physchem_descriptors = []
23
+ descriptors.each do |descriptor|
24
+ physchem_descriptors << PhysChem.find_by(:name => descriptor)
25
+ end
26
+ result = compound.calculate_properties physchem_descriptors
27
+ csv = (0..result.size-1).collect{|i| "\"#{physchem_descriptors[i].name}\",#{result[i]}"}.join("\n")
28
+ csv = "SMILES,\"#{params[:identifier]}\"\n#{csv}" if params[:identifier]
29
+ case @accept
30
+ when "text/csv","application/csv"
31
+ return csv
32
+ when "application/json"
33
+ result_hash = (0..result.size-1).collect{|i| {"#{physchem_descriptors[i].name}" => "#{result[i]}"}}
34
+ data = {"compound" => {"SMILES" => "#{params[:identifier]}"}}
35
+ data["compound"]["InChI"] = "#{compound.inchi}" if compound.inchi
36
+ data["compound"]["results"] = result_hash
37
+ return JSON.pretty_generate(data)
38
+ end
39
+ end
40
+
41
+ get %r{/api/compound/(InChI.+)} do |input|
42
+ compound = Compound.from_inchi URI.unescape(input)
43
+ if compound
44
+ response['Content-Type'] = @accept
45
+ case @accept
46
+ when "application/json"
47
+ c = {"compound": {"id": compound.id, "inchi": compound.inchi, "smiles": compound.smiles, "warnings": compound.warnings}}
48
+ return JSON.pretty_generate JSON.parse(c.to_json)
49
+ when "chemical/x-daylight-smiles"
50
+ return compound.smiles
51
+ when "chemical/x-inchi"
52
+ return compound.inchi
53
+ when "chemical/x-mdl-sdfile"
54
+ return compound.sdf
55
+ when "chemical/x-mdl-molfile"
56
+ when "image/png"
57
+ return compound.png
58
+ when "image/svg+xml"
59
+ return compound.svg
60
+ #when "text/plain"
61
+ #return "#{compound.names}\n"
62
+ else
63
+ halt 400, "Content type #{@accept} not supported."
64
+ end
65
+ else
66
+ halt 400, "Compound with #{input} not found.".to_json
67
+ end
68
+ end
data/lib/dataset.rb ADDED
@@ -0,0 +1,33 @@
1
+ # Get all datasets
2
+ get "/api/dataset/?" do
3
+ datasets = Dataset.all #.limit(100)
4
+ case @accept
5
+ when "application/json"
6
+ list = datasets.collect{|dataset| uri("/api/dataset/#{dataset.id}")}.to_json
7
+ return list
8
+ else
9
+ halt 400, "Mime type #{@accept} is not supported."
10
+ end
11
+ end
12
+
13
+ # Get a dataset
14
+ get "/api/dataset/:id/?" do
15
+ dataset = Dataset.find :id => params[:id]
16
+ halt 400, "Dataset with id: #{params[:id]} not found." unless dataset
17
+ case @accept
18
+ when "text/csv", "application/csv"
19
+ return File.read dataset.source
20
+ else
21
+ bad_request_error "Mime type #{@accept} is not supported."
22
+ end
23
+ end
24
+
25
+ # Get a dataset attribute. One of compounds, nanoparticles, substances, features
26
+ get "/api/dataset/:id/:attribute/?" do
27
+ dataset = Dataset.find :id => params[:id]
28
+ halt 400, "Dataset with id: #{params[:id]} not found." unless dataset
29
+ attribs = ["compounds", "nanoparticles", "substances", "features"]
30
+ return "Attribute '#{params[:attribute]}' is not available. Choose one of #{attribs.join(', ')}." unless attribs.include? params[:attribute]
31
+ out = dataset.send("#{params[:attribute]}")
32
+ return out.to_json
33
+ end
data/lib/endpoint.rb ADDED
@@ -0,0 +1,23 @@
1
+ # Get a list of all endpoints
2
+ # @param [Header] Accept one of text/uri-list,
3
+ # @return [text/uri-list] list of all prediction models
4
+ get "/api/endpoint/?" do
5
+ models = Model::Validation.all
6
+ endpoints = models.collect{|m| m.endpoint}.uniq
7
+ case @accept
8
+ when "text/uri-list"
9
+ return endpoints.join("\n") + "\n"
10
+ when "application/json"
11
+ return endpoints.to_json
12
+ else
13
+ halt 400, "Mime type #{@accept} is not supported."
14
+ end
15
+ end
16
+
17
+ get "/api/endpoint/:endpoint/?" do
18
+ models = Model::Validation.where(endpoint: params[:endpoint])
19
+ list = []
20
+ models.each{|m| list << {m.species => uri("/api/model/#{m.id}")} }
21
+ halt 404, "Endpoint: #{params[:endpoint]} not found." if models.blank?
22
+ return list.to_json
23
+ end