diff options
Diffstat (limited to 'fminer.rb')
-rw-r--r-- | fminer.rb | 76 |
1 files changed, 49 insertions, 27 deletions
@@ -23,7 +23,7 @@ get "/fminer/bbrc/?" do DC.title => 'fminer backbone refinement class representatives', DC.creator => "andreas@maunz.de, helma@in-silico.ch", DC.contributor => "vorgrimmlerdavid@gmx.de", - OT.isA => OTA.PatternMiningSupervised, + RDF.type => [OTA.PatternMiningSupervised], OT.parameters => [ { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" }, { DC.description => "Feature URI for dependent variable", OT.paramScope => "mandatory", DC.title => "prediction_feature" }, @@ -44,7 +44,7 @@ get "/fminer/last/?" do DC.title => 'fminer latent structure class representatives', DC.creator => "andreas@maunz.de, helma@in-silico.ch", DC.contributor => "vorgrimmlerdavid@gmx.de", - OT.isA => OTA.PatternMiningSupervised, + RDF.type => [OTA.PatternMiningSupervised], OT.parameters => [ { DC.description => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" }, { DC.description => "Feature URI for dependent variable", OT.paramScope => "mandatory", DC.title => "prediction_feature" }, @@ -70,7 +70,7 @@ post '/fminer/bbrc/?' do halt 404, "Please submit a dataset_uri." unless params[:dataset_uri] and !params[:dataset_uri].nil? halt 404, "Please submit a prediction_feature." unless params[:prediction_feature] and !params[:prediction_feature].nil? - prediction_feature = params[:prediction_feature] + prediction_feature = OpenTox::Feature.find params[:prediction_feature] training_dataset = OpenTox::Dataset.find "#{params[:dataset_uri]}", @subjectid halt 404, "No feature #{params[:prediction_feature]} in dataset #{params[:dataset_uri]}" unless training_dataset.features and training_dataset.features.include?(params[:prediction_feature]) @@ -88,6 +88,11 @@ post '/fminer/bbrc/?' do @@bbrc.SetBackbone(eval params[:backbone]) if params[:backbone] and ( params[:backbone] == "true" or params[:backbone] == "false" ) # convert string to boolean @@bbrc.SetChisqSig(params[:min_chisq_significance]) if params[:min_chisq_significance] @@bbrc.SetConsoleOut(false) + if prediction_feature.feature_type == "regression" + @@bbrc.SetRegression(true) + else + @training_classes = training_dataset.feature_classes(prediction_feature.uri) + end feature_dataset = OpenTox::Dataset.new(nil, @subjectid) feature_dataset.add_metadata({ @@ -119,21 +124,30 @@ post '/fminer/bbrc/?' do next end entry.each do |feature,values| - if feature == prediction_feature + if feature == prediction_feature.uri values.each do |value| if value.nil? LOGGER.warn "No #{feature} activiity for #{compound.to_s}." else - case value.to_s - when "true" - nr_active += 1 - activity = 1 - when "false" - nr_inactive += 1 - activity = 0 - else + if prediction_feature.feature_type == "classification" + case value.to_s + when "true" + nr_active += 1 + activity = 1 + when "false" + nr_inactive += 1 + activity = 0 + when /#{@training_classes.last}/ + nr_active += 1 + activity = 1 + when /#{@training_classes.first}/ + nr_inactive += 1 + activity = 0 + else + LOGGER.warn "Unknown class \"#{value.to_s}\"." + end + elsif prediction_feature.feature_type == "regression" activity = value.to_f - @@bbrc.SetRegression(true) end begin @@bbrc.AddCompound(smiles,id) @@ -192,7 +206,7 @@ post '/fminer/bbrc/?' do features << smarts metadata = { OT.hasSource => url_for('/fminer/bbrc', :full), - OT.isA => OT.Substructure, + RDF.type => [OT.Substructure], OT.smarts => smarts, OT.pValue => p_value.to_f, OT.effect => effect, @@ -283,23 +297,31 @@ post '/fminer/last/?' do if value.nil? LOGGER.warn "No #{feature} activiity for #{compound.to_s}." else - case value.to_s - when "true" - nr_active += 1 - activity = 1 - when "false" - nr_inactive += 1 - activity = 0 - else + if prediction_feature.feature_type == "classification" + case value.to_s + when "true" + nr_active += 1 + activity = 1 + when "false" + nr_inactive += 1 + activity = 0 + when /#{@training_classes.last}/ + nr_active += 1 + activity = 1 + when /#{@training_classes.first}/ + nr_inactive += 1 + activity = 0 + else + LOGGER.warn "Unknown class \"#{value.to_s}." + end + elsif prediction_feature.feature_type == "regression" activity = value.to_f - @@last.SetRegression(true) end begin - @@last.AddCompound(smiles,id) - @@last.AddActivity(activity, id) + @@bbrc.AddCompound(smiles,id) + @@bbrc.AddActivity(activity, id) all_activities[id]=activity # DV: insert global information compounds[id] = compound - smi[id] = smiles # AM LAST: changed this to store SMILES. id += 1 rescue LOGGER.warn "Could not add " + smiles + "\t" + value.to_s + " to fminer" @@ -340,7 +362,7 @@ post '/fminer/last/?' do unless features.include? smarts features << smarts metadata = { - OT.isA => OT.Substructure, + RDF.type => [OT.Substructure], OT.hasSource => feature_dataset.uri, OT.smarts => smarts, OT.pValue => p_value.to_f, |