ALL Metrics
-
Views
-
Downloads
Get PDF
Get XML
Cite
Export
Track
Software Tool Article

The khmer software package: enabling efficient nucleotide sequence analysis

[version 1; peer review: 2 approved, 1 approved with reservations]
PUBLISHED 25 Sep 2015
Author details Author details
OPEN PEER REVIEW
REVIEWER STATUS

This article is included in the Iowa State University collection.

Abstract

The khmer package is a freely available software library for working efficiently with fixed length DNA words, or k-mers. khmer provides implementations of a probabilistic k-mer counting data structure, a compressible De Bruijn graph representation, De Bruijn graph partitioning, and digital normalization. khmer is implemented in C++ and Python, and is freely available under the BSD license at https://github.com/dib-lab/khmer/.

Keywords

bioinformatics, dna sequencing analysis, k-mer, kmer, khmer, online, low-memory, streaming

Introduction

DNA words of a fixed-length k, or “k-mers”, are a common abstraction in DNA sequence analysis that enable alignment-free sequence analysis and comparison. With the advent of second-generation sequencing and the widespread adoption of De Bruijn graph-based assemblers, k-mers have become even more widely used in recent years. However, the dramatically increased rate of sequence data generation from Illumina sequencers continues to challenge the basic data structures and algorithms for k-mer storage and manipulation. This has led to the development of a wide range of data structures and algorithms that explore possible improvements to k-mer-based approaches.

Here we present version 2.0 of the khmer software package, a high-performance library implementing memory- and time-efficient algorithms for the manipulation and analysis of short-read data sets. khmer contains reference implementations of several approaches, including a probabilistic k-mer counter based on the CountMin Sketch1, a compressible De Bruijn graph representation built on top of Bloom filters2, a streaming lossy compression approach for short-read data sets termed “digital normalization”3, and a generalized semi-streaming approach for k-mer spectral analysis of variable-coverage shotgun sequencing data sets4.

khmer is both research software and a software product for users: it has been used in the development of novel data structures and algorithms, and it is also immediately useful for certain kinds of data analysis (discussed below). We continue to develop research extensions while maintaining existing functionality.

The khmer software consists of a core library implemented in C++, a CPython library wrapper implemented in C, and a set of Python “driver” scripts that make use of the library to perform various sequence analysis tasks. The software is currently developed on GitHub under https://github.com/dib-lab/khmer, and it is released under the BSD License. There is greater than 87% statement coverage under automated tests, measured on both C++ and Python code but primarily executed at the Python level.

Methods

Implementation

The core data k-mer counting data structures and graph traversal code are implemented in C++, and then wrapped for Python in hand-written C code, for a total of 10.5k lines of C/C++ code. The command-line API and all of the tests are written in 13.7k lines of Python code. C++ FASTQ and FASTA parsers came from the SeqAn library5.

Documentation is written in reStructuredText, compiled with Sphinx, and hosted on ReadTheDocs.org.

We develop khmer on github.com as a community open source project focused on sustainable software development6, and encourage contributions of any kind. As an outcome of several community events, we have comprehensive documentation on contributing to khmer at https://khmer.readthedocs.org/en/latest/dev/7. Most development decisions are discussed and documented publicly as they happen.

Operation

khmer is primarily developed on Linux for Python 2.7 and 64-bit processors, and several core developers use Mac OS X. The project is tested regularly using the Jenkins continuous integration system running on Ubuntu 14.04 LTS and Mac OS X 10.10; the current development branch is also tested under Python 3.3, 3.4, and 3.5. Releases are tested against many Linux distributions, including RedHat Enterprise Linux, Debian, Fedora, and Ubuntu. khmer should work on most UNIX derivatives with little modification. Windows is explicitly not supported.

Memory requirements for using khmer vary with the complexity of data and are user configurable. Several core data structures can trade memory for false positives, and we have explored these details in several papers, most notably Pell et al. 20122 and Zhang et al. 20141. For example, most single organism mRNAseq data sets can be processed in under 16 GB of RAM3,8, while memory requirements for metagenome data sets may vary from dozens of gigabytes to terabytes of RAM.

The user interface for khmer is via the command line. The command line interface consists of approximately 25 Python scripts; they are documented at http://khmer.readthedocs.org/ under User Documentation. Changes to the interface are managed with semantic versioning9 which guarantees command line compatibility between releases with the same major version.

khmer also has an unstable developer interface via its Python and C++ libraries, on which the command line scripts are built.

Use cases

khmer has several complementary feature sets, all centered on short-read manipulation and filtering. The most common use of khmer is for preprocessing short read Illumina data sets prior to de novo sequence assembly, with the goals of decreasing compute requirements for the assembler as well as potentially improving the assembly results.

Prefiltering sequence data for de novo assembly with digital normalization

We provide an implementation of a novel streaming “lossy compression” algorithm in khmer that performs abundance normalization of shotgun sequence data. This “digital normalization” algorithm eliminates redundant short reads while retaining sufficient information to generate a contig assembly3. The algorithm takes advantage of the online k-mer counting functionality in khmer to estimate per-read coverage as reads are examined; reads can then be accepted as novel or rejected as redundant. This is a form of error reduction, because the net effect is to decrease not only the total number of reads considered for assembly, but also the total number of errors considered by the assembler. Digital normalization results in a decrease of the amount of memory needed for de novo assembly of high-coverage data sets with little to no change in the assembled contigs.

Digital normalization is implemented in the script normalize-by-median.py. This script takes as input a list of FASTA or FASTQ files, which it then filters by abundance as described above; see 3 for details. The output of the digital normalization script is a downsampled set of reads, with no modifications to the individual reads. The three key parameters for the script are the k-mer size, the desired coverage level, and the amount of memory to be used for k-mer counting. The interaction between these three parameters and the filtering process is complex and depends on the data set being processed, but higher coverage levels and longer k-mer sizes result in less data being removed. Lower memory allocation increases the rate at which reads are removed due to erroneous estimates of their abundance, but this process is very robust in practice1.

The output of normalize-by-median.py can be assembled using a de novo assembler such as Velvet10, IDBA11, Trinity12 or SPAdes13.

K-mer counting and read trimming

Using a memory-efficient CountMin Sketch data structure, khmer provides an interface for online counting of k-mers in streams of reads. The basic functionality includes calculating the k-mer frequency spectrum in sequence data sets and trimming reads at low-abundance k-mers. This functionality is explored and benchmarked in1.

Basic read trimming is performed by the script filter-abund.py, which takes as arguments a k-mer countgraph (created by khmer’s load-into-counting.py script) and one or more sequence data files. The script examines each sequence to find k-mers below the given abundance cutoff, and truncates the sequence at the first such k-mer. This truncates reads at the location of substitution errors produced by the sequencing process. When processing sequences from variable coverage data sets, filter-abund.py can also be configured to ignore reads that have low estimated abundance.

K-mer abundance distributions can be calculated using the script abundance-dist.py, which takes as arguments a k-mer countgraph, a sequence data file, and an output filename. This script determines the abundance of each distinct k-mer in the data file according to the k-mer countgraph, and summarizes the abundances in a histogram output.

We recently extended digital normalization to provide a generalized semi-streaming approach for k-mer spectral analysis4. Here, we examine read coverage on a per-locus basis in the De Bruijn graph and, once a particular locus has sufficient coverage, call errors or trim bases for all following reads belonging to that graph locus. The approach is “semi-streaming”4 because some reads must be examined twice. This semi-streaming approach enables few-pass analysis of high coverage data sets. More, the approach also makes it possible to apply k-mer spectral analysis to data sets with uneven coverage such as metagenomes, transcriptomes, and whole-genome amplified samples.

Because our core data structure sizes are preallocated based on estimates of the unique k-mer content of the data, we also provide fast and low-memory k-mer cardinality estimation via the script unique-kmers.py. This script uses the HyperLogLog algorithm to provide a probabilistic estimate of the number of unique k-mers in a data set with a guaranteed upper bound14. A manuscript on this implementation is in progress (Irber and Brown, unpublished).

Partitioning reads into disconnected assembly graphs

We have also built a De Bruijn graph representation on top of a Bloom filter, and implemented this in khmer. The primary use for this so far has been to enable memory efficient graph partitioning, in which reads contributing to disconnected subgraphs are placed into different files. This can lead to an approximately 20-fold decrease in the amount of memory needed for metagenome assembly2, and may also separate reads into species-specific bins15.

Reformatting collections of short reads

In support of the streaming nature of this project, our preferred paired-read format is with pairs interleaved in a single file. As an extension of this, we automatically support a “broken-paired” read format where orphaned reads and pairs coexist in a single file. This enables single input/output streaming connections between tools, while leaving our tools compatible with fully paired read files as well as files containing only orphaned reads.

For converting to and from this format, we supply the scripts extract-paired-reads.py, interleave-reads.py, and split-paired-reads.py to respectively extract fully paired reads from sequence files, interleave two files containing read pairs, and split an interleaved file into two files containing read pairs.

In addition, we supply several utility scripts that we use in our own work. These include sample-reads-randomly.py for performing reservoir sampling of reads and readstats.py for summarizing sequence files.

Summary

The khmer project is an increasingly mature open source scientific software project that provides several efficient data structures and algorithms for analyzing short-read nucleotide sequencing data. khmer emphasizes online analysis, low memory data structures and streaming algorithms. khmer continues to be useful for both advancing bioinformatics research and analyzing biological data.

Software availability

Link to archived source code as at time of publication

http://dx.doi.org/10.5281/zenodo.3125816

Software license

Michael Crusoe: Copyright: 2010–2015, Michigan State University. Copyright: 2015, The Regents of the University of California. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the Michigan State University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Comments on this article Comments (4)

Version 1
VERSION 1 PUBLISHED 25 Sep 2015
  • Reader Comment 20 Apr 2022
    Lior Pachter, California Institute of Technology, Pasadena, California, USA
    20 Apr 2022
    Reader Comment
    The comment by Russell Neches implies that by mentioning Nathan Kohn's name I revealed a protected pseudonym, i.e. that I doxxed an author, and by doing so violated a long-standing ... Continue reading
  • Reader Comment 01 Oct 2015
    Russell Neches, UC Davis, USA
    01 Oct 2015
    Reader Comment
    I wold like to make a comment regarding Lior Pachter's comment.

    The use of pseudonyms has a long and important history in scientific discourse. 

    Despite the fact that we now know its author's ... Continue reading
  • Reader Comment 28 Sep 2015
    F1000Research
    28 Sep 2015
    Reader Comment
    Thank you for bringing this to our attention.
     
    Because F1000Research does not have editors and the authors are in charge of their publication, one of the key requirements for publication is ... Continue reading
  • Reader Comment 28 Sep 2015
    Lior Pachter, University of California, Berkeley, USA
    28 Sep 2015
    Reader Comment
    This article appears to violate the F1000 criteria for authorship mentioned here and defined in the "uniform requirements". Specifically, the contribution of "one or more Git commits" in the code ... Continue reading
Author details Author details
Competing interests
Grant information
Copyright
Download
 
Export To
metrics
Views Downloads
F1000Research - -
PubMed Central
Data from PMC are received and updated monthly.
- -
Citations
CITE
how to cite this article
Crusoe MR, Alameldin HF, Awad S et al. The khmer software package: enabling efficient nucleotide sequence analysis [version 1; peer review: 2 approved, 1 approved with reservations] F1000Research 2015, 4:900 (https://doi.org/10.12688/f1000research.6924.1)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.
track
receive updates on this article
Track an article to receive email alerts on any updates to this article.

Open Peer Review

Current Reviewer Status: ?
Key to Reviewer Statuses VIEW
ApprovedThe paper is scientifically sound in its current form and only minor, if any, improvements are suggested
Approved with reservations A number of small changes, sometimes more significant revisions are required to address specific details and improve the papers academic merit.
Not approvedFundamental flaws in the paper seriously undermine the findings and conclusions
Version 1
VERSION 1
PUBLISHED 25 Sep 2015
Views
280
Cite
Reviewer Report 08 Oct 2015
Rob Patro, Computer Science Department, Stony Brook University, Stony Brook, NY, USA 
Approved
VIEWS 280
This paper describes version 2 of the khmer software suite.  The software is developed to provide both a set of directly usable tools (e.g. normalize-by-median for digital normalization) as well as an experimental framework for developers looking to design new ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Patro R. Reviewer Report For: The khmer software package: enabling efficient nucleotide sequence analysis [version 1; peer review: 2 approved, 1 approved with reservations]. F1000Research 2015, 4:900 (https://doi.org/10.5256/f1000research.7456.r10508)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.
Views
310
Cite
Reviewer Report 06 Oct 2015
Daniel S. Katz, Computation Institute, University of Chicago, Chicago, IL, USA 
Approved
VIEWS 310
Regarding the paper, it is a fairly straightforward description of a software package, containing all the things that such a paper should have - a description of the goals, the implemented methods, the hardware and software dependencies (systems on which ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Katz DS. Reviewer Report For: The khmer software package: enabling efficient nucleotide sequence analysis [version 1; peer review: 2 approved, 1 approved with reservations]. F1000Research 2015, 4:900 (https://doi.org/10.5256/f1000research.7456.r10513)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.
  • Reviewer Response 06 Oct 2015
    Daniel S. Katz, Computation Institute, University of Chicago, Chicago, USA
    06 Oct 2015
    Reviewer Response
    In addition to my report, regarding software papers in general under F1000, I believe that much more should be required from their reviewers, and what is required should be made clear.  Software ... Continue reading
  • Reader Comment 08 Oct 2015
    F1000Research
    08 Oct 2015
    Reader Comment
    Thanks for this helpful feedback on our guidelines.
     
    Our current guidelines for reviewing software tools are focused around the content of the article itself, and what information should be included. However, ... Continue reading
COMMENTS ON THIS REPORT
  • Reviewer Response 06 Oct 2015
    Daniel S. Katz, Computation Institute, University of Chicago, Chicago, USA
    06 Oct 2015
    Reviewer Response
    In addition to my report, regarding software papers in general under F1000, I believe that much more should be required from their reviewers, and what is required should be made clear.  Software ... Continue reading
  • Reader Comment 08 Oct 2015
    F1000Research
    08 Oct 2015
    Reader Comment
    Thanks for this helpful feedback on our guidelines.
     
    Our current guidelines for reviewing software tools are focused around the content of the article itself, and what information should be included. However, ... Continue reading
Views
605
Cite
Reviewer Report 05 Oct 2015
Ewan Birney, European Molecular Biology Laboratory, European Bioinformatics Institute, Hinxton, UK 
Approved with Reservations
VIEWS 605
This is an update of a widely used tool, khmer, which is in broad use in the technical community around de Bruijn graphs and short reads, based on Bloom filters. It is a good update, provides link to the code, ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Birney E. Reviewer Report For: The khmer software package: enabling efficient nucleotide sequence analysis [version 1; peer review: 2 approved, 1 approved with reservations]. F1000Research 2015, 4:900 (https://doi.org/10.5256/f1000research.7456.r10514)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.

Comments on this article Comments (4)

Version 1
VERSION 1 PUBLISHED 25 Sep 2015
  • Reader Comment 20 Apr 2022
    Lior Pachter, California Institute of Technology, Pasadena, California, USA
    20 Apr 2022
    Reader Comment
    The comment by Russell Neches implies that by mentioning Nathan Kohn's name I revealed a protected pseudonym, i.e. that I doxxed an author, and by doing so violated a long-standing ... Continue reading
  • Reader Comment 01 Oct 2015
    Russell Neches, UC Davis, USA
    01 Oct 2015
    Reader Comment
    I wold like to make a comment regarding Lior Pachter's comment.

    The use of pseudonyms has a long and important history in scientific discourse. 

    Despite the fact that we now know its author's ... Continue reading
  • Reader Comment 28 Sep 2015
    F1000Research
    28 Sep 2015
    Reader Comment
    Thank you for bringing this to our attention.
     
    Because F1000Research does not have editors and the authors are in charge of their publication, one of the key requirements for publication is ... Continue reading
  • Reader Comment 28 Sep 2015
    Lior Pachter, University of California, Berkeley, USA
    28 Sep 2015
    Reader Comment
    This article appears to violate the F1000 criteria for authorship mentioned here and defined in the "uniform requirements". Specifically, the contribution of "one or more Git commits" in the code ... Continue reading
Alongside their report, reviewers assign a status to the article:
Approved - the paper is scientifically sound in its current form and only minor, if any, improvements are suggested
Approved with reservations - A number of small changes, sometimes more significant revisions are required to address specific details and improve the papers academic merit.
Not approved - fundamental flaws in the paper seriously undermine the findings and conclusions
Sign In
If you've forgotten your password, please enter your email address below and we'll send you instructions on how to reset your password.

The email address should be the one you originally registered with F1000.

Email address not valid, please try again

You registered with F1000 via Google, so we cannot reset your password.

To sign in, please click here.

If you still need help with your Google account password, please click here.

You registered with F1000 via Facebook, so we cannot reset your password.

To sign in, please click here.

If you still need help with your Facebook account password, please click here.

Code not correct, please try again
Email us for further assistance.
Server error, please try again.