Tuesday, September 8, 2009

Heat Mapper rises from the ashes

This is the second of two posts about Apple-specific programming issues, so feel free to move on if you don't care about both subjects. I spent the labor day weekend re-doing my program to draw heat maps in Objective-C, and finally have a minimally functional version.

As usual, most of the time was wasted running down stupid errors, but I seem to be getting a little better about recognizing them. One of these had to do with a call like:

IBOutlet id myController;

in a header file. This only works if said file is in the "Classes" section of Xcode. If it's in "Resources," as happened once by mistake, there is an error message from the compiler because the IB cannot actually connect to the outlet.

But the biggest time-waster (and probably the silliest bug) was caused by using spaces (long ago) to pad the the row names in the sample data which I feed to the application. It makes the text version look prettier (tabs don't always line up), as you can see in this sample without ljust:

bacteroidales 0 0 0 0
rikenella 0 0 0 0
prevotella 0 0 0 1
porphyro 0 0 0 1
capno 9 0 6 19
fuso 1 0 0 2
lepto 0 0 0 0
kingella 0 0 1 0
neisseria 1 0 4 2

The problem came when I used a dictionary with genus names as keys to specify colors to draw the strings. The names I read from the data file were padded out to the length of the longest one:

"rikenella "

So the key lookup failed when searching for the second key but not for the first. It kinda worked… I spent at least 10 hours on this. Since writing code is laborious in Objective-C, writing testing code is also laborious.

On the other hand, the bug is solved, and if it ever comes again I hope to recognize the issue. Of course, if NSString had a strip method I would have used it it automatically as I do in Python, and it never would have happened.

No comments: