summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-12-20 19:25:30 +0100
committerChristoph Helma <helma@in-silico.de>2009-12-20 19:25:30 +0100
commitfb758ce73b5ca3a9f75452b971c161556309fae1 (patch)
tree9e8e8baba797d46fa021777b424b9d3ff7e5cc31
parent023a5b4bb9693bd633b4c3b1f757effc7933b731 (diff)
dataset prediction added, OWL-DL (partially) fixed
-rw-r--r--README11
-rw-r--r--lazar.rb92
2 files changed, 27 insertions, 76 deletions
diff --git a/README b/README
index 4cf5228..710aec5 100644
--- a/README
+++ b/README
@@ -9,8 +9,8 @@ REST operations:
Get a list of all lazar models GET / - List of model URIs 200
Get the representation of a lazar model GET /{id} - Model representation 200,404
-Predict a compound POST /{id} compound_uri, Prediction representation 200,404,500
- type (optional)
+Predict a compound POST /{id} compound_uri Prediction representation 200,404,500
+Predict a dataset POST /{id} dataset_uri Prediction dataset URI 200,404,500
Delete a model DELETE /{id} - - 200,404
Supported MIME formats (http://chemical-mime.sourceforge.net/):
@@ -29,8 +29,11 @@ Get the representation of a lazar model
Predict a compound
curl -X POST -d compound_uri={compound_uri} http://webservices.in-silico.ch/test/model/{id}
-Predict a compound and get the result as YAML (setting the Accept header does not work with Content-Type:application/x-www-form-urlencoded to submit parameters)
- curl -X POST -d compound_uri={compound_uri} -d type=application/x-yaml http://webservices.in-silico.ch/test/model/{id}
+Predict a compound and get the result as YAML
+ curl -X POST -H "Accept:application/x-yaml" -d compound_uri={compound_uri} http://webservices.in-silico.ch/test/model/{id}
+
+Predict a dataset
+ curl -X POST -d dataset_uri={dataset_uri} http://webservices.in-silico.ch/test/model/{id}
Delete a model
curl -X DELETE http://webservices.in-silico.ch/model/{id}
diff --git a/lazar.rb b/lazar.rb
index 5275602..c940cbe 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -12,8 +12,7 @@ get '/:id/?' do
accept = "application/rdf+xml" if accept == '*/*' or accept == '' or accept.nil?
case accept
when "application/rdf+xml"
- lazar = OpenTox::Model::Lazar.new
- lazar.read_yaml(params[:id],File.read(path))
+ lazar = OpenTox::Model::Lazar.new(path)
lazar.rdf
when /yaml/
send_file path
@@ -29,8 +28,7 @@ delete '/:id/?' do
File.delete path
"Model #{params[:id]} deleted."
else
- status 404
- "Model #{params[:id]} does not exist."
+ halt 404, "Model #{params[:id]} does not exist."
end
end
@@ -56,83 +54,33 @@ post '/?' do # create model
end
# PREDICTIONS
+# TODO predict dataset, correct owl format
post '/:id/?' do # create prediction
path = File.join("models",params[:id] + ".yaml")
halt 404, "Model #{params[:id]} does not exist." unless File.exists? path
- halt 404, "No compound_uri." unless compound_uri = params[:compound_uri]
- lazar = YAML.load_file path
- dataset = OpenTox::Dataset.new
-
- # find database activities
- if lazar[:activities][compound_uri]
- c = dataset.find_or_create_compound(compound_uri)
- f = dataset.find_or_create_feature(lazar[:endpoint])
- v = dataset.find_or_create_value lazar[:activities][compound_uri].join(',')
- dataset.add_data_entry c,f,v
- else
- #puts compound_uri
- compound = OpenTox::Compound.new(:uri => compound_uri)
- #puts compound.smiles
- #puts compound.inchi
- compound_matches = compound.match lazar[:features]
-
- conf = 0.0
- neighbors = []
- classification = nil
-
- lazar[:fingerprints].each do |uri,matches|
-
- sim = weighted_tanimoto(compound_matches,matches,lazar[:p_values])
- if sim > 0.3
- neighbors << uri
- lazar[:activities][uri].each do |act|
- case act.to_s
- when 'true'
- conf += OpenTox::Utils.gauss(sim)
- when 'false'
- conf -= OpenTox::Utils.gauss(sim)
- end
- end
- end
- end
-
- conf = conf/neighbors.size
- if conf > 0.0
- classification = true
- elsif conf < 0.0
- classification = false
+ halt 404, "No compound_uri or dataset_uri parameter." unless compound_uri = params[:compound_uri] or dataset_uri = params[:dataset_uri]
+ lazar = OpenTox::Model::Lazar.new(path)
+
+ if compound_uri
+ lazar.classify(compound_uri) unless lazar.database_activity?(compound_uri)
+ elsif dataset_uri
+ input_dataset = OpenTox::Dataset.find(dataset_uri)
+ input_dataset.compounds.each do |compound_uri|
+ lazar.classify(compound_uri) unless lazar.database_activity?(compound_uri)
end
-
- c = dataset.find_or_create_compound(compound_uri)
- f = dataset.find_or_create_feature(lazar[:endpoint] + " lazar prediction")
- v = dataset.find_or_create_value classification
- dataset.add_data_entry c,f,v
-
end
- if /yaml/ =~ params[:type]
- { :classification => classification,
- :confidence => conf,
- :neighbors => neighbors,
- :features => compound_matches
- }.to_yaml
+ case request.env['HTTP_ACCEPT']
+ when /yaml/
+ lazar.predictions.to_yaml
else
- dataset.rdf
+ if params[:compound_uri]
+ lazar.dataset.rdf
+ elsif params[:dataset_uri]
+ lazar.dataset.save
+ end
end
end
-def weighted_tanimoto(fp_a,fp_b,p)
- common_features = fp_a & fp_b
- all_features = fp_a + fp_b
- common_p_sum = 0.0
- if common_features.size > 0
- common_features.each{|f| common_p_sum += p[f]}
- all_p_sum = 0.0
- all_features.each{|f| all_p_sum += p[f]}
- common_p_sum/all_p_sum
- else
- 0.0
- end
-end