diff options
author | Andreas Maunz <andreas@maunz.de> | 2012-04-17 15:14:02 +0200 |
---|---|---|
committer | Andreas Maunz <andreas@maunz.de> | 2012-04-17 15:14:02 +0200 |
commit | e50b7083a584e1387d885a594d13320b0013ef55 (patch) | |
tree | c5581c950667c6d005973b1a848a0ec1984db8d2 | |
parent | de3da90232f325735b8d05d9da05cc57326c2b67 (diff) |
Corrected: CSV download, fminer prediction f detect
CSV: order of rows in order of compounds
fminer check_params: auto-detecting prediction feature in case of a
single feature in the dataset
-rw-r--r-- | lib/algorithm.rb | 10 | ||||
-rw-r--r-- | lib/serializer.rb | 21 | ||||
-rw-r--r-- | lib/utils.rb | 2 |
3 files changed, 25 insertions, 8 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 948d4b7..4f18d89 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -56,9 +56,15 @@ module OpenTox def check_params(params,per_mil,subjectid=nil) raise OpenTox::NotFoundError.new "Please submit a dataset_uri." unless params[:dataset_uri] and !params[:dataset_uri].nil? - raise OpenTox::NotFoundError.new "Please submit a prediction_feature." unless params[:prediction_feature] and !params[:prediction_feature].nil? - @prediction_feature = OpenTox::Feature.find params[:prediction_feature], subjectid @training_dataset = OpenTox::Dataset.find "#{params[:dataset_uri]}", subjectid + + unless params[:prediction_feature] # try to read prediction_feature from dataset + raise OpenTox::NotFoundError.new "Please provide a prediction_feature parameter" unless @training_dataset.features.size == 1 + prediction_feature = OpenTox::Feature.find(@training_dataset.features.keys.first,@subjectid) + params[:prediction_feature] = prediction_feature.uri + end + @prediction_feature = OpenTox::Feature.find params[:prediction_feature], subjectid + raise OpenTox::NotFoundError.new "No feature #{params[:prediction_feature]} in dataset #{params[:dataset_uri]}" unless @training_dataset.features and @training_dataset.features.include?(params[:prediction_feature]) unless params[:min_frequency].nil? diff --git a/lib/serializer.rb b/lib/serializer.rb index 2205ade..d3616ce 100644 --- a/lib/serializer.rb +++ b/lib/serializer.rb @@ -459,21 +459,32 @@ module OpenTox def initialize(dataset) @rows = [] @rows << ["SMILES"] + features = dataset.features.keys + # prepare for subgraphs + have_substructures = features.collect{ |id| dataset.features[id][RDF.type].include? OT.Substructure}.compact.uniq + if have_substructures.size == 1 && have_substructures[0] + features_smarts = features.collect{ |id| "'" + dataset.features[id][OT.smarts] + "'" } + dataset.complete_data_entries + end + + # gather missing features delete_features = [] - features.each{ |fn| - dataset.features[fn][RDF.type].each { |typestr| + features.each{ |id| + dataset.features[id][RDF.type].each { |typestr| if typestr.include? "MissingFeature" - delete_features << fn + delete_features << id end } } + features = features - delete_features + features_smarts && @rows.first << features_smarts || @rows.first << features - @rows.first << features @rows.first.flatten! - dataset.data_entries.each do |compound,entries| + dataset.compounds.each do |compound| + entries=dataset.data_entries[compound] cmpd = Compound.new(compound) smiles = cmpd.to_smiles inchi = URI.encode_www_form_component(cmpd.to_inchi) diff --git a/lib/utils.rb b/lib/utils.rb index 0ad0d92..a3f8161 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -119,7 +119,7 @@ module OpenTox ds.save else - raise "No descriptors matching your criteria found." + raise OpenTox::BadRequestError.new "No descriptors matching your criteria found." end end |