Development miscellany

Third-party use

We ask that third parties who build upon the codebase to do so from a versioned release. This will help them determine when bug fixes apply and generally make it easier to collaborate. If more intensive modifications happen then we request that the repository is forked, again preferably from a version tag.

Build framework

‘make’ should build everything, including tests and “development” code.

Coding standards

All plain-text files should have line widths of 80 characters or less unless that is not supported for the particular file format.

For C++, we use Todd Hoff’s coding standard, and astyle -A10 / “One True Brace Style” indentation and bracing. Note: @CTB needs emacs settings that work for this.

Vim users may want to set the ARTISTIC_STYLE_OPTIONS shell variable to “-A10 –max-code-length=80” and run `:%!astyle` to reformat. The four space indentation can be set with:

set expandtab
set shiftwidth=4
set softtabstop=4

For Python, PEP 8 is our standard. The `pep8` and `autopep8` Makefile targets are helpful.

Code, scripts, and documentation must have its spelling checked. Vim users can run:

:setlocal spell spelllang=en_us

Use ]s and [s to navigate between misspellings and z= to suggest a correctly spelled word. zg will add a word as a good word.

GNU’s aspell can also be used to check the spelling in a single file:

aspell check --mode ccpp $filename


Copy and paste the following into a pull-request when it is ready for review:

- [ ] Is it mergable
- [ ] Did it pass the tests?
- [ ] If it introduces new functionality in scripts/ is it tested?
  Check for code coverage.
- [ ] Is it well formatted? Look at `pep8`/`pylint`, `cppcheck`, and
  `make doc` output. Use `autopep8` and `astyle -A10 --max-code-length=80`
  if needed.
- [ ] Is it documented in the Changelog?
- [ ] Was spellcheck run on the source code and documentation after changes
  were made?

git and github strategies

Still in the works, but read this.

Make a branch on ged-lab (preferred so others can contribute) or fork the repository and make a branch there.

Each piece or fix you are working on should have its own branch; make a pull- request to ged-lab/master to aid in code review, testing, and feedback.

If you want your code integrated then it needs to be mergeable

Example pull request update using the command line:

  1. Clone the source of the pull request (if needed)

    git clone

  2. Checkout the source branch of the pull request

    git checkout my-pull-request

  3. Pull in the destination of the pull request and resolve any conflicts

    git pull master

  4. Push your update to the source of the pull request git push

  5. Jenkins will automatically attempt to build and test your pull requests.


./ nosetest is the canonical way to run the tests. This is what make test does.

Code coverage

Jenkins calculates code coverage for every build. Navigate to the results from the master node first to view the coverage information.

Code coverage should never go down and new functionality needs to be tested.


All khmer scripts used by a published recommended analysis pipeline must be included in scripts/ and meet the standards therein implied.

Command line scripts

Python command-line scripts should use ‘-‘ instead of ‘_’ in the name. (Only filenames containing code for import imported should use _.)

Please follow the command-line conventions used under scripts/. This includes most especially standardization of ‘-x’ to be hash table size, ‘-N’ to be number of hash tables, and ‘-k’ to always refer to the k-mer size.

Command line thoughts:

If a filename is required, typically UNIX commands don’t use a flag to specify it.

Also, positional arguments typically aren’t used with multiple files.

CTB’s overall philosophy is that new files, with new names, should be created as the result of filtering etc.; this allows easy chaining of commands. We’re thinking about how best to allow override of this, e.g. <kh file> <filename> [ -o <filename.keep> ]

All code in scripts/ must have automated tests; see tests/ Otherwise it belongs in sandbox/.

When files are overwritten, they should only be opened to be overwritten after the input files have been shown to exist. That prevents stupid command like mistakes from trashing important files.

It would be nice to allow piping from one command to another where possible. But this seems complicated.

CTB: should we squash output files (overwrite them if they exist), or not? So far, leaning towards ‘not’, as that way no one is surprised and loses their data.

A general error should be signaled by exit code 1 and success by 0. Linux supports exit codes from 0 to 255 where the value 1 means a general error. An exit code of -1 will get converted to 255.

CLI reading:

Python / C integration

The Python extension that wraps the C++ core of khmer lives in khmer/_khmermodule.CC

This wrapper code is tedious and annoying so we use a static analysis tool to check for correctness.

Developers using Ubuntu Precise will want to install the gcc-4.6-plugin-dev package

Example usage:

--maxtrans=512" python build_ext 2>&1 | less

False positives abound: ignore errors about the C++ standard library. This tool is primarily useful for reference count checking, error-handling checking, and format string checking.

Errors to ignore: “Unhandled Python exception raised calling ‘execute’ method”, “AttributeError: ‘NoneType’ object has no attribute ‘file’”

Warnings to address:

khmer/ note: this function is too complicated
for the reference-count checker to fully analyze: not all paths were

Adjust –maxtrans and re-run.

khmer/ warning: Mismatching type in call to
Py_BuildValue with format code "i" [enabled by default]
  argument 2 ("D.68937") had type
    "long long unsigned int"
  but was expecting
  for format code "i"

See below for a format string cheatsheet One also benefits by matching C type with the function signature used later.

“I” for unsigned int “K” for unsigned long long a.k.a khmer::HashIntoType.

comments powered by Disqus