Python

Posted by Jeet Sukumaran

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.

Posted by Jeet Sukumaran

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:

Posted by Jeet Sukumaran

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:

Posted by Jeet Sukumaran

I find this very useful:

Posted by Jeet Sukumaran

The following function returns the current external ip address:

def get_external_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("www.google.com",80))
    ipaddr, port = s.getsockname()
    return ipaddr
Posted by Jeet Sukumaran

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.

Posted by Jeet Sukumaran

The following code snippet is useful to "pretty-print" a tuple of dictionaries as a plain text table.

Posted by Jeet Sukumaran

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: