My reaction to the first half-dozen chapters is restrained, but I am still hopeful that the heart of the text will be interesting. His knowledge of Python is pretty good, though he doesn't seem to use list comprehension. Not that it matters, but he also doesn't seem to be very up-to-date about Macs (still hung up on the big-endian business which went out with the switch to Intel chips), and it looks like he wants to use Tkinter for a User Interface (Yeccch...). Here I take a look at the code for scoring a sequence alignment (Code 7-1).
He uses ord to convert a list of characters to decimal, then uses a vector operation from numpy to count the number of equal values (giving a vector of Booleans), then converts those to ints and finally sums them. Then, he does the whole thing again, to count mismatches. I thought, that's got to be slow. I just go through a zipped list of the sequences and compare each pair of characters. My code gives a different result for the case of two opposing '-' gap characters (he notes this issue in the text). A timing test shows his code is about 2.5x slower, which is a lot faster than I had guessed it would be. Of course, if we cared, we'd be using C. But, I think that if you use a complicated method to explain something this simple, you ought to have a very good reason for it.
from numpy import equal, not_equal |