summaryrefslogtreecommitdiff
path: root/fminer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'fminer.rb')
-rw-r--r--fminer.rb88
1 files changed, 65 insertions, 23 deletions
diff --git a/fminer.rb b/fminer.rb
index 94284db..95ce469 100644
--- a/fminer.rb
+++ b/fminer.rb
@@ -30,15 +30,16 @@ 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",
+# BO.instanceOf => "http://opentox.org/ontology/ist-algorithms.owl#fminer_bbrc",
RDF.type => [OT.Algorithm,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" },
- { DC.description => "Minimum frequency", OT.paramScope => "optional", DC.title => "minfreq" },
- { DC.description => "Feature type, can be 'paths' or 'trees'", OT.paramScope => "optional", DC.title => "feature_type" },
- { 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 => "Dataset URI", OT.paramScope => "mandatory", DC.title => "dataset_uri" },
+ { DC.description => "Feature URI for dependent variable", OT.paramScope => "mandatory", DC.title => "prediction_feature" },
+ { 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 => "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" },
+ ]
}
case request.env['HTTP_ACCEPT']
when /text\/html/
@@ -61,14 +62,15 @@ 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",
+# BO.instanceOf => "http://opentox.org/ontology/ist-algorithms.owl#fminer_last",
RDF.type => [OT.Algorithm,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" },
- { DC.description => "Minimum frequency", OT.paramScope => "optional", DC.title => "minfreq" },
- { DC.description => "Feature type, can be 'paths' or 'trees'", OT.paramScope => "optional", DC.title => "feature_type" },
- { DC.description => "Maximum number of hops", OT.paramScope => "optional", DC.title => "hops" },
- ]
+ { 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" },
+ { 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 => "Maximum number of hops", OT.paramScope => "optional", DC.title => "hops" },
+ ]
}
case request.env['HTTP_ACCEPT']
when /text\/html/
@@ -83,6 +85,37 @@ get "/fminer/last/?" do
end
end
+# Creates same features for dataset <dataset_uri> that have been created
+# with fminer in dataset <feature_dataset_uri>
+# accept params[:nr_hits] as used in other fminer methods
+post '/fminer/:method/match?' do
+ raise OpenTox::BadRequestError.new "feature_dataset_uri not given" unless params[:feature_dataset_uri]
+ raise OpenTox::BadRequestError.new "dataset_uri not given" unless params[:dataset_uri]
+ task = OpenTox::Task.create("Matching features", url_for('/fminer/match',:full)) do |task|
+ f_dataset = OpenTox::Dataset.find params[:feature_dataset_uri],@subjectid
+ c_dataset = OpenTox::Dataset.find params[:dataset_uri],@subjectid
+ res_dataset = OpenTox::Dataset.create CONFIG[:services]["dataset"],@subjectid
+ f_dataset.features.each do |f,m|
+ res_dataset.add_feature(f,m)
+ end
+ c_dataset.compounds.each do |c|
+ res_dataset.add_compound(c)
+ comp = OpenTox::Compound.new(c)
+ f_dataset.features.each do |f,m|
+ if params[:nr_hits] == "true"
+ hits = comp.match_hits([m[OT.smarts]])
+ res_dataset.add(c,f,hits[m[OT.smarts]]) if hits[m[OT.smarts]]
+ else
+ res_dataset.add(c,f,1) if comp.match?(m[OT.smarts])
+ end
+ end
+ end
+ res_dataset.save @subjectid
+ res_dataset.uri
+ end
+ return_task(task)
+end
+
# Run bbrc algorithm on dataset
#
# @param [String] dataset_uri URI of the training dataset
@@ -124,7 +157,7 @@ post '/fminer/bbrc/?' do
OT.parameters => [
{ DC.title => "dataset_uri", OT.paramValue => params[:dataset_uri] },
{ DC.title => "prediction_feature", OT.paramValue => params[:prediction_feature] }
- ]
+ ]
})
feature_dataset.save(@subjectid)
@@ -138,12 +171,12 @@ post '/fminer/bbrc/?' do
g_array=fminer.all_activities.values # DV: calculation of global median for effect calculation
g_median=g_array.to_scale.median
-
+
raise "No compounds in dataset #{fminer.training_dataset.uri}" if fminer.compounds.size==0
task.progress 10
step_width = 80 / @@bbrc.GetNoRootNodes().to_f
features = Set.new
-
+
# run @@bbrc
(0 .. @@bbrc.GetNoRootNodes()-1).each do |j|
results = @@bbrc.MineRoot(j)
@@ -185,7 +218,7 @@ post '/fminer/bbrc/?' do
OT.parameters => [
{ DC.title => "dataset_uri", OT.paramValue => params[:dataset_uri] },
{ DC.title => "prediction_feature", OT.paramValue => params[:prediction_feature] }
- ]
+ ]
}
feature_dataset.add_feature feature_uri, metadata
#feature_dataset.add_feature_parameters feature_uri, feature_dataset.parameters
@@ -199,8 +232,13 @@ post '/fminer/bbrc/?' do
feature_dataset.add(fminer.compounds[id], feature_uri, 1)
end
}
- end
- end
+
+ end # end of
+ end # feature parsing
+
+ # AM: add feature values for non-present features
+ # feature_dataset.complete_data_entries
+
feature_dataset.save(@subjectid)
feature_dataset.uri
end
@@ -250,7 +288,7 @@ post '/fminer/last/?' do
OT.parameters => [
{ DC.title => "dataset_uri", OT.paramValue => params[:dataset_uri] },
{ DC.title => "prediction_feature", OT.paramValue => params[:prediction_feature] }
- ]
+ ]
})
feature_dataset.save(@subjectid)
@@ -261,7 +299,7 @@ post '/fminer/last/?' do
# Add data to fminer
fminer.add_fminer_data(@@last, params, @value_map)
-
+
raise "No compounds in dataset #{fminer.training_dataset.uri}" if fminer.compounds.size==0
# run @@last
@@ -309,7 +347,7 @@ post '/fminer/last/?' do
OT.parameters => [
{ DC.title => "dataset_uri", OT.paramValue => params[:dataset_uri] },
{ DC.title => "prediction_feature", OT.paramValue => params[:prediction_feature] }
- ]
+ ]
}
feature_dataset.add_feature feature_uri, metadata
end
@@ -319,10 +357,14 @@ post '/fminer/last/?' do
ids.each_with_index { |id,i| feature_dataset.add(fminer.compounds[id], feature_uri, counts[smarts][i])}
end
end
+
+ # AM: add feature values for non-present features
+ # feature_dataset.complete_data_entries
+
feature_dataset.save(@subjectid)
feature_dataset.uri
end
response['Content-Type'] = 'text/uri-list'
raise OpenTox::ServiceUnavailableError.newtask.uri+"\n" if task.status == "Cancelled"
halt 202,task.uri.to_s+"\n"
-end \ No newline at end of file
+end