From 3539215bdbf35a6a7a78456ac409bfd66d581f3e Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Fri, 16 Nov 2012 12:58:54 +0100 Subject: Added get_target parameter --- fminer.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/fminer.rb b/fminer.rb index 3dc2bf2..735df7d 100644 --- a/fminer.rb +++ b/fminer.rb @@ -77,6 +77,7 @@ get "/fminer/bbrc/?" do { DC.description => "BBRC classes, pass 'false' to switch off mining for BBRC representatives.", OT.paramScope => "optional", DC.title => "backbone" }, { DC.description => "Significance threshold (between 0 and 1)", OT.paramScope => "optional", DC.title => "min_chisq_significance" }, { DC.description => "Whether subgraphs should be weighted with their occurrence counts in the instances (frequency)", OT.paramScope => "optional", DC.title => "nr_hits" }, + { DC.description => "Set to 'true' to obtain target variable as a feature", OT.paramScope => "optional", DC.title => "nr_hits" }, ] } case request.env['HTTP_ACCEPT'] @@ -141,6 +142,7 @@ get "/fminer/last/?" do { DC.description => "Minimum frequency", OT.paramScope => "optional", DC.title => "min_frequency" }, { DC.description => "Feature type, can be 'paths' or 'trees'", OT.paramScope => "optional", DC.title => "feature_type" }, { DC.description => "Whether subgraphs should be weighted with their occurrence counts in the instances (frequency)", OT.paramScope => "optional", DC.title => "nr_hits" }, + { DC.description => "Set to 'true' to obtain target variable as a feature", OT.paramScope => "optional", DC.title => "nr_hits" }, ] } case request.env['HTTP_ACCEPT'] @@ -201,6 +203,7 @@ end # - min_chisq_significance Significance threshold (between 0 and 1) # - nr_hits Set to "true" to get hit count instead of presence # - complete_entries Set to "true" to obtain data entries for each compound +# - get_target Set to "true" to obtain target variable as feature # @return [text/uri-list] Task URI post '/fminer/bbrc/?' do @@ -245,6 +248,9 @@ post '/fminer/bbrc/?' do # Add data to fminer @@fminer.add_fminer_data(@@bbrc, value_map) + if (params[:get_target] == "true") + feature_dataset.add_feature @@fminer.prediction_feature.uri, @@fminer.prediction_feature.metadata + end g_array=@@fminer.all_activities.values # DV: calculation of global median for effect calculation g_median=g_array.to_scale.median @@ -322,6 +328,9 @@ post '/fminer/bbrc/?' do @@fminer.training_dataset.compounds.each { |cmpd| feature_dataset.add_compound(cmpd) # *unconditionally* add compounds *in order* i = which_row[cmpd] + if (params[:get_target] == "true") + feature_dataset.add_data_entry ( cmpd, @@fminer.prediction_feature.uri, @@fminer.training_dataset.data_entries[cmpd][@@fminer.prediction_feature.uri][i] ) + end fminer_results[cmpd] && fminer_results[cmpd].each { |feature, values| feature_dataset.add_data_entry( cmpd, feature, values[i] ) } @@ -532,6 +541,7 @@ end # - feature_type Feature type, can be 'paths' or 'trees' (default "trees") # - nr_hits Set to "true" to get hit count instead of presence # - complete_entries Set to "true" to obtain data entries for each compound +# - get_target Set to "true" to obtain target variable as feature # @return [text/uri-list] Task URI post '/fminer/last/?' do @@ -573,6 +583,9 @@ post '/fminer/last/?' do # Add data to fminer @@fminer.add_fminer_data(@@last, value_map) + if (params[:get_target] == "true") + feature_dataset.add_feature @@fminer.prediction_feature.uri, @@fminer.prediction_feature.metadata + end raise "No compounds in dataset #{@@fminer.training_dataset.uri}" if @@fminer.compounds.size==0 @@ -596,7 +609,23 @@ post '/fminer/last/?' do params[:complete_entries] == "true" ? complete_entries=true : complete_entries=false matches, counts = lu.match_rb(@@fminer.smi,smarts,hit_count,complete_entries) # creates instantiations - @@fminer.training_dataset.compounds.each { |cmpd| feature_dataset.add_compound(cmpd) } + + which_row = @@fminer.training_dataset.compounds.inject({}) { |h,id| h[id]=0; h } + + all_target_vals = [] + if (params[:get_target] == "true") + @@fminer.training_dataset.compounds.each { |cmpd| + all_target_vals << @@fminer.training_dataset.data_entries[cmpd][@@fminer.prediction_feature.uri][which_row[cmpd]] + which_row[cmpd] += 1 + } + end + + @@fminer.training_dataset.compounds.each_with_index { |cmpd,idx| + feature_dataset.add_compound(cmpd) + if (params[:get_target] == "true") + feature_dataset.add_data_entry ( cmpd, @@fminer.prediction_feature.uri, all_target_vals[idx] ) + end + } matches.each do |smarts, ids| metadata = calc_metadata (smarts, ids, counts[smarts], @@last, nil, value_map, params) feature_uri = File.join feature_dataset.uri,"feature","last", feature_dataset.features.size.to_s -- cgit v1.2.3