blob: 3764ee277ea264f3d262a3cdb32a0a3e42f84bde (
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
|
# Get a list of all prediction models
# @param [Header] Accept one of text/uri-list,
# @return [text/uri-list] list of all prediction models
get "/model/?" do
models = Model::Validation.all
case @accept
when "text/uri-list"
uri_list = models.collect{|model| uri("/model/#{model.id}")}
return uri_list.join("\n") + "\n"
when "application/json"
models = JSON.parse models.to_json
list = []
models.each{|m| list << uri("/model/#{m["_id"]["$oid"]}")}
return list.to_json
else
bad_request_error "Mime type #{@accept} is not supported."
end
end
get "/model/:id/?" do
model = Model::Validation.find params[:id]
not_found_error "Model with id: #{params[:id]} not found." unless model
return model.to_json
end
post "/model/:id/?" do
identifier = params[:identifier].split(",")
compounds = identifier.collect{ |i| Compound.from_smiles i.strip.gsub(/\A"|"\Z/,'') }
model = Model::Validation.find params[:id]
batch = {}
compounds.each do |compound|
prediction = model.predict(compound)
batch[compound] = {:id => compound.id, :inchi => compound.inchi, :smiles => compound.smiles, :model => model, :prediction => prediction}
end
return batch.to_json
end
|