KSSD

May 27, 2026 · View on GitHub

KSSD logo

KSSD

K-mer substring space sampling / shuffling decomposition for large-scale DNA sequence sketching, resemblance estimation, and containment analysis

KSSD is a Linux command-line tool for sketching large collections of DNA sequences and estimating sequence resemblance or containment from reduced k-mer representations. It accepts FASTA and FASTQ input, including gzipped files, and can also sketch streamed sequence data, for example from SRA Toolkit commands.

KSSD differs from ordinary per-dataset k-mer sampling methods by using a predefined shuffled k-mer substring space. References and queries are mapped into the same sampled k-mer subspace, enabling efficient large-scale comparison while preserving both resemblance- and containment-oriented signals.

If you use KSSD, please cite the Genome Biology paper listed in Citation.


Contents


Features

  • Sketch DNA sequences from FASTA or FASTQ files.
  • Supports gzipped and uncompressed input files.
  • Builds indexed reference sketch databases.
  • Searches query sketches against reference sketch databases.
  • Computes pairwise resemblance and containment statistics.
  • Supports Jaccard-like and containment-oriented output modes.
  • Supports sketch union, intersection, subtraction, unique union, and pan-sketch combination operations.
  • Supports streaming input through --pipecmd.
  • Supports multi-threading when compiled with OpenMP.
  • Designed for Linux systems.

Installation

Requirements

KSSD is currently intended for Linux. A typical build requires:

  • gcc
  • make
  • zlib
  • OpenMP support, usually available through GCC

On Ubuntu or Debian:

sudo apt-get update
sudo apt-get install -y build-essential zlib1g-dev

Build from source

git clone https://github.com/yhg926/public_kssd.git
cd public_kssd
make

After compilation, the executable should be available as:

./kssd

You can optionally add the repository directory to your PATH.


Command overview

The executable exposes the following top-level subcommands:

CommandPurpose
kssd shuffleGenerate a shuffled k-mer substring-space file (.shuf).
kssd distSketch sequences, build/index reference sketches, and estimate distances or containment.
kssd setPerform set operations on sketches.
kssd reverseRecover k-mer sets from KSSD sketches.
kssd compositeAdvanced metagenomic composition analysis command.

Most users will mainly use shuffle, dist, and set.


Quick tutorial

The repository includes a small example dataset under test_fna/.

cd test_fna

# 1. Sketch and index reference sequences.
../kssd dist -L ../shuf_file/L3K10.shuf -o reference ./seqs1
../kssd dist -o reference reference

# 2. Sketch query sequences with the same .shuf file.
../kssd dist -L ../shuf_file/L3K10.shuf -o query ./seqs2

# 3. Search queries against the reference database.
../kssd dist -r reference -o distout query

# 4. Or compute pairwise distances among the reference sketches.
../kssd dist -r reference -o distout reference

The main output file is:

distout/distance.out

Core workflow

A common KSSD analysis has four stages:

Input FASTA/FASTQ files
        |
        v
Sketch sequences with a .shuf file
        |
        v
Build/index reference sketches
        |
        v
Compare query sketches against references
        |
        v
distance.out

Important: references and queries must be sketched using the same .shuf file. Otherwise, their sampled k-mer spaces are not comparable.


Choosing k-mer and reduction parameters

KSSD uses half-length notation for k-mers.

For example:

-k 8

means a full k-mer length of 16.

Common starting points

Data typeSuggested -kFull k-mer lengthSuggested reduction level
Bacterial / prokaryotic genomes816-L 2 or -L 3
Intermediate-size genomes918-L 3 or -L 4
Mammalian genomes or large metagenomic datasets10 or 1120 or 22-L 4 or -L 5

The expected dimensionality reduction rate for level L is approximately:

16^L

Examples:

LApproximate reduction
2256×
34,096×
465,536×
51,048,576×

Higher reduction levels produce smaller sketches and faster comparisons, but may reduce sensitivity.


Generate a shuffled k-mer substring space

A .shuf file defines the shuffled k-mer substring space used for sketching.

kssd shuffle \
  -k <half_kmer_length> \
  -s <half_substring_length> \
  -l <reduction_level> \
  -o <output_prefix_or_file>

Example:

kssd shuffle -k 8 -s 5 -l 3 -o bacteria_L3K8.shuf

Options:

OptionMeaningDefault in command help
-kHalf-length of the k-mer. Full k-mer length is 2 × k.8
-sHalf-length of the k-mer substring.5
-lDimensionality reduction level. Expected reduction is 16^l.2
-oOutput prefix or file name for the generated .shuf file../default
--usedefaultUse the default prokaryote-oriented setting: k=8, s=5, l=2.off

Parameter relationship:

l < s < k

You can also use the provided .shuf files under shuf_file/.


Sketch references

There are two common ways to sketch references.

A. Use an existing .shuf file

kssd dist \
  -L <shuf_file> \
  -o <reference_output_dir> \
  <reference_sequence_dir>

Example:

kssd dist -L shuf_file/L3K10.shuf -o reference genomes/

Then build/index the reference sketch database:

kssd dist -o reference reference

B. Let kssd dist generate a default .shuf file

kssd dist \
  -L <reduction_level> \
  -k <half_kmer_length> \
  -o <reference_output_dir> \
  <reference_sequence_dir>

Example:

kssd dist -L 3 -k 8 -o reference genomes/

When -L receives an integer instead of an existing .shuf file, KSSD generates and uses a shuffled space internally in the output directory.


Sketch queries

Queries must be sketched with the same .shuf file used for the references.

kssd dist \
  -L <same_shuf_file_used_for_references> \
  -o <query_output_dir> \
  <query_sequence_dir>

Example:

kssd dist -L shuf_file/L3K10.shuf -o query query_fastq/

Compare sketches

Search queries against references

kssd dist \
  -r <reference_sketch_dir> \
  -o <output_dir> \
  <query_sketch_dir>

Example:

kssd dist -r reference -o search_out query

The main result is:

search_out/distance.out

Pairwise comparison among references

kssd dist \
  -r <reference_sketch_dir> \
  -o <output_dir> \
  <reference_sketch_dir>

Example:

kssd dist -r reference -o pairwise_out reference

Useful dist options

OptionMeaningDefault / notes
-k, --halfKmerlength INTHalf k-mer length. Full k-mer length is 2 × k.8
-p, --threadN INTNumber of threads.all available threads if OpenMP is enabled
-l, --list fileFile containing paths to query sequences.optional
-L, --DimRdcLevel INT/fileReduction level or .shuf file.2
-m, --maxMemory NUMMaximum memory in GB.system memory
-n, --LstKmerOcrs INTMinimum k-mer occurrence threshold in FASTQ input.1, capped internally at 7
-Q, --quality INTFilter k-mers with lowest base quality below this Phred value.0
-r, --reference_dir pathReference sketch/database directory.optional
-o, --outdir pathOutput directory..
-N, --neighborN_max INTMaximum number of nearest reference genomes to report.command help says 1; internal default is 0
-D, --mutDist_max FLTMaximum mutation distance allowed for output.1
-M, --metric 0/1Output metric: 0 = Jaccard, 1 = containment.0
-O, --outfields 0/1/2Output fields: distance, q-values, confidence intervals. Later levels include earlier ones.2
--correction 0/1Correct shared k-mer counts or not.0
-A, --abundanceAbundance-estimation mode.off
-u, --dedupIgnore repeated k-mers in reference.off
--keepcofileKeep intermediate .co files.off
--pipecmd cmdRead input from a pipe command.optional
--keepskfKeep shared-kmer-count file.off
-f, --skf pathShared-kmer-count file path.optional
--byreadSketch input by read.off

Sketch from streaming input

KSSD can sketch sequence data from a command pipeline. This is useful for SRA accessions.

Example using fastq-dump:

kssd dist \
  -L <shuf_file> \
  -n 2 \
  -o <output_dir> \
  --pipecmd "fastq-dump --skip-technical --split-spot -Z" \
  ERR000001

Or after prefetching the SRA file:

prefetch ERR000001

kssd dist \
  -L <shuf_file> \
  -n 2 \
  -o <output_dir> \
  --pipecmd "fastq-dump --skip-technical --split-spot -Z" \
  /path/to/ERR000001.sra

Combine query batches

If query sketches were generated in multiple batches using the same .shuf file, they can be combined:

kssd dist \
  -o <combined_output_dir> \
  <query_batch_1> <query_batch_2> ...

Example:

kssd dist -o combined_queries query_batch1 query_batch2 query_batch3

All batches must have been generated with compatible sketch parameters.


Set operations

kssd set operates on combined sketch directories.

Union

kssd set -u -o <union_output_dir> <combined_sketch_dir>

Example:

kssd set -u -o union_out query/qry

Unique union

kssd set -q -o <unique_union_output_dir> <combined_sketch_dir>

Intersection with a pan-sketch

kssd set -i <pan_sketch_dir> -o <intersection_output_dir> <combined_sketch_dir>

Example:

kssd set -i union_out -o intersect_out query/qry

Subtraction of a pan-sketch

kssd set -s <pan_sketch_dir> -o <subtraction_output_dir> <combined_sketch_dir>

Example:

kssd set -s union_out -o subtract_out query/qry

Other set options

OptionMeaning
-c, --combin_panCombine pan files into a combined sketch file.
-p, --threads INTNumber of threads.
-P, --printPrint genome names.
-g, --grouping file.tsvGroup genomes by an input category file.
-o, --outdir pathOutput directory.

Reverse sketches to k-mer sets

kssd reverse is an advanced command for recovering k-mer sets from KSSD sketch directories.

kssd reverse \
  -L <shuf_file> \
  -o <output_dir> \
  <co_dir>

Options:

OptionMeaning
-L, --shufFile pathProvide the .shuf file used for sketching.
-o, --outdir pathOutput directory for recovered k-mer files.
-p, --threads INTNumber of threads.
-b, --byreadsRecover k-mers from sketches generated by read.

Output: distance.out

The main comparison result is written to:

<output_dir>/distance.out

Typical columns include:

ColumnDescription
QryQuery sequence or sketch name.
RefReference sequence or sketch name.
Shared_kNumber of shared sampled k-mers between query and reference sketches.
Ref_sReference sketch size.
Qry_sQuery sketch size.
JaccardJaccard coefficient.
MashDMash-style distance.
ContainmentMContainment measurement.
AafDAAF-style distance.
Jaccard_CI95% confidence interval for Jaccard.
MashD_CI95% confidence interval for Mash distance.
ContainmentM_CI95% confidence interval for containment measurement.
AafD_CI95% confidence interval for AAF distance.
P-value(J)P-value for Jaccard.
P-value(C)P-value for containment.
FDR(J)False discovery rate for Jaccard.
FDR(C)False discovery rate for containment.

The exact fields may depend on options such as -M and -O.


Notes and limitations

  • KSSD currently targets Linux. macOS and Windows are not officially supported.
  • References and queries must be sketched with the same .shuf file.
  • Report the .shuf file, -k, -s, reduction level, KSSD version, and command lines in reproducible analyses.
  • Very high reduction levels reduce sketch size and runtime but may reduce sensitivity.
  • Some advanced commands, especially composite, are exposed by the executable but are less documented than the main shuffle, dist, and set workflow.

Citation

If you use KSSD, please cite:

Yi, H., Lin, Y., Lin, C. et al.
Kssd: sequence dimensionality reduction by k-mer substring space sampling enables real-time large-scale datasets analysis.
Genome Biology 22, 84 (2021).
https://doi.org/10.1186/s13059-021-02303-4

License

KSSD is distributed under the Apache License, Version 2.0. See LICENSE.txt for details.


Contact

Please use the GitHub Issues page for bug reports, questions, and feature requests:

https://github.com/yhg926/public_kssd/issues