KMC is a disk-based program for counting k-mers from (possibly gzipped) FASTQ/FASTA files. KMC is one of many projects developed by REFRESH Bioinformatics Group.
For accessing k-mers stored in database produced by KMC there is an API (kmc_api directory). Note that for KMC versions 0.x and 1.x dababase format differs from produced by KMC version 2.x. From version 2.2.0 API is unified for both formats and all new features/bug fixes are present only for 2.x branch (standalone API for older KMC version is not longer under development, so new version of API should be used even for databases produced by older KMC version).
The simplest way to get the KMC is to download newest release for appropriate operating system from KMC releases.
./kmc -k27 input.fastq 27mers .
The command above will count all the 27-mers occurring in input.fastq
at least twice (configurable with -ci
switch).
The result will be stored in a KMC database, which is split into two files: 27mers.kmc_pre
and 27mers.kmc_suf
.
KMC will create hundreds of intermediate files. In the case of the above command, those will be created in the current working directory(the .
at the end of the command).
It may be more convinient to use dedicated directory for KMC temporary files, for example:
mkdir kmc_tmp # create directory for kmc temporary files
./kmc -k27 input.fastq 27mers kmc_tmp
Having the k-mers counted it is possible to dump KMC binary database to textual form with kmc_tools
.
./kmc_tools transform 27mers dump 27mers.txt
Installation details
git clone --recurse-submodules https://github.com/refresh-bio/kmc.git
cd kmc
make -j32
= The following libraries come with KMC in a binary (64-bit compiled for x86 platform) form. If your system needs other binary formats, you should put the following libraries in kmc_core/libs:
The following libraries come with KMC in a source coude form.
If needed, you can also redefine maximal length of k-mer, which is 256 in the current version.
Note: KMC is highly optimized and spends only as many bytes for k-mer (rounded up to 8) as necessary, so using large values of MAX_K does not affect the KMC performance for short k-mers.
Some parts of KMC use C++17 features, so you need a compatible C++ compiler
After that, you can run make to compile kmc and kmc_dump applications.
There might be a need to change g++ path in makefile_mac. If needed we recommend install g++ with brew (http://brew.sh/).
Note that KMC creates a hundreds of temporary files, while default limit for opened files is small for under MAC OS platform. To increase this number use following command before running KMC:
ulimit -n 2048
It is possible to use the KMC directly from C++ code through. Detailed API description is available at wiki
Python wrapper for KMC API was created using pybind11. Warning: python binding is experimental. The library used to create binding as well as public interface may change in the future. Warning 2: python wrapper for C++ KMC API is much slower (much, much more than I have been expecting) than native C++ API. In fact the first attempt to create python wrapper was to use ctypes, but it turned out it was even slower than in case when pybind11 is used. The wrapper is designed and was tested only for python3. The main goal was to make it as similar to C++ API as possible. For this reason the API may be not [pythonic] (https://blog.startifact.com/posts/older/what-is-pythonic.html) enough for regular python programmer. Suggestions or pull requests to make it more robust are welcome.
Python module wrapping KMC API must be compiled.
make py_kmc_api
As a result of pybind11 .so file (for linux and mac os) or .pyd (for windows) is created and may be used as a python module. *.pyd file is in fact DLL file, the only difference is its extension.
python3-config --extension-suffix
To be able to use this file one should make it visible for python. One way to do this is to extend PYTHONPATH environment variable. For linux/mac os one may just
source py_kmc_api/set_path.sh
while, for windows:
py_kmc_api\set_path.bat
it will export apropriate file. The example of Python wrapper for KMC API is presented in file: py_kmc_api/py_kmc_dump.py
Detailed API description is available at wiki
After compilation you will obtain two binaries:
KMC software distributed under GNU GPL 3 licence.
gzip is free, open-source
pybind11 (https://github.com/pybind/pybind11) is open-source (BDS-style license)
In case of doubt, please consult the original documentations.
Archival source codes, binaries and documentation = Archival source codes, binaries and documentation are available at wiki.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.