Pages

Saturday, August 06, 2011

Hacking Bioclipse scripts in Groovy

Users are demanding. Peter (of Specs) and I chatted yesterday afternoon briefly about the Bioclipse Scripting Langauge, and in particular how to append content in the JavaScript to an existing file. I do not know how to do that with either Bioclipse managers, nor with JavaScript.

So, I look up an old patch that updated the JavaScript console to use Groovy instead (which I also use in my Groovy Cheminformatics book, which just had a third edition out). And it still worked! On the train back home I cleaned up the code to use a separate console window, separate threads, etc, so that you can have a Groovy and a JavaScript console running in parallel (they do not share variables):


The print command still routes the text to something undefined, instead of the console.But it mostly works the same as with the JavaScript console, and all managers are available in the same way.

This means, one can now do fancy stuff like:

new File("/tmp/test.smi").eachLine { smiles ->
  if (smiles.length() > 0)
    js.say("" + cdk.fromSMILES(smiles))
}

Now, I just realize that the 'print' issue is actually worked around in the JavaScript console with a dedicated js manager, which I used above. But of course this routes the output to the JavaScript console, not the Groovy console :)

Update: I discovered that a JSR 223 provides a ScriptContext which allows one to overwrite the ScriptEngines standard output. That means practically, that I got the print to work properly now :)