summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2012-05-07 14:11:23 +0200
committerAndreas Maunz <andreas@maunz.de>2012-05-07 14:11:23 +0200
commit3a790b762fafbfe1a3b92aa494355bc8ab6ca978 (patch)
tree07dae14fb562d386203acae370804bba94066e1d
parent1b02cef5f5af5930a2c0a449357618c9266c29ed (diff)
checking instance if data should be added to fminer
-rw-r--r--lib/algorithm.rb29
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 64fa508..54bb371 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -75,7 +75,7 @@ module OpenTox
end
end
- def add_fminer_data(fminer_instance, value_map, prepare_backend=true)
+ def add_fminer_data(fminer_instance, value_map)
# detect nr duplicates per compound
@@ -119,8 +119,8 @@ module OpenTox
activity= values[i].to_f
end
begin
- fminer_instance.AddCompound(smiles,id) if prepare_backend
- fminer_instance.AddActivity(activity, id) if prepare_backend
+ fminer_instance.AddCompound(smiles,id) if fminer_instance
+ fminer_instance.AddActivity(activity, id) if fminer_instance
@all_activities[id]=activity # DV: insert global information
@compounds[id] = compound
@smi[id] = smiles
@@ -579,3 +579,26 @@ module OpenTox
end
end
end
+
+class Array
+ # collect method extended for parallel processing.
+ # Note: assign return value as: ans = arr.pcollect(n) { |obj| ... }
+ # @param n the number of processes to spawn (default: unlimited)
+ def pcollect(n = nil)
+ nproc = 0
+ result = collect do |*a|
+ r, w = IO.pipe
+ fork do
+ r.close
+ w.write( Marshal.dump( yield(*a) ) )
+ end
+ if n and (nproc+=1) >= n
+ Process.wait ; nproc -= 1
+ end
+ [ w.close, r ].last
+ end
+ Process.waitall
+ result.collect{|r| Marshal.load [ r.read, r.close ].first}
+ end
+end
+