---
title: 'CA-MER: Chaos Game-Based k-MER Representation'
url: https://www.emergentmind.com/topics/ca-mer
type: topic
---

# CA-MER: Chaos Game-Based k-MER Representation

CA-MER, short for Chaos-game-based \(k\)-MER representations, denotes the use of Chaos Game Representation (CGR) and Frequency CGR (FCGR) as encodings of DNA \(k\)-mer statistics. In the formal framework established for DNA over \(\Sigma=\{A,C,G,T\}\), a CGR discretized at resolution \(2^k\times 2^k\) is mathematically equivalent to the FCGR of order \(k\), and vectorization of that FCGR is exactly the \(k\)-mer frequency vector up to a fixed bijection between pixels and \(k\)-mers. CA-MER therefore unifies geometric visualization, histogram-based image representations, and classical compositional statistics within a single mathematical object [2506.22172].

## 1. Formal definition of CGR in the CA-MER framework

For the nucleotide alphabet \(\Sigma=\{A,C,G,T\}\), CGR is defined on an axis-aligned square centered at the origin with side length \(2\):
\[
\{(x,y)\mid -1 < x < 1,\; -1 < y < 1\}.
\]
The four vertices are assigned nucleotides by
\[
\text{label}(A)=(-1,-1),\quad \text{label}(C)=(-1,1),\quad \text{label}(G)=(1,1),\quad \text{label}(T)=(1,-1).
\]

Given a DNA sequence \(s=a_1a_2\dots a_n\in\Sigma^n\), its CGR is the sequence of points \(\{p_0,p_1,\dots,p_n\}\subset\mathbb{Q}^2\) defined by
\[
p_0=(0,0),\qquad p_i=\frac{p_{i-1}+\text{label}(a_i)}{2},\quad 1\le i\le n.
\]
Each base is therefore plotted at the midpoint between the previous point and the vertex associated with that base. In this formulation, CGR is an iterative affine map rather than a purely heuristic image-generation procedure.

A key object is the last point of the CGR of a word \(w\in\Sigma^+\), denoted \(p_{\text{last}(w)}=p_{|w|}\). If \(w=a_1\cdots a_k\) and \(\text{label}(a_\ell)=(x_\ell,y_\ell)\) with \(x_\ell,y_\ell\in\{-1,1\}\), then the coordinates of the last point admit the closed form
\[
x_w=\frac{\sum_{\ell=1}^k x_\ell 2^{\ell-1}}{2^k},\qquad
y_w=\frac{\sum_{\ell=1}^k y_\ell 2^{\ell-1}}{2^k}.
\]
This expression is central because it turns the recursive geometry of CGR into an explicit combinatorial encoding of \(k\)-mers.

## 2. FCGR as discretized CGR and as a \(k\)-mer count array

For a fixed order \(k\ge 1\), the CGR square is partitioned into a uniform \(2^k\times 2^k\) grid. A grid cell of order \(k\) with indices \(0\le i,j\le 2^k-1\) is centered at
\[
(x_j,y_i)=\left(-\frac{2^k-1}{2^k}+\frac{j}{2^{k-1}},\;\frac{2^k-1}{2^k}-\frac{i}{2^{k-1}}\right),
\]
with matrix indexing convention \(i\) from top to bottom and \(j\) from left to right. The FCGR of order \(k\) is then the histogram
\[
FCGR_k(s)(i,j)=\mathrm{card}\bigl(CGR(s)\cap \text{cell}_k(i,j)\bigr),
\]
so FCGR is exactly the point density of CGR on the \(2^k\times 2^k\) grid.

For each \(k\)-mer \(w\in\Sigma^k\), the corresponding CGR cell \(c(w)\) is the open square centered at \(p_{\text{last}(w)}\) with side \(2^{1-k}\). The framework establishes three structural facts: \(p_{\text{last}(w)}\) is the center of \(c(w)\); the cells \(c(w)\) for distinct \(w\in\Sigma^k\) are disjoint; and there are exactly \(4^k\) such cells. Proposition 1 proves that these cells coincide with the grid partition: each \(k\)-mer corresponds to exactly one FCGR pixel, and each pixel corresponds to exactly one \(k\)-mer [2506.22172].

The central theorem states that for any sequence \(s\in\Sigma^n\) and any \(k\)-mer \(w\in\Sigma^k\) with \(1\le k\le n\),
\[
occ(s,w)=\mathrm{card}\bigl(CGR(s)\cap c(w)\bigr).
\]
Thus the number of occurrences of \(w\) in the sequence is exactly the number of CGR points falling in the cell associated with \(w\). Combined with the bijection between \(k\)-mers and pixels, this yields Corollary 4: the FCGR matrix \(FCGR_k(s)\) obtained by discretizing \(CGR(s)\) at resolution \(2^k\times 2^k\) is exactly the array of \(k\)-mer counts. The same result also implies that no CGR point lies on a cell boundary, so the use of open cells is unambiguous.

A common misconception is that FCGR images at fixed order \(k\) necessarily contain information beyond classical \(k\)-mer composition. In this framework they do not: at order \(k\), FCGR, discretized CGR, and the \(k\)-mer count vector are exact reformulations of one another.

## 3. Pixel assignment, binary decoding, and lexicographic order

The correspondence between \(k\)-mers and FCGR pixels can be expressed geometrically or combinatorially. In the geometric form, if \(w=a_1\cdots a_k\) with \(\text{label}(a_\ell)=(x_\ell,y_\ell)\), the associated pixel indices are
\[
j=\frac{2^k-1+\sum_{\ell=1}^k x_\ell 2^{\ell-1}}{2},\qquad
i=\frac{2^k-1-\sum_{\ell=1}^k y_\ell 2^{\ell-1}}{2}.
\]
Taken over all \(w\in\Sigma^k\), this produces a bijection between the \(4^k\) pixels of the FCGR and the \(4^k\) possible \(k\)-mers.

The paper also introduces a base-4 lexicographic indexing of \(k\)-mers using
\[
\xi(A)=0,\qquad \xi(C)=1,\qquad \xi(G)=2,\qquad \xi(T)=3,
\]
and
\[
\mathrm{idx}(w)=\sum_{t=1}^{k}4^{k-t}\,\xi(a_t)\in\{0,\dots,4^k-1\}.
\]
This induces the lexicographic order \(A<C<G<T\). If the pixel coordinates satisfy
\[
i=\sum_{\ell=0}^{k-1}\alpha_\ell 2^\ell,\qquad
j=\sum_{\ell=0}^{k-1}\beta_\ell 2^\ell,
\]
with \(\alpha_\ell,\beta_\ell\in\{0,1\}\), then Lemma 5 gives the inverse decoding rule
\[
a_\ell=\text{label}^{-1}\bigl(1-2\alpha_{\ell-1},\;2\beta_{\ell-1}-1\bigr),\qquad \ell=1,\dots,k.
\]
The pixel indices therefore determine the \(k\)-mer directly from the binary expansions of \(i\) and \(j\).

Proposition 6 further states that if \(w_\tau\) is the \(k\)-mer with lexicographic index \(\tau=\mathrm{idx}(w_\tau)\), then \(FCGR_k(s)(i,j)=occ(s,w_\tau)\). This means that vectorization of FCGR in any consistent scan order is a re-ordering of the classical \(k\)-mer frequency vector. The geometric image and the compositional vector differ only by indexing convention [2506.22172].

## 4. Dihedral symmetries and nucleotide permutations

Because CGR is defined on a square, its natural symmetry group is the dihedral group \(D_8\), consisting of four rotations and four reflections. The framework makes this correspondence explicit by mapping the geometric symmetries of the square to a subgroup \(S\subset S_4\) of nucleotide permutations. Examples include
\[
f(e)=(),\quad f(r)=(A\,T\,G\,C),\quad f(r^2)=(A\,G)(C\,T),\quad f(s)=(A\,C)(G\,T),
\]
with analogous definitions for the remaining elements of \(D_8\). Each permutation is extended to words by monoid morphism.

Theorem 7 states that for words \(u,w\in\Sigma^n\) and one of these eight permutations \(\sigma\in S\),
\[
u=\sigma(w)\quad\Longleftrightarrow\quad CGR(u)=f^{-1}(\sigma)\cdot CGR(w),
\]
where the right-hand side applies the corresponding \(2\times 2\) symmetry matrix to every CGR point. Geometric transformations of the CGR are therefore in one-to-one correspondence with specific renamings of nucleotides [2506.22172].

This result has two immediate consequences. First, the set of all CGR images of DNA sequences is closed under the eight square symmetries. Second, orientation normalization of CGR images can be interpreted as choosing a canonical representative in the \(D_8\)-orbit, which is equivalent to fixing a canonical nucleotide labeling. A plausible implication is that image-level data augmentation by rotations or reflections is not generically label-preserving unless the downstream task is invariant under the corresponding nucleotide permutation.

The same symmetry principle extends to avoided \(k\)-mers. If a sequence avoids a unique \(k\)-mer \(\alpha\) and a nucleotide permutation \(\sigma\in S\) is applied, then the transformed sequence avoids \(\beta=\sigma(\alpha)\). In CGR terms, a symmetry that moves a hole corresponding to \(\alpha\) yields a hole corresponding to \(\sigma(\alpha)\).

## 5. Inverse CA-MER: reconstruction from prescribed \(k\)-mer distributions

The inverse direction of CA-MER starts from a target \(k\)-mer distribution or FCGR and reconstructs a DNA sequence with matching or approximately matching \(k\)-mer statistics. Using the base-4 indexing above, the \(k\)-mer frequency vector of a sequence \(s\) is
\[
F_k(s)=\bigl(occ(s,w_0),\dots,occ(s,w_{4^k-1})\bigr)\in\mathbb{N}^{4^k},
\]
and the empirical \(k\)-mer distribution is
\[
\theta^s=\frac{1}{n-k+1}F_k(s)\in\Delta^{4^k-1}.
\]
These distributions must satisfy marginal consistency constraints arising from \(k\)-mer overlaps. For each \((k-1)\)-mer \(v\),
\[
\sum_{a\in\Sigma}\theta_{va}^s=\sum_{a\in\Sigma}\theta_{av}^s=\theta_v^s.
\]

The reconstruction algorithm builds a De Bruijn multigraph of order \(k\). Vertices are the \((k-1)\)-mers appearing as prefixes or suffixes of \(k\)-mers with positive target count, and each \(k\)-mer \(w\) with prefix \(u\) and suffix \(v\) contributes \(c_w\) parallel edges from \(u\) to \(v\). Any Eulerian path in this multigraph corresponds to a sequence whose \(k\)-mer counts match the edge multiplicities. Exact realizability requires the integer balance condition
\[
\sum_{a\in\Sigma}c_{va}=\sum_{a\in\Sigma}c_{av}
\]
at every vertex, together with strong connectivity of the nonzero-edge subgraph.

Given \(k\), sequence length \(n\), and a target distribution \(\theta\) satisfying the marginal constraints, the algorithm proceeds by scaling \(\theta\) to pseudo-counts \(c_w=\mathrm{round}((n-k+1)\theta_w)\), building the De Bruijn multigraph, computing the vertex imbalance
\[
\delta(v)=\sum_{a\in\Sigma}c_{va}-\sum_{a\in\Sigma}c_{av},
\]
adding artificial edges along paths of length at most \(k-1\) to balance the graph, optionally adding up to \(4^{k-1}\) additional edges to ensure strong connectivity, constructing an Eulerian cycle with Hierholzer’s algorithm, and finally decoding the cycle into a DNA sequence [2506.22172].

Theorem 8 gives the approximation guarantee. If \(1<k<n\), \(\epsilon\in[0,1]\), and \(\theta\in\Delta^{4^k-1}\) satisfies the marginal constraints, then whenever
\[
n>\frac{2(k-1)4^k}{\epsilon}+k-1,
\]
there exists an algorithm outputting a sequence \(s\) whose empirical \(k\)-mer distribution \(\hat\theta^s\) satisfies
\[
\|\hat\theta^s-\theta\|_1\le\epsilon.
\]
The error arises from rounding and from artificial balancing edges; the bound shows that any marginal-consistent \(k\)-mer distribution can be approximated to arbitrary precision by a sufficiently long synthetic sequence.

## 6. Synthetic CGR generation, empirical evaluation, and machine-learning use

Because the framework proves the equivalence
\[
\theta \Longleftrightarrow k\text{-mer counts }c_w \Longleftrightarrow FCGR_k \Longleftrightarrow \text{CGR at resolution }2^k\times 2^k,
\]
the reconstruction algorithm directly enables controllable synthesis of FCGR and CGR images. One specifies a target \(k\)-mer distribution \(\theta\), reconstructs a sequence \(s\) with \(\hat\theta^s\approx\theta\), and then computes \(FCGR_k(s)\) or \(CGR(s)\). By the core equivalence theorem, the resulting image matches the target pixelwise \(k\)-mer statistics [2506.22172].

Two classes of experiments are reported. In template-based reconstruction from real genomes, the study samples a \(100\)k-bp fragment for each of \(100\) species from each major kingdom, computes empirical \(k\)-mer distributions for \(k=2,\dots,6\), reconstructs sequences, and measures total variation distance between original and reconstructed distributions. The reported errors are small and below the theoretical \(\epsilon\) across kingdoms. In de-novo reconstruction, points are sampled from the relevant sub-polytope of \(\Delta^{4^k-1}\) satisfying the marginal constraints by a hit-and-run MCMC method. For \(k=2,\dots,6\), sequences are reconstructed with
\[
n_{\min}=\frac{2(k-1)4^k}{\epsilon}+(k-1),
\]
using \(\epsilon=0.01\), and the observed reconstruction errors are all \(<\epsilon\).

The practical complexity is also stated explicitly. Building the De Bruijn multigraph is \(O(4^k)\); balancing and adding artificial edges is \(O(4^k)\) in the worst case; Eulerian cycle construction is \(O(|E'|)\approx O(n)\); and sequence generation is \(O(n)\). For moderate \(k\), specifically \(k\le 6\), and \(n\le 10^5\), the reported web implementation runs in \(<1\) s and \(<200\) MB RAM on a laptop.

The machine-learning motivation is downstream analysis on FCGR or CGR images, including CNN-based taxonomic classification and contrastive or self-supervised approaches. The data specifically notes applications to CNN-based taxonomic classifiers using FCGR/CGR images, citing Rizzo 2016, Safoury and Hussein 2019, Avila Cartes et al. 2023, and DeepMicrobes-style architectures, as well as contrastive or self-supervised settings such as DeLUCS and CGRclust. Within this setting, synthetic reconstructions can preserve species-specific genomic signatures at the level of \(k\)-mer bias patterns while varying local sequence content.

## 7. Scope, interpretive consequences, and limitations of CA-MER

The theoretical significance of CA-MER is that it turns CGR and FCGR from visually motivated encodings into rigorously characterized representations of \(k\)-mer composition. At fixed order \(k\), any numerical method operating on FCGR images is, in the strict sense established here, a method on \(k\)-mer frequencies. This suggests that convolutional filters learned on FCGR images should be interpreted as detectors of local structure in the ordered arrangement of \(k\)-mer counts rather than as exploiting information absent from the underlying \(k\)-mer vector [2506.22172].

The framework also clarifies the geometric semantics of CGR patterns. Fractal-looking regions, empty cells, and dense regions are no longer merely descriptive image features: each pixel corresponds to a specific \(k\)-mer, and absence or over-representation of that pixel corresponds to low or high count of that \(k\)-mer. Likewise, square symmetries are not arbitrary image manipulations but exact realizations of nucleotide permutations.

At the same time, the representational limits are explicit. For a given \(k\), CA-MER ignores all structure beyond \(k\)-mer counts. Higher-order dependencies, longer motifs, and structural features are therefore not captured by the representation. Reconstruction is not unconstrained: marginal consistency must hold or be enforced, and sufficiently large sequence length is needed to obtain the stated approximation guarantees. The dimension \(4^k\) also grows rapidly with \(k\), so although FCGR has fixed size independent of sequence length, high-resolution CA-MER becomes increasingly expensive as \(k\) increases.

Within those assumptions, CA-MER is a reversible representation up to approximation and length requirements. That reversibility supports controlled perturbation of genomic signatures, generation of synthetic FCGR/CGR images with prescribed statistics, and direct analysis of how changes in \(k\)-mer composition affect downstream alignment-free classification and representation learning.

Source: https://www.emergentmind.com/topics/ca-mer