[Biopython-dev] Martel changes

Andrew Dalke adalke at mindspring.com
Wed Dec 12 05:21:59 EST 2001


I'm doing some work with Martel again.  Cayte asked
earlier about a way to simplify working with Martel
callbacks.  I outlined a possible simplification.

I've implemented it.  It's called 'SimpleFields'.
You can take a look at it at
  http://www.biopython.org/~dalke/SimpleFields.py

It supports both callback and iterative styles.
(See the module docstring for examples of each.)

I'm going to add it to CVS as soon as I think up
better names than 'SimpleFields' and 'groups'.
(Although I do like 'LAX' :)

Is anyone using the iterator facility in Martel?
I would like to change the API.  Currently you pass
it the factory function which produces SAX handlers.
I would rather just pass it a SAX handler, and
trust the handler to reset itself properly with the
startDocument/endDocument methods.  (Those which
don't can easily be wrapped.)

The problem with the current API is when the handler
needs parameters then you need to create something
which passed those parameters to each instance.  It's
ugly, and it's common... I think.  I also don't like
that the object is created for every record instead
of reusing the existing one.

I don't think anyone uses this feature, so I'll go
ahead and change it unless someone gives me a good
reason otherwise.

Finally, I'm adding some common patterns to the top-level
Martel/__init__.py.  These are for things like 'Word'
which is

def Word(name = None, attrs = None):
  exp = Re(r"\w+")
  if name is None:
    if attrs is not None:
        raise TypeError("....")
    return exp
  return Group(name, exp, attrs)

The idea is to make it easier to specify, say, a list
of words on line

format = Word("species") + Whitespace() + \
         Word("count") + Whitespace() + \
         ToEol("sequence")

Has anyone started building up a collection of those
common patterns?  I've got Integer, SignedInteger, Float,
Word, and Whitespace.  I'll probably add Spaces (for
only " "), NonSpaces (up to a " ").


Comments on any of these?

                    Andrew
                    dalke at dalkescientific.com





More information about the Biopython-dev mailing list