Python
I recently integrated unit test code coverage analysis (using coverage) as a setuptools command extension into the DendroPy phylogenetic computing library, and thought that I would share how this was done.
The following is an example of how to use the "pkg_resources" module (provided by the setuptools project) to compose a list of all available modules in a Python package.
One of the great strengths of Git is the multiple and flexible ways of handling remote repositories. Just like Subversion, they can be "served" out of a location, but more generally, if you can reach it from your computer through any number of ways (ssh, etc.), you can git it.
YonderGit wraps up a number of a common operations with remote repositories: creating, initializing, adding to (associating with) the local repository, removing, etc.
You can clone your own copy of the YonderGit code repository using:
UPDATE Nov 7, 2009: Better parsing of traceback.
UPDATE Nov 4, 2009: Now passing a "-b" flag to the script opens the parsed stack frame references in a BBEdit results browser, inspired by an AppleScript script by Marc Liyanage.
When things go wrong in a Python script, the interpreter dumps a stack trace, which looks something like this:
I find this very useful:
The following function returns the current external ip address:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.google.com",80))
ipaddr, port = s.getsockname()
return ipaddr
The following code snippet will return the mode(s) of a list of values, using the specified bin size. If "bin_size" is set to "None", then values are not binned.
The following code snippet is useful to "pretty-print" a tuple of dictionaries as a plain text table.
The following script takes a space separated list of GenBank numbers as input, and then uses BioPython to download the corresponding sequences from GenBank, strips off all non-coding nucleotides, gives the sequences sensible names, and assembles them into a FASTA file.
I find this a pretty useful wrapper around SGE"s "qstat". Enhancements include much more compact representation of useful information (e.g., excludes "department"), and also allows sorting (or reverse sorting) by any one of the display columns:
feed