Tuesday, November 27, 2007

Re: the EMBOSS bioinformatics toolset, and the IEP utility in particular

The iep.c codebase is supposed to predict Isoelectric Point for an amino acid sequence. And it does this, but it also manages to serve as an object lesson in bad C code:

  • AjPFile, AjPStr, and ajint types: your very own custom integer type?? Really?
  • Put everything in global variables! Thus, you wind up w/ void functions that take 0 parameters and do something incredibly important; the challenge is to track down what that important thing might be! (Every programmer should be required to write code in a purely functional language for at least 3 months. By law.) Take void embIepPkRead() , for example.
  • Functions that simply wrap other functions. Code as treasure hunt!


Biologists shouldn't code.

If anybody is interested in the basic algorithm used by EMBOSS IEP to calculate Pi, it basically calculates the charge of the protein iteratively across potential pH's until it hits 0 charge, or the upper and lower bounds converge. The primary function can be found in embIepPhConverge. ajint *c holds a histogram of amino acid counts, double *K is an array of dissociation constants for each amino acid, and double *pro is the moneymaker -- it gets updated w/ a proton count for each amino acid as different pH's are tried. The loop starts w/ max 14.0 and min 1.0, sets pro for the midpoint pH, then sets either the upper or lower bound to the midpoint, depending upon whether the calculated charge is positive or negative.

Friday, November 16, 2007

Java from the command line and GUI dependence

Calling a .jar file from the command-line in headless mode--say, from a web-server--seems to pose a problem under OS X Tiger, in that java requires communication w/ the GUI system. (This leads me to believe that the problem applies under Linux as well.)

The solution is the "-Djava.awt.headless=true" parameter; for example, here's how I call the Batik SVG rasterizer:
/usr/bin/java -Djava.awt.headless=true -jar /Library/WebServer/Documents/py/archive/batik-1.7/batik-rasterizer.jar -w 1000 -h 1000 -bg 255.255.255.255 xxx.svg


I knew I didn't trust that newfangled Java.