require 'csv' require 'tempfile' class String def float? Float(self) rescue false end end class LoaelMazzatorta def self.predict smiles smiles = [smiles] unless smiles.is_a? Array predictions = [] input = Tempfile.new("/tmp/smi") begin input.write smiles.join("\n") input.close loaels = `cd #{File.join(File.dirname(__FILE__),"..","java")}; java -cp LoaelMazzatorta.class:CustomDescriptors.class:insilicoCore.jar:cdk-1.4.9-pruned.jar:. LoaelMazzatorta #{input.path}`.split "\n" loaels.each_with_index do |loael,i| if loael.float? predictions << {"value" => loael.to_f, "SMILES" => smiles[i]} else predictions << {"warnings" => [loael], "SMILES" => smiles[i]} end end ensure input.unlink end predictions.size == 1 ? predictions[0] : predictions end end