Wednesday, July 31, 2013

Writing CDK code in Bioclipse

Of course, there is the CDK manager in Bioclipse (Fig. 2, doi:10.1186/1471-2105-10-397), which exposes a good deal of the commonly used functionality, but yesterday there was this question on the CHMINF-L mailing list about how to find all existing isotopes, given a certain exact mass.

Now, that's something we can do with CDK's IsotopeFactory (with thanx to John for these "stable" URIs!), but I did not want to propose using something arcane as a command line, so was wondering if it could be done in Bioclipse. So, I had to figure out how to create Java objects in JavaScript, a skill I once had but lost.

But, I regained it after some googling and ended up with this code:

It's an image as I had to make one for where the source code can be downloaded.

The key JavaScript calls as importPackage() and importClass(), and I am sure there are some things that can be optimized here (please leave a comment if you have a better solution), but once I have the IsotopeFactory, I iterate over all elements and for each ask all isotopes (yeah, I think there is some API methods missing here :). And for each isotope I test if it matches (within a certain error) the search mass, and if it matches, reports the mass number, element symbol, and exact mass (using the js manager).