Skip to content

Python bindings Examples

Anuradha Wickramarachchi edited this page Mar 28, 2026 · 1 revision

Python bindings examples

All runnable Python examples are in ./examples/python. For completeness, this folder includes duplicated FASTA input data in:

Setup

Install bindings:

pip install pykmertools

Or via Bioconda:

conda install -c bioconda kmertools

Run each script from the repository root.

1. Utility conversion helpers

Script: utils_roundtrip.py

python kmertools.wiki/examples/python/utils_roundtrip.py

Shows:

  • ACGT string -> (forward, reverse) numeric tuple
  • numeric -> ACGT roundtrip

2. K-mer iterator API

Script: kmer_generator.py

python kmertools.wiki/examples/python/kmer_generator.py

Shows:

  • iterating (forward, reverse) integer k-mers
  • converting iterator output back to strings
  • using kmer_pos_maps()

3. Minimiser iterator API

Script: minimiser_generator.py

python kmertools.wiki/examples/python/minimiser_generator.py

Shows:

  • iterating (minimiser, start, end)
  • mapping minimisers to sequence spans via seq[start:end]
  • converting minimiser ints to strings with to_acgt

4. Oligonucleotide vectors

Script: oligo_vectors.py

python kmertools.wiki/examples/python/oligo_vectors.py

Shows:

  • vectorise_one and vectorise_batch
  • mins=True headers and top features
  • raw forward-space vectors with mins=False

5. CGR vectors

Script: cgr_vectors.py

python kmertools.wiki/examples/python/cgr_vectors.py

Shows:

  • sequence-to-CGR point conversion
  • batch CGR conversion
  • invalid-base error handling

6. Plot CGR using Python API from FASTA input

Script: cgr_api_plots.py

python kmertools.wiki/examples/python/cgr_api_plots.py

Inputs:

Outputs:

Simple plot conventions used:

  • x-axis and y-axis are always labeled.
  • colorbar is labeled for density plot.

Clone this wiki locally