summaryrefslogtreecommitdiff
path: root/lib/model.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/model.rb')
-rw-r--r--lib/model.rb49
1 files changed, 36 insertions, 13 deletions
diff --git a/lib/model.rb b/lib/model.rb
index a858a0f..c9d367e 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -103,7 +103,7 @@ module OpenTox
include Model
- attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :subjectid, :value_map, :compound_fingerprints, :feature_calculation_algorithm, :neighbors
+ attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :subjectid, :value_map, :compound_fingerprints, :feature_calculation_algorithm, :neighbors, :compounds
def initialize(uri=nil)
if uri
@@ -169,12 +169,13 @@ module OpenTox
lazar.prediction_algorithm = hash["prediction_algorithm"] if hash["prediction_algorithm"]
lazar.subjectid = hash["subjectid"] if hash["subjectid"]
lazar.value_map = hash["value_map"] if hash["value_map"]
+ lazar.compounds = hash["compounds"] if hash["compounds"]
lazar
end
def to_json
- Yajl::Encoder.encode({:uri => @uri,:metadata => @metadata, :compound => @compound, :prediction_dataset => @prediction_dataset, :features => @features, :effects => @effects, :activities => @activities, :p_values => @p_values, :fingerprints => @fingerprints, :feature_calculation_algorithm => @feature_calculation_algorithm, :similarity_algorithm => @similarity_algorithm, :prediction_algorithm => @prediction_algorithm, :subjectid => @subjectid, :value_map => @value_map})
+ Yajl::Encoder.encode({:uri => @uri,:metadata => @metadata, :compound => @compound, :prediction_dataset => @prediction_dataset, :features => @features, :effects => @effects, :activities => @activities, :p_values => @p_values, :fingerprints => @fingerprints, :feature_calculation_algorithm => @feature_calculation_algorithm, :similarity_algorithm => @similarity_algorithm, :prediction_algorithm => @prediction_algorithm, :subjectid => @subjectid, :value_map => @value_map, :compounds => @compounds})
end
def run( params, accept_header=nil, waiting_task=nil )
@@ -237,6 +238,7 @@ module OpenTox
@compound = Compound.new compound_uri
features = {}
+
#LOGGER.debug self.to_yaml
unless @prediction_dataset
@prediction_dataset = Dataset.create(CONFIG[:services]["opentox-dataset"], subjectid)
@@ -247,19 +249,19 @@ module OpenTox
OT.parameters => [{DC.title => "compound_uri", OT.paramValue => compound_uri}]
} )
end
- if OpenTox::Feature.find(metadata[OT.dependentVariables], subjectid).feature_type == "regression"
- all_activities = []
- all_activities = @activities.values.flatten.collect! { |i| i.to_f }
- end
+
unless database_activity(subjectid) # adds database activity to @prediction_dataset
+
# Calculation of needed values for query compound
@compound_features = eval("#{@feature_calculation_algorithm}({
:compound => @compound,
:features => @features,
:feature_dataset_uri => @metadata[OT.featureDataset],
:pc_type => self.parameter(\"pc_type\"),
+ :lib => self.parameter(\"lib\"),
:subjectid => subjectid
})")
+
# Adding fingerprint of query compound with features and values(p_value*nr_hits)
@compound_fingerprints = {}
@compound_features.each do |feature, value| # value is nil if "Substructure.match"
@@ -314,6 +316,16 @@ module OpenTox
@prediction_dataset.add @compound.uri, feature_uri, true
f+=1
end
+ elsif @feature_calculation_algorithm == "Substructure.lookup"
+ f = 0
+ @compound_features.each do |feature, value|
+ features[feature] = feature
+ @prediction_dataset.add_feature(feature, {
+ RDF.type => [OT.NumericFeature]
+ })
+ @prediction_dataset.add @compound.uri, feature, value
+ f+=1
+ end
else
@compound_features.each do |feature|
features[feature] = feature
@@ -337,15 +349,26 @@ module OpenTox
else
feature_uri = feature
end
- @prediction_dataset.add neighbor[:compound], feature_uri, true
+ if @feature_calculation_algorithm == "Substructure.lookup"
+ @prediction_dataset.add neighbor[:compound], feature_uri, @fingerprints[neighbor[:compound]][feature_uri]
+ else
+ @prediction_dataset.add neighbor[:compound], feature_uri, true
+ end
+
unless features.has_key? feature
features[feature] = feature_uri
- @prediction_dataset.add_feature(feature_uri, {
- RDF.type => [OT.Substructure],
- OT.smarts => feature,
- OT.pValue => @p_values[feature],
- OT.effect => @effects[feature]
- })
+ if @feature_calculation_algorithm == "Substructure.lookup"
+ @prediction_dataset.add_feature(feature_uri, {
+ RDF.type => [OT.NumericFeature]
+ })
+ else
+ @prediction_dataset.add_feature(feature_uri, {
+ RDF.type => [OT.Substructure],
+ OT.smarts => feature,
+ OT.pValue => @p_values[feature],
+ OT.effect => @effects[feature]
+ })
+ end
f+=1
end
end