summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-06-19 16:42:02 +0200
committerChristoph Helma <helma@in-silico.ch>2013-06-19 16:42:02 +0200
commitf6106825338557274d14aab47600b0a58b8b11a9 (patch)
treee0c3a79a1254e611f6cd18f3aff2c19ad46ee50a
parent0be40680cb30d26fa961d0c47f3e0569db6c4e03 (diff)
parentad386110267ecc3e0c5301769b4880a7e555a44e (diff)
Merge branch 'development' of github.com:opentox/algorithm into development
Conflicts: descriptor.rb lazar.rb lib/dataset.rb lib/lazar.rb
-rw-r--r--application.rb6
-rw-r--r--descriptor.rb46
-rw-r--r--fminer.rb12
-rw-r--r--lazar.rb3
-rw-r--r--lib/dataset.rb32
-rw-r--r--lib/lazar.rb32
-rw-r--r--test.rb2
7 files changed, 107 insertions, 26 deletions
diff --git a/application.rb b/application.rb
index 198d3a8..1262b9e 100644
--- a/application.rb
+++ b/application.rb
@@ -17,6 +17,12 @@ Dir['./*.rb'].each { |f| require_relative f; also_reload f } # Webapps
# Entry point
module OpenTox
class Application < Service
+
+ # for service check
+ head '/?' do
+ #$logger.debug "Algorithm service is running."
+ end
+
get '/?' do
list = [ to('/lazar', :full),
to('/fminer/bbrc', :full),
diff --git a/descriptor.rb b/descriptor.rb
index f4597e0..23f4174 100644
--- a/descriptor.rb
+++ b/descriptor.rb
@@ -184,6 +184,50 @@ module OpenTox
@sdf_file.close
end
end
+<<<<<<< HEAD
+=======
+
+ def fix_value val
+ if val.numeric?
+ val = Float(val)
+ val = nil if val.nan? or val.infinite?
+ else
+ val = nil if val == "NaN"
+ end
+ val
+ end
+ end
+
+ before '/descriptor/?*' do
+ if request.get?
+ @algorithm = OpenTox::Algorithm.new @uri, @subjectid
+ @algorithm.parameters = [
+ { RDF::DC.description => "Dataset URI",
+ RDF::OT.paramScope => "optional",
+ RDF::DC.title => "dataset_uri" } ,
+ { RDF::DC.description => "Compound URI",
+ RDF::OT.paramScope => "optional",
+ RDF::DC.title => "compound_uri" }
+ ]
+ @algorithm.metadata = {
+ RDF.type => [RDF::OTA.DescriptorCalculation],
+ }
+ elsif request.post?
+ @feature_dataset = Dataset.new nil, @subjectid
+ @feature_dataset.metadata = {
+ RDF::DC.title => "Physico-chemical descriptors",
+ RDF::DC.creator => @uri,
+ RDF::OT.hasSource => @uri,
+ }
+ if params[:compound_uri]
+ @feature_dataset.parameters = [ { RDF::DC.title => "compound_uri", RDF::OT.paramValue => params[:compound_uri] }]
+ elsif params[:dataset_uri]
+ @feature_dataset.parameters = [ { RDF::DC.title => "dataset_uri", RDF::OT.paramValue => params[:dataset_uri] }]
+ else
+ bad_request_error "Please provide a dataset_uri or compound_uri parameter", @uri
+ end
+ end
+>>>>>>> ad386110267ecc3e0c5301769b4880a7e555a44e
end
before '/descriptor/:lib/:descriptor/?' do
@@ -221,7 +265,7 @@ module OpenTox
if params[:compound_uri]
compounds = [ Compound.new(params[:compound_uri], @subjectid) ]
elsif params[:dataset_uri]
- compounds = Dataset.new(params[:dataset_uri]).compounds
+ compounds = Dataset.new(params[:dataset_uri], @subjectid).compounds
end
[:openbabel, :cdk, :joelib].each{ |lib| send lib, compounds, descriptors[lib] if descriptors[lib] }
@feature_dataset.put
diff --git a/fminer.rb b/fminer.rb
index 30426da..049b4e5 100644
--- a/fminer.rb
+++ b/fminer.rb
@@ -41,7 +41,7 @@ module OpenTox
# Get representation of BBRC algorithm
# @return [String] Representation
get "/fminer/bbrc/?" do
- algorithm = OpenTox::Algorithm.new(to('/fminer/bbrc',:full))
+ algorithm = OpenTox::Algorithm.new(to('/fminer/bbrc',:full), @subjectid)
algorithm.metadata = {
RDF::DC.title => 'Backbone Refinement Class Representatives',
RDF::DC.creator => "andreas@maunz.de",
@@ -63,7 +63,7 @@ module OpenTox
# Get representation of BBRC-sample algorithm
# @return [String] Representation
get "/fminer/bbrc/sample/?" do
- algorithm = OpenTox::Algorithm.new(to('/fminer/bbrc/sample',:full))
+ algorithm = OpenTox::Algorithm.new(to('/fminer/bbrc/sample',:full), @subjectid)
algorithm.metadata = {
RDF::DC.title => 'Backbone Refinement Class Representatives, obtained from samples of a dataset',
RDF::DC.creator => "andreas@maunz.de",
@@ -85,7 +85,7 @@ module OpenTox
# Get representation of fminer LAST-PM algorithm
# @return [String] Representation
get "/fminer/last/?" do
- algorithm = OpenTox::Algorithm.new(to('/fminer/last',:full))
+ algorithm = OpenTox::Algorithm.new(to('/fminer/last',:full), @subjectid)
algorithm.metadata = {
RDF::DC.title => 'Latent Structure Pattern Mining descriptors',
RDF::DC.creator => "andreas@maunz.de",
@@ -106,7 +106,7 @@ module OpenTox
# Get representation of matching algorithm
# @return [String] Representation
get "/fminer/:method/match?" do
- algorithm = OpenTox::Algorithm.new(to("/fminer/#{params[:method]}/match",:full))
+ algorithm = OpenTox::Algorithm.new(to("/fminer/#{params[:method]}/match",:full), @subjectid)
algorithm.metadata = {
RDF::DC.title => 'fminer feature matching',
RDF::DC.creator => "mguetlein@gmail.com, andreas@maunz.de",
@@ -135,7 +135,7 @@ module OpenTox
# @return [text/uri-list] Task URI
post '/fminer/bbrc/?' do
- @@fminer=OpenTox::Algorithm::Fminer.new(to('/fminer/bbrc',:full))
+ @@fminer=OpenTox::Algorithm::Fminer.new(to('/fminer/bbrc',:full), @subjectid)
@@fminer.check_params(params,5)
task = OpenTox::Task.run("Mining BBRC features", uri('/fminer/bbrc'), @subjectid) do |task|
@@ -291,7 +291,7 @@ module OpenTox
# @return [text/uri-list] Task URI
post '/fminer/last/?' do
- @@fminer=OpenTox::Algorithm::Fminer.new(to('/fminer/last',:full))
+ @@fminer=OpenTox::Algorithm::Fminer.new(to('/fminer/last',:full), @subjectid)
@@fminer.check_params(params,80)
task = OpenTox::Task.run("Mining LAST features", uri('/fminer/last'), @subjectid) do |task|
diff --git a/lazar.rb b/lazar.rb
index de3f753..a9ef863 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -30,8 +30,7 @@ module OpenTox
# @return [text/uri-list] Task URI
post '/lazar/?' do
bad_request_error "Please provide a dataset_uri parameter." unless params[:dataset_uri]
- #TODO: URI namespace clashes
- #resource_not_found_error "Dataset '#{params[:dataset_uri]}' not found." unless URI.accessible? params[:dataset_uri]
+ resource_not_found_error "Dataset '#{params[:dataset_uri]}' not found." unless URI.accessible? params[:dataset_uri], @subjectid
bad_request_error "Please provide a feature_generation_uri parameter." unless params[:feature_generation_uri]
task = OpenTox::Task.run("Create lazar model", uri('/lazar'), @subjectid) do |task|
#lazar = OpenTox::Model::Lazar.new(nil, @subjectid)
diff --git a/lib/dataset.rb b/lib/dataset.rb
new file mode 100644
index 0000000..4f51e41
--- /dev/null
+++ b/lib/dataset.rb
@@ -0,0 +1,32 @@
+=begin
+* Name: dataset.rb
+* Description: Dataset algorithms
+* Author: Andreas Maunz <andreas@maunz.de>
+* Date: 10/2012
+=end
+
+module OpenTox
+ class Dataset
+
+ # Find database activities and calculate a consens
+ # @param [Hash] uri Compound URI, Feature URI
+ # @return [Object] activity Database activity, or nil
+ def database_activity(params)
+ f=Feature.new params[:prediction_feature_uri], @subjectid
+ db_act = values(Compound.new(params[:compound_uri], @subjectid), f)
+ if !db_act.empty?
+ if f.feature_type == "classification"
+ db_act = db_act.to_scale.mode.dup
+ else
+ db_act = db_act.to_scale.median
+ end
+ $logger.debug "Database activity for '#{params[:compound_uri]}': '#{db_act}'"
+ db_act
+ else
+ nil
+ end
+ end
+
+ end
+end
+
diff --git a/lib/lazar.rb b/lib/lazar.rb
index 34d868c..edfee43 100644
--- a/lib/lazar.rb
+++ b/lib/lazar.rb
@@ -12,7 +12,6 @@ module OpenTox
attr_accessor :prediction_dataset
def initialize(params)
- puts "prediction started"
@prediction_dataset = OpenTox::Dataset.new(nil, @subjectid)
# set instance variables and prediction dataset parameters from parameters
params.each {|k,v|
@@ -25,7 +24,7 @@ module OpenTox
instance_variable_set("@#{k}", [])
}
- @prediction_feature = OpenTox::Feature.new(@prediction_feature_uri,@subjectid)
+ @prediction_feature = OpenTox::Feature.new @prediction_feature_uri, @subjectid
@predicted_variable = OpenTox::Feature.new @predicted_variable_uri, @subjectid
@predicted_confidence = OpenTox::Feature.new @predicted_confidence_uri, @subjectid
@prediction_dataset.metadata = {
@@ -36,8 +35,6 @@ module OpenTox
RDF::OT.predictedVariables => [@predicted_variable_uri,@predicted_confidence_uri]
}
- puts "metadata set"
-
@training_dataset = OpenTox::Dataset.new(@training_dataset_uri,@subjectid)
@feature_dataset = OpenTox::Dataset.new(@feature_dataset_uri, @subjectid)
@@ -50,18 +47,16 @@ module OpenTox
prediction_feature_pos = @training_dataset.features.collect{|f| f.uri}.index @prediction_feature.uri
if @dataset_uri
- compounds = OpenTox::Dataset.new(@dataset_uri,@subjectid).compounds
+ compounds = OpenTox::Dataset.new(@dataset_uri, @subjectid).compounds
else
- compounds = [ OpenTox::Compound.new(@compound_uri,@subjectid) ]
+ compounds = [ OpenTox::Compound.new(@compound_uri, @subjectid) ]
end
- puts "compounds started"
compounds.each do |compound|
#database_activity = @training_dataset.database_activity(params)
database_activities = @training_dataset.values(compound,@prediction_feature)
- puts "checking dataset activity"
if database_activities and !database_activities.empty?
database_activities.each do |database_activity|
@prediction_dataset.add_data_entry compound, @prediction_feature, database_activity
@@ -75,15 +70,10 @@ module OpenTox
:compound => compound,
:feature_dataset => @feature_dataset,
}
- puts "fingerprints"
- puts @feature_calculation_algorithm
- puts compound_params
#compound_fingerprints = OpenTox::Algorithm::FeatureValues.send( @feature_calculation_algorithm, compound_params, @subjectid )
# TODO: fix for pc descriptors
#compound_fingerprints = OpenTox::Algorithm::Descriptor.send( @feature_calculation_algorithm, compound, @feature_dataset.features.collect{ |f| f[RDF::DC.title] } )
compound_fingerprints = eval("#{@feature_calculation_algorithm}(compound, @feature_dataset.features.collect{ |f| f[RDF::DC.title] } )")
- puts "Fingerprints"
- puts compound_fingerprints.inspect
@training_dataset.compounds.each_with_index { |cmpd, idx|
act = @training_dataset.data_entries[idx][prediction_feature_pos]
@acts << (@prediction_feature.feature_type=="classification" ? @prediction_feature.value_map.invert[act] : nil)
@@ -99,12 +89,10 @@ module OpenTox
} # query structure
=end
@q_prop = compound_fingerprints.first.collect{|v| v.to_f}
- puts @q_prop.inspect
mtf = OpenTox::Algorithm::Transform::ModelTransformer.new(self)
mtf.transform
- puts "Prediction"
prediction = OpenTox::Algorithm::Neighbors.send(@prediction_algorithm,
{ :props => mtf.props,
:acts => mtf.acts,
@@ -127,7 +115,7 @@ module OpenTox
if @compound_uri # add neighbors only for compound predictions
@neighbors.each do |neighbor|
- n = OpenTox::Compound.new(neighbor[:compound])
+ n = OpenTox::Compound.new(neighbor[:compound], @subjectid)
@prediction_dataset.add_data_entry n, @prediction_feature, @prediction_feature.value_map[neighbor[:activity]]
@prediction_dataset.add_data_entry n, @similarity_feature, neighbor[:similarity]
#@prediction_dataset << [ n, @prediction_feature.value_map[neighbor[:activity]], nil, nil, neighbor[:similarity] ]
@@ -218,6 +206,18 @@ module OpenTox
put
@uri
+<<<<<<< HEAD
+=======
+ if params[:feature_dataset_uri]
+ bad_request_error "Feature dataset #{params[:feature_dataset_uri]} does not exist." unless URI.accessible? params[:feature_dataset_uri], @subjectid
+ @parameters << {RDF::DC.title => "feature_dataset_uri", RDF::OT.paramValue => params[:feature_dataset_uri]}
+ self[RDF::OT.featureDataset] = params["feature_dataset_uri"]
+ else
+ # run feature generation algorithm
+ feature_dataset_uri = OpenTox::Algorithm.new(params[:feature_generation_uri], @subjectid).run(params)
+ @parameters << {RDF::DC.title => "feature_dataset_uri", RDF::OT.paramValue => feature_dataset_uri}
+ self[RDF::OT.featureDataset] = feature_dataset_uri
+>>>>>>> ad386110267ecc3e0c5301769b4880a7e555a44e
end
end
diff --git a/test.rb b/test.rb
index 75044da..dc5ac9f 100644
--- a/test.rb
+++ b/test.rb
@@ -6,7 +6,7 @@ module OpenTox
post '/test/wait_for_error_in_task/?' do
task = OpenTox::Task.run("wait_for_error_in_task",@uri,@subjectid) do |task|
sleep 1
- uri = OpenTox::Dataset.new(File.join($dataset[:uri],'test/error_in_task')).post
+ uri = OpenTox::Dataset.new(File.join($dataset[:uri],'test/error_in_task'), @subjectid).post
end
response['Content-Type'] = 'text/uri-list'
halt 202,task.uri.to_s+"\n"