Uncovering hidden assembly artifacts: when unitigs are not safe and bidirected graphs are not helpful

Recent assemblies by the T2T and VGP consortia have achieved significant accuracy but required a tremendous amount of effort and resources. More typical assembly efforts, on the other hand, still suffer both from mis-assemblies (joining sequences that should not be adjacent) and from under-assemblies (not joining sequences that should be adjacent). To better understand the common algorithm-driven causes of these limitations, we investigated the unitig algorithm, which is a core algorithm at the heart of most assemblers. We prove that, contrary to popular belief, even when there are no sequencing errors, unitigs are not always safe (i.e. they are not guaranteed to be substrings of the sequenced genome). We also prove that the unitigs of a bidirected de Bruijn graph are different from those of a doubled de Bruijn graph and, contrary to our expectations, result in under-assembly. Using experimental simulations, we then confirm that these two artifacts exist not only in theory but also in the output of widely used assemblers. In particular, when coverage is low then even error-free data results in unsafe unitigs; also, unitigs may unnecessarily split palindromes in half if special care is not taken. To the best of our knowledge, this paper is the first to theoretically predict the existence of these assembler artifacts and confirm and measure the extent of their occurrence in practice.


Introduction
Reconstructing the full sequence of a genome from its sequencing data remains one of the most challenging problems in bioinformatics. Assemblers have suffered both from mis-assemblies (putting together sequences that should not be adjacent) and under-assemblies (not putting together sequences whose adjacency should be apparent from the data) [4,35]. Recent efforts by the Telomereto-Telomere consortium [25,24] and the Vertebrate Genome Project [30] demonstrated how long read technologies, long-range contact mapping, and manual curation can alleviate these errors. However, the time and cost of those efforts remain prohibitive for most biology labs. In such cases, mis-and under-assemblies continue to be a major limitation (e.g. [38]).
Understanding the common algorithm-driven causes of these limitations is made complicated by the diversity and complexity of assembly algorithms. We can start by focusing on assemblers that use de Bruijn graphs (dBGs) [16], which continue to be popular even for long-read data [5]. But even dBG-based assemblers differ on how they handle complexities arising from sequencing errors, heterogeneity, or DNA double strandedness. Nevertheless, most assemblers are built on top of the unitig algorithm, which returns all the maximal unitigs in an assembly graph [35]; a unitig is a path whose vertices have exactly one incoming and one outgoing edge, with the exception that the first and last vertex can have any number of incoming and outgoing edges, respectively. Being a common denominator of most assemblers, the unitig algorithm is a good target for investigating shared sources of mis-and under-assemblies.
It is already known that the unitig algorithm contributes to under-assembly (e.g. see the safe and complete framework of [37,9]) and can trivially create mis-assemblies when there are sequencing errors. The effect of sequencing errors on assembly errors has even been theoretically studied more broadly in [32,33,34]. However, it is widely assumed that if it were not for sequencing errors, unitigs would always be safe (i.e. substrings of the sequenced genome). In an earlier work [19], we attempted to formally prove this but could only do so by assuming perfect coverage. This assumption was also necessary in another earlier work [37], where it was suggested that without it, unitigs may not be safe. Unitigs were also implied to be unsafe in certain models of the assembly problem [9]. We therefore hypothesize that, contrary to popular belief, there are non-contrived conditions which lead to unsafe unitigs on error-free data.
The unitig algorithm also needs to account for the fact that the strand from which a read is sequenced is unknown. Most assemblers do so via two common approaches to constructing the dBG. In one, every k-mer is "doubled" prior to constructing the dBG, i.e. for every k-mer in the input, both it and its reverse complement is added to the dBG (e.g. SPAdes [6]). In the other approach, edges are given two instead of one orientation, thereby capturing the way that double-stranded strings can overlap. This results in a bidirected dBG [22], used in assemblers such as ABySS [36,17]). Since this is a more elegant construction for capturing the double-stranded nature of the data, one would intuitively expect that it should not hurt assembly accuracy.
In this paper, we perform a theoretical and empirical study to validate our two hypothesis about common algorithm-driven sources of mis-and under-assemblies. First, despite widespread belief to the contrary, we show that even on error-free data, unitigs do not always appear in the sequenced genome (i.e. they are unsafe). Our experimental results confirm that at least two different assemblers exhibit this behavior in practice. Second, we establish that there is a bijection between maximal unitigs in the doubled and bidirected dBGs, except that palindromic unitigs in the doubled dBG are split in half in the bidirected dBG. This shows that, contrary to intuition, naively using the bidirected graph actually contributes to under-assembly compared to the doubled graph. Our experimental results confirm that this artifact appears in some assemblers but not in others. Nevertheless, we also find that the extent of these two artifacts is limited. To the best of our knowledge, this paper is the first to theoretically predict the existence of these assembler artifacts and confirm and measure the extent of their occurrence in practice.

Preliminaries
In this section we give the formal definitions for our paper. The reader may wish to delay reading the last three paragraphs (relating to bidirected graphs) until they are used in Section 4.
Strings: In this paper, we assume all strings are over the four-letter DNA alphabet. A string of length k is called a k-mer. We define suf k (x) (respectively, pre k (x)) to be the last (respectively, first) k characters of x. When the subscript is omitted from pre, and suf , we assume it is k − 1. For x and y with suf (x) = pre(y), we define gluing x and y, denoted by x ⊙ y, as x concatenated with the last |y| − k + 1 characters of y. Given two strings x and y, we define occ y (x) as the number of times that x occurs in y. The reverse complement of x is denoted as x. For a set of strings S, S denotes the set of the reverse complements of all strings of S. A string x is a palindrome iff x = x. A string x is canonical if it is the lexicographically smaller of x and x. For s ∈ {0, 1}, we define orient(x, s) to be x if s = 0 and to be x if s = 1. To canonize x is to replace it by its canonical version, canon(x) = min i (orient(x, i)). We say that x 0 and x 1 have a (s 0 , s 1 )-orientedoverlap if suf (orient(x 0 , 1 − s 0 )) = pre(orient(x 1 , s 1 )). Intuitively, such an overlap exists between two strings if we can orient them in such a way that they are glueable. For example, GT T and T T G has a (1, 0)-oriented overlap, and AAC and T T G have a (0, 0)-oriented overlap. We define the non-canonical k-spectrum sp k (x) as the set of all k-mer substrings of x.
Directed de Bruijn graphs: Given a set of k-mers K, the basic node-centric directed de Bruijn Graph, G basic (K), is directed graph where nodes are the k-mers of K, and an edge exists from k-mer x to k-mer y iff suf (x) = pre(y). A double directed de Bruijn graph on K, G dbl (K) is a basic de Bruijn graph on the set of k-mers K ∪ K, i.e. G dbl (K) = G basic (K ∪ K). Observe that for any k-mer x such that suf (x) ̸ = pre(x), the existence of the edge from x to y in G dbl (K) implies the existence of a different edge from y to x. We refer to such a pair of edges as mirrors. For a k-mer x such that suf (x) = pre(x), the G dbl (K) will contain an edge from x to x; we call this edge a self-mirror.
Walks and unitigs in directed graphs For a vertex x in a directed graph, the in-degree d − (x) (respectively, out-degree d + (x)) is the number of edges incoming to (respectively, outgoing from) it. The sequence of vertices w = (x 0 , . . . , x n ), for n ≥ 0, is a walk iff for all 1 ≤ i ≤ n there exists an edge from x i−1 to x i . Vertices x 0 and x n are called endpoints, and a walk sometimes has one endpoint. The spelling of a walk is defined as spell(w) = x 0 ⊙ · · · ⊙ x n . A walk is said to be circular iff n ≥ 1 and x 0 = x n , and a simple cycle if for all i and j such that 0 ≤ i < j ≤ n, x i = x j implies i = 0 and j = n. A simple periodic cycle is a walk that starts with a simple cycle and then keeps on looping around it without ever exiting; formally, a walk is a simple periodic cycle if there exists 0 ≤ i ≤ n − 1 such that (x 0 , . . . , x i ) is a simple cycle and x i+1 , . . . , x n is a repetition of x 0 , . . . , x i , except the last repetition may be partial. A walk is a unitig if it is not a periodic cycle and for all 1 ≤ i ≤ n, d − (x i ) = 1 and for all 0 ≤ i ≤ n − 1, d + (x i ) = 1. A unitig is maximal if it is not a proper subwalk of another unitig.
Bidirected de Bruijn graph: A bidirected graph G is a pair (V, E) where the set V are called vertices and E is a set of edges. Intuitively, every vertex has two sides; formally, a vertex-side is a pair (u, s), where u ∈ V and s ∈ {0, 1}. An edge e is a set of two vertex-sides {(u 0 , s 0 ), (u 1 , s 1 )}, where u i ∈ V and s i ∈ {0, 1}, for i ∈ {0, 1}. Intuitively, an edge is an undirected connection between two (not-necessarily distinct) vertex-sides. We say that an edge e is incident to each of the two vertex-sides. Note that there can be multiple edges between two vertices, but only one edge once the sides are fixed. A labeled bidirected graph is a bidirected graph G where every vertex u has a string label lab(u), and for every edge e = {(u 0 , s 0 ), (u 1 , s 1 )}, there is a (s 0 , s 1 )-orientedoverlap between lab(u 0 ) and lab(u 1 ). G is said to be overlap-closed if there is an edge for every such overlap. Let K be a set of canonical k-mers. The node-centric bidirected de Bruijn graph, denoted by G bid (K), is the overlap-closed labeled bidirected graph where the vertices and their labels correspond to K. Figure S1A shows an example of a bidirected graph.
Walks and unitigs in bidirected graphs: An edge in a bidirected graph is an inverted loop if its two vertex-sides are equal. An inverted loop {(u, s), (u, s)} is lonely if it is the only edge incident to (u, s). We define the degree of a vertex-side d(u, s) to be the number of edges incident to it, but with an inverted loop contributing two to the degree. A sequence t = (u 0 , s 0 , u 1 , s 1 , . . . , u n , s n ) with n ≥ 0 is a walk if for all 1 ≤ i ≤ n, there exists an edge The vertex-sides (u 0 , s 0 ) and (u n , 1 − s n ) are called the first and last endpoint sides, respectively. Note that even when n = 0, there are two endpoint sides. The spelling of a walk is defined as spell(w) = orient(lab(u 0 ), s 0 ) ⊙ · · · ⊙ orient(lab(u n ), s n ). The reverse of t is rev(t) = (u n , 1 − s n , . . . , u 0 , 1 − s 0 ). Note that, as expected, spell(t) = spell(rev(t)). Note that if t ′ is a subwalk of t, then rev(t ′ ) is a subwalk of rev(t) and spell(t ′ ) is a substring of spell(t) (the converse is not necessarily true when k is even). Figure S1BC gives an example illustrating a walk in a bidirected graph and Figure S1D shows a corresponding walk in a doubled directed dBG.
A walk w = (u 0 , s 0 , . . . , u n , s n ) is said to be circular iff n ≥ 1 and (u 0 , s 0 ) = (u n , s n ), and a simple cycle if for all i and j such that 0 ≤ i < j ≤ n, (u i , s i ) = (u j , s j ) implies i = 0 and j = n. A simple periodic cycle is a walk that starts with a simple cycle and then keeps on looping around it without ever exiting; formally, w is a simple periodic cycle if there exists 0 ≤ i ≤ n − 1 such that (u 0 , s 0 , . . . , u i , s i ) is a simple cycle and (u i+1 , s i+1 , . . . , u n , s n ) is a repetition of (u 0 , s 0 , . . . , u i , s i ), except the last repetition may be partial. A walk is a unitig if it is not a periodic cycle and for all 1 ≤ i ≤ n, d − (x i ) = 1 and for all 0 ≤ i ≤ n − 1, d + (x i ) = 1. A walk (u 0 , s 0 , . . . , u n , s n ) is a unitig if it is not a periodic cycle and for all 0 ≤ i < n, d(u i , 1 − s i ) = 1 and, for all 0 < i ≤ n, d(u i , s i ) = 1. A unitig is said to be maximal if it is not a proper subwalk of another unitig. Note that all the subwalks of a unitig must themselves be unitigs.

Safety of unitigs
In this section, we will give necessary and sufficient conditions for a unitig to be unsafe in the basic dBG constructed from error-free reads. To properly formulate this question, we define a sequenced read interval as a genomic interval that generated a read, i.e. from which a read was sequenced. A sequencing experiment then corresponds to a set of sequenced read intervals. A sequenced interval is then defined as a maximal interval which is covered by sequenced read intervals, with the additional constraint that any two consecutive sequenced intervals overlap by at least k − 1. We define a sequenced segment as the string corresponding to a sequenced interval. Observe that the sequenced intervals do not overlap by more than k − 2 bases (otherwise they would not be maximal), but the sequenced segment may have longer overlaps due to repeats. A set of reads then induces a set S = {S 1 , . . . , S |S| } of sequenced segments. Figure 1 illustrates this formulation. In this section, we do not explicitly account for reverse complements, since they will be considered in Section 4.
Given a set of sequenced segments S, we say that a unitig w in G basic (sp k (S)) is unsafe iff spell(w) is not a substring of a string in S. Equivalently, w is unsafe iff it is not a subwalk of a walk that corresponds to a string in S. Our definition of unsafe captures the notion of a potential mis-assembly, as the unitig is not present in the sequenced part of the genome. 1 Observe that in formulating the problem, we start with the set of sequenced segments themselves; the read set that induced them is irrelevant. We can now state the main result of this section, which gives the necessary and sufficient conditions for a unitig to be unsafe. The proof of this theorem, along with the necessary Lemmas, is left for Appendix A due to space constraints. Theorem 1. Let S be a set of sequenced segments and let w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (S)). Then w is unsafe if and only if for all S ∈ S, one of the following holds: (i) S does not contain any k-mer of w, The cases of Theorem 1 are illustrated in Figure 2 and can be understood intuitively as follows. Since every k-mer of G basic (sp k (S)) is in S, every k-mer of w must be touched by some S ∈ S. Then, consider a walk g corresponding to such a string S. If g starts in the middle of w and does not visit its own starting vertex again, then g does not fully contain w (case (ii)). Similarly, if g ends in the middle of w and did not visit its own ending vertex previously, then g does not fully contain w (case (iii)). If g starts and ends in the middle of w, with the ending vertex to the right of the starting vertex, and contains each of those vertices exactly twice, then g does not fully contain w (case (iv)). This is the "if" direction of Theorem 1, with the "only if" direction further stating that under all other conditions, g fully contains w.
When the genome is a single chromosome and the coverage is high enough so that every k-mer is sequenced, the whole genome becomes one sequenced segment. In this case, Theorem 1 simplifies because the genome has only one starting and ending vertex and, for a unitig w to be unsafe, the genome must somehow contain every vertex of w without containing w as a subwalk. Corollary 1. Let X be a string and let w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (X)). Then spell(w) is not a substring of X iff one of the following holds: Moreover, this can hold for at most one unitig in G basic (sp k (X)).
This corollary tells us that with perfect coverage, all unitigs, except possibly one, are safe. Note that this is a stronger version of the perfect coverage case than the one given in [19], which made an assumption that the starting vertex of X is a source and the ending vertex of X is a sink.
A natural question is how a scenario which gives an unsafe unitig looks like in terms of the original genome. Figure 3 visualized the following natural possibility. Suppose that the sequenced Figure 1: Illustration of sequenced segments. The black text on top shows the reference genome of length 26. The seven sequences in red are reads aligned to the reference. The green boxes highlight the resulting sequenced segments when k = 3. Note that the reads TACCG and GCCTA form two separate segments as the kmer CGC is not present in K. For segment colored in green, case (i) holds. For red, case (ii), for blue, case (iii) and for orange, case (iv) holds. genome X has a repeat that appears as a maximal unitig ψ in G basic (sp k (X)). Then, suppose that the region encompassing the start of one copy and the region encompassing the end of the other copy is not sequenced. Then ψ loses its maximality in G basic (sp k (S)) and becomes a subwalk of a bigger unitig w. Though w is a unitig in the graph from the sequencing data, it would not be a unitig if all the k-mers of X were included in the graph. In Section 5, we will show that this situation accounts for the majority of our experimental observations. 4 The relationship between the doubled dBG (G dbl (K)) and the bidirected dBG (G bid (K))

A C G T A C T T A A A C G G G G A A T A C C G C C T A
In this section, we will characterize the relationship between the maximal unitigs of G dbl (K) and the maximal unitigs of G bid (K) (Theorem 2). Due to space constraints, the lemmas and proofs needed to prove Theorem 2 are in Appendix B. Here, we will instead give an intuitive walk-through to elucidate the relationship between the two graphs. We will incrementally show the relationship between objects in the doubled graph and the bidirected graph -first between vertices and vertexsides, then between edges, then between walks, and finally between maximal unitigs. Let K be a set of canonical k-mers, with k odd. We only consider the case of odd k; when k is even, there may be palindrome k-mers, which create special cases to handle both in the practical assembler implementation and in the theoretical analysis. Since most assemblers anyway restrict k to be odd, we limit ourselves to this case as well.
There is a natural mapping between vertices of G dbl (K) and vertex-sides of G bid (K). For a vertex x in G dbl (K), define F V (x) = (u, s), where u is a vertex in G bid (K) and s ∈ {0, 1} such that lab(u) = orient(x, s). By the definition of G bid (K), there exists a unique u and unique s that satisfy this condition. The uniqueness of s is guaranteed by the fact that x cannot be a palindrome. Formally, F V is a bijection between vertices of G dbl (K) and vertex-sides of G bid (K) (Lemma B.10).
There is also a natural mapping between edges in G dbl (K) and G bid (K). Let x 1 and x 2 be two k-mers in G dbl (K) and let (u 1 , s 1 ) = F V (x 1 ) and (u 2 , s 2 ) = F V (x 2 ). We define the mapping  Figure 4: Example of a bidirected dBG (G bid (K)) (panel A) and a doubled dBG (G dbl (K)) (panel B) on the same underlying set of k-mers K = {CAC, AAC, ACT, CT A, AT A}. Each vertex side in G bid (K) and each in-and outside of a vertex in G dbl (K) is numbered with the corresponding degree. All maximal unitigs are shown using a long filled rectangle with an arrow. The maximal unitigs of G bid (K) are color coded so that red is B no-loop , dark green is B last-loop , and light green is B first-loop . The maximal unitigs of G dbl (K) are color coded so that dark red is D non-pal and blue is D pal . Self-mirror edges in G dbl (K) are shown in blue.
is an edge in G bid (K) (Lemma B.11). Note, however, that F E is not a bijection, since a pair of mirror edges (x, y) and (y, x) map to the same bidirected edge, i.e. F E (x, y) = F E (y, x).
The F V and F E mappings allow us to naturally define a mapping from walks in G dbl (K) to walks in G bid (K). Let w = (x 0 , . . . , x n ) be a walk in G dbl (K). For each 0 ≤ i ≤ n, let (u i , s i ) = F V (x i ) and define F W (w) ≜ (u 0 , s 0 , . . . , u n , s n ). F W is a spell-preserving bijection between the set of walks in G dbl (K) and the set of walks in G bid (K) (Lemma B.12).
One might hypothesize that F W is also a bijection between the maximal unitigs of G dbl (K) and the maximal unitigs of G bid (K). Surprisingly, it turns out to not be the case, though the following more careful analysis reveals a close relationship. For G dbl (K), let us partition the set of maximal unitigs into non-palindromic strings D non-pal and palindromic strings D pal . For G bid (K), let B no-loop be the set of maximal unitigs where neither endpoint side has an incident lonely inverted loop, let B first-loop be the set of maximal unitigs where the only endpoint side with a lonely inverted loop is the first one, and let B last-loop be the set of maximal unitigs where the only endpoint side with a lonely inverted loop is the last one. To avoid corner cases, let us further assume that there are no circular unitigs in G dbl (K), which eliminates the possibility of a maximal unitig having lonely inverted loops at both endpoint sides and implies that B no-loop , B first-loop , and B last-loop are a partition of the maximal unitigs of G bid (K) (Lemma B.16). Figure 4 shows an example.
We also need to define a function head which, informally, takes a maximal palindromic unitig in G dbl (K), extracts the first half of it, and maps it to G bid (K). Formally, head(w) maps a walk w = (x 0 , . . . , x n ) in D pal to the walk F W ((x 0 , . . . , x n−1 2 )) in G bid (K). Note that n−1 2 is necessarily an integer since w is a palindrome and hence n must be odd (Lemma B.1). We can now state the main theorem of this section.
Theorem 2. Let K be a set of canonical k-mers where k is odd and G dbl (K) does not contain a circular unitig.
(i) The function F W is a bijection from D non-pal to B no-loop .
(ii) The function rev is a bijection between B last-loop and B first-loop .
(iii) head is a bijection from D pal and B last-loop  The theorem says that for maximal unitigs that are non-palindromic in G dbl (K) and do not have inverted self loops incident at the endpoint sides in G bid (K), F W is in fact a bijection. However, every maximal unitig w that is palindromic in G dbl (K) is split into two maximal unitigs in G bid (K): one that spells the first half of w and has a self loop incident at the last endpoint side, and one that spells the second half of w and has a self loop at the first endpoint side. These are necessarily reverses of each other.
Inverted loops are caused by k-mers x where suf (x) = suf (x) (e.g. GTA). When these type of k-mers are not present in K, there are no inverted loops in G bid (K) or palindromic unitigs in G dbl (K). Hence, D pal = B first-loop = B last-loop = ∅, and Theorem 2 immediately simplifies.
Corollary 2. Let K be a set of k-mers, with odd k, which does not contain any x such that suf (x) = suf (x). Then F W is a bijection from the maximal unitigs in G dbl (K) to the maximal unitigs in G bid (K).

Empirical results
Occurrence of unsafe unitigs in real genomes: Theorem 1 predicts the possibility of unsafe unitigs. To verify the extent to which this happens with real genomes, we use T2T human reference chromosome 1 [25]. We simulated error-free reads of length 100 with varying target coverages and varying k. Note that for this experiment, we want to test if mis-assemblies occur even when the data is perfect, so making the reads error-free is necessary. The sequenced read intervals correspond to the source location of each simulated read, and the sequenced segments are defined as in Section 3. From these reads, we constructed the basic de Bruijn graph and output its maximal unitigs, using a version of BCALM [10,11] modified to ignore reverse-complementary. We confirmed that the unitigs that were unsafe(i.e. not a substring of the sequenced segments) were exactly the unitigs that satisfied the conditions of Theorem 1. Table 1 shows the number of unsafe unitigs, as a function of the coverage and of k. There are as many as 17,635 unsafe unitigs (at coverage 2x and k = 71). The best indicator for the number of unsafe unitigs is the percent of k-mers sampled (or the number of sequenced segments), i.e. the number of unsafe unitigs goes down as the percent of sampled k-mers goes up. This trend is in line with the prediction of Corollary 1, which states that once the coverage is perfect, we expect to see at most one unsafe unitig. Our results indicate that the artifacts identified by Theorem 1 do occur in real genomes, though they become less common as more of the genomic k-mers are sampled.
An unsafe unitig is not necessarily a mis-assembly, as it may be a substring of the unsequenced genome by luck. We define an unitig to be mis-assembled if its spelling is not a substring of the reference. Table 1 shows that the number of mis-assembled unitigs is substantially lower than the unsafe unitigs, e.g. with 708 mis-assembled unitigs at 2x coverage and k = 71. Thus the potential  for mis-assembly does not usually translate into a real mis-assembly, though many mis-assemblies remain.
We further check how many of these mis-assembled unitigs fit the example in Fig. 3. A formal definition to capture this example is included in Appendix A for reference. Table 1 shows that the vast majority of mis-assembled cases are in fact caused by this situation, where a repeat has an occurrence in which its start is unsequenced and another occurrence in which its end is unsequenced.
The simulations in Table 1 suggest that the mis-assembly artifact can be removed by simply increasing coverage. In a metagenome expirement, however, this is not always possible. Even when one increases the number of reads, there will continue to be genomes in the sample whose abundance is low enough that their coverage is low. To verify this intuition, we used a standard benchmark dataset generated by the CAMI competition [31], containing 70 million synthetic reads from 30 genomes. Table 2 shows there are 33-37 mis-assembled unitigs, indicating that this artifact remains under realistic coverage of a metagenomic dataset. The section "CAMI dataset" in Appendix C contains more details about the experiment, including Table S1 which shows the details of the dataset.

Presence of unsafe unitigs in the contig output of real assemblers:
We investigated the extent to which the artifact predicted by Theorem 1 appears in output of real assemblers. Assemblers do not simply output the unitigs of a graph but perform many other steps, hence it was not clear if this artifact would appear in the output contigs. Unfortunately, it is not clear how to verify this artifact with real data, as sequencing errors make it difficult to know which of the misassembled contigs are caused by the conditions of Theorem 1. We therefore again used a simulated error-free dataset from the T2T chromosome 1, using the ART simulator [15], with read length of 250 and varying coverages. This time, we simulated reads from either strand, since assemblers are not typically run in single-stranded mode. We also used the CAMI dataset, but simulating reads in double-stranded mode. We then constructed the doubled de Bruijn graph using k = 74 and output its maximal unitigs (note that Theorem 1 holds for even k). We also ran SPAdes [6] and MEGAHIT [18] to assemble the reads (see Appendix C for parameter details). We then identified Table 3: The extent to which mis-assembled unitigs contribute to mis-assembled contigs of real assemblers. Here, U is the set of mis-assembled unitigs in G dbl , S is the set of mis-assembled contigs of SPAdes, and M is the set of mis-assembled contigs of MEGAHIT. We use A ⊏t B to indicate the subset of A that matches at least one element of B at a threshold of t.  unitigs and the assembler contigs that were mis-assembled, but allowing for reverse complements. We will say that a string x matches a string y with a threshold of t if a fraction t of the k-mers of x occur in y. Tables 3 and 4 show that nearly all of the mis-assembled unitigs matched at least one misassembled SPAdes contig with a threshold of 1. For MEGAHIT, the threshold of 1 turned out to be stringent; this is not surprising, since assemblers have many steps that may add or remove k-mers from the graph; additionally, MEGAHIT varies the value of k internally and may therefore join k-mers that do not have an overlap of length k−1. Using a threshold of 0.5, however, we found that, similarly to SPAdes, most mis-assembled unitigs matched a mis-assembled contig of MEGAHIT. These results indicate that the artifact predicted by Theorem 1 not only appears in unitigs of the raw graph but also in the output of widely used assemblers like SPAdes and MEGAHIT.
Presence of palindrome splitting in a real genome: To measure the extent of the "palindrome splitting" artifact predicted by Theorem 2, we let K be the set of all constituent k-mers in human chromosome 21 (grch38.p13), after excising the Ns. We confirmed the correctness of Theorem 2 by verifying that the spellings of D non-pal are equal to the spellings of B no-loop and that the spellings of B last-loop are equal to the spellings of D pal and are the reverse complements of the spellings of B first-loop . Table 5 shows that the splitting artifact is present but rare, e.g. for k = 15, there were 186 palindromic maximal unitigs in G dbl (K) which were split in G bid (K). The artifact becomes rarer with increasing k (e.g. for k = 43, there were only 3 split palindromes), which is expected since palindrome frequency in real genomes decreases with length.
Presence of palindrome splitting in real assemblers: Most assembler papers do not contain enough detail to ascertain what kind of de Bruijn graph they use to handle reverse complements nor what modifications, if any, they make to the unitig algorithm used for the final output. Looking at MEGAHIT [18], SPAdes [6], ABySS [36,17], and minia [12], only the SPAdes paper is unambiguously clear in saying how it handled reverse complements (it used the doubled dBG). Furthermore, since these assemblers implement many heuristics, the splitting artifact may be absent (respec-  tively, present) even if they did (respectively, did not) use bidirected graphs. We therefore tested the behavior of these assemblers by looking for evidence of palindrome splitting in their output, rather than in their technical descriptions.
Since large exact palindromes are uncommon in typical genomes, we created a synthetic genome by modifying a ∼ 7 mil bp long contig from human chromosome 4 (grch38.p13) as follows. We randomly sampled a 1,000bp-long region and replaced the last 500bp by the reverse complement of first 500 bp; we then repeated the sampling process 700,000 times. We then simulated error-free Illumina reads with ART. We used a read length of 100bp so that assemblers will not be able to supplement the dBG with read information in a way that hides the palindrome splitting artifact. We used 10x coverage so that most k-mers would be sampled.
First, we find the reference location of each unitig w in D pal . Then, we find all exact alignments of the assembler contigs to the reference. We say that w is fully-covered if there exists a contig whose alignment spans w's. Otherwise, we say w is split if one half of w's region does not overlap with any contig alignments while the other half has a contig aligned that ends precisely in the middle of w at one end and extends past w at the other end. A unitig is ambiguous if it does fall into either category. Appendix C contains a more precise definition of these cases. Table 6 shows that ABySS clearly exhibits the palindrome splitting artifact, with all nonambiguous unitigs being split and none fully-covered. In fact, this is due to a heuristic that breaks unitigs at any palindromic edges or vertices [1,2]. The opposite was true for SPAdes and MEGAHIT, with all non-ambiguous unitigs being fully-covered and none split. minia on the other hand exhibited mixed behavior. Of the 417 non-ambiguous cases, 34 were split and 383 were fullycovered. These results indicate that the palindrome splitting artifact of Theorem 2 does persist all the way to the contig output stage in some assemblers. However, this artifact requires the presence of long exact palindromes in the reference, which is uncommon in most genomes.

Discussion
Our theoretical study uncovered two artifacts of the unitig algorithm for genome assembly. The first is that even without sequencing errors, it can create mis-assemblies in places of imperfect coverage. The second is that when the bidirected graph is used to model double-strandedness, the unitig algorithm under-assembles by failing to merge the two halves of palindromes. Our experiments confirmed the presence of these theoretically-predicted artifacts in real genomes and popular assemblers. Fortunately, the impact of these artifacts is not large and can be addressed. Mis-assembly issues due to the first artifact can be resolved by increasing coverage or, potentially, breaking unitigs at places where the coverage along them is uneven. Under-assembly issues due to the palindrome artifact are rare in real genomes and, moreover, can sometimes be fixed by forcing the unitigs to "push their way through" lonely inverted loops (however, it is not always possible, e.g. [23,8].
One of the tangential outcomes of this paper is that we have given proper definitions for things like walks and unitigs in the context of bidirected graphs. Previous papers used these concepts somewhat informally; when definitions were given, they worked in the context of that paper but failed to have more general desired properties. For example, our previous work had an inconsistency in the way that a walk was defined on a single vertex versus on many vertices [28]. One key takeaway is that as a rule thumb, when working with bidirected graphs one should avoid thinking in terms of vertices but think instead of vertex-sides. The definitions we have provided in this paper generalize further than previous ones and are able to form the basis for the type of analysis we have done in this paper. For example, we are the first to prove the bijection between walks in the doubled and bidirected dBGs. We hope that these definitions will facilitate future attempts to formally study questions in bidirected graphs.
Bidirected graphs give an elegant way to capture the double-stranded nature of DNA in a dBG, but our results here indicate that, for the unitig algorithm, they do not give any theoretical advantage. One of the claimed advantages of using the bidirected graph framework in assembly is that it allows one to take advantage of results from graph theory that may otherwise be hidden. The primary example of this is a result (involving one of the authors) in [22] where a variant of the assembly problem was theoretically solved in polynomial time by relying on a reduction to the flow problem in bidirected graphs [14]. When viewed in retrospect, however, it is not clear that this connection was necessary. The algorithm being reduced to [14] was too cumbersome to implement and, when the assembly problem later necessitated a software solution, an approximation algorithm was used instead [20,21]. But the approximation algorithm worked on the doubled graph, erasing the advantage of having initially formulated the problem on bidirected graphs. Therefore, it remains to be seen if there are situations where the connection to graph theoretical results on bidirected graphs can prove useful for genome assembly. Alternatively, using a different setting may better help identify the advantages of bidirected graphs, e.g. pangenomics [27], rearrangement analysis [7], or compression [29]. Quantifying these advantages would be an exciting future direction.
Reproducibility In this subsection, we will prove Theorem 1 and Corollary 1. In the following, we will always have S be a set of sequenced segments and w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (S)). We start with a lemma that, roughly speaking, says that if a walk corresponding to some S ∈ S touches w, it must contain all of w except that it may begin or end somewhere along the way.
Lemma A.1. Let S be a set of sequenced segments and let w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (S)). Let S ∈ S and let g = (g 0 , . . . , g |S| ) be the walk corresponding to S. Suppose there exists i and j such that x i = g j . Then, Proof. We will only prove (i), since the argument for (ii) is symmetric. We use induction on δ.
For δ = 0, we have that the implication of (i) reduces to g j = x i , which is vacuously true because it is also a condition of the theorem. Now we assume that (i) holds for δ − 1, i.e. g j+δ−1 = x i+δ−1 . Since x i+δ−1 ̸ = suf k (G), g j+δ−1 is not the last vertex of g. Because x i+δ−1 is a non-last vertex of a unitig, it has only one out-neighbor, which is x i+δ . Therefore, g j+δ = x i+δ , which shows that that (i) holds for δ.
Using this lemma, we can now prove some general properties of unsafe unitigs. Proof. For (i), consider a unitig that has just one vertex x. Since each k-mer in G basic (sp k (S)), there must be at least one S ∈ S whose walk contains x. Hence, the unitig that is composed of only x is safe. For (ii), assume for sake of contradiction that for all S ∈ S, pre k (S) / ∈ {x 1 , . . . , x m }. Since every vertex of the graph must be contained in at least one string, let S ′ ∈ S be a string that contains x m . Applying Lemma A.1(ii) with i = m, we get that the walk corresponding to S ′ must contain w, contradicting that w is unsafe. The case of (iii) is symmetric to (ii), using x 0 instead of x m and applying Lemma A.1(i) with i = 0. For (iv), let g = (g 0 , . . . , g |S| ) and assume for sake of contradiction that there exists a S ∈ S such that g shares a vertex with w and pre k (S) / ∈ {x 1 , . . . , x m } and suf k (S) / ∈ {x 0 , . . . , x m−1 }. Let x i and g j be the vertices of w and g, respectively, that are equivalent. We can apply Lemma A.1 to get that (g j , . . . , g j+m−i ) = (x i , . . . , x m ) and (g j−i , . . . , g j ) = (x 0 , . . . , x i ). This means that w is a subwalk of g, which is a contradiction. For (v), let S ∈ S and let g = (g 0 , . . . , g |S| ) be its corresponding walk. If g and w do not share any vertices, then occ S (x i ) = 0 ≤ 2 for all i and we are done. Otherwise, we can apply (iv) to get that either (1) pre k (S) ∈ {x 1 , . . . , x m } or (2) suf k (S) ∈ {x 0 , . . . , x m−1 }. Let us consider (1) -we will omit the argument for (2) since it is symmetrical. Then g 0 = x i for some 1 ≤ i ≤ m. Note that g 0 is the first occurrence of x i in g. Assume for the sake of contradiction that occ S (x i ) > 2. To get the second occurrence of x i , g must first visit x 0 . After this second visit to x i , g must continue all the way until x m if it is to visit x i for a third time. Therefore, at the second visit to x i , g must in fact visit (x 0 , . . . , x m ), which contradicts that w is unsafe.
The case when a sequenced segment contains its first and/or last k-mer more than once puts additional constraints on how it can contain a unitig.
Lemma A.3. Let S be a set of sequenced segments and let w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (S)). Let S ∈ S such that at least one of the following holds: (i) occ S (pre k (S)) = 2 and there exists an integer i ∈ [1, m] such that x i = pre k (S), or (ii) occ S (suf k (S)) = 2 and there exists an integer j ∈ [i, m − 1] such that x j = suf k (S).
Then, spell(w) is not a substring of S iff both (i) and (ii) hold.
Proof. We only prove case (i) since case (ii) is symmetrical. Let g be the walk corresponding to S. In the first phase, g starts from x i and, since it must visit x i a second time, continues until x m . Then at some point it enters w through x 0 and proceeds to visit x i for the second and last time. We will refer to the time from the end of the first phase to the point it enters x 0 as the second phase, and the rest of the walk as the third phase. Observe that g does not contain w as a subwalk in either the first or second phase. Now we prove the if direction. During phase 1, g visits x j exactly once. During phase 2, g does not visit x j . During phase 3, g proceeds from x 0 forward along the unitig until it hits x j for the second time. Since x j is occurs exactly twice and is the last vertex of g, this is the end of g. Since j < m, g does not contain w as a subwalk during the third phase.
Now we prove the only if direction. Assume w is not a subwalk of g. Therefore, during the third phase g cannot go until x m and must stop earlier at some x j = suf k (S), for some integer j ∈ [i, m − 1]. This x j was visited once during phase 1 and not visited during phase 2 and now visited a second and final time during phase 3.
These lemmas are all the pieces we need to prove Theorem 1.
Theorem 1. Let S be a set of sequenced segments and let w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (S)). Then w is unsafe if and only if for all S ∈ S, one of the following holds: (i) S does not contain any k-mer of w, (ii) occ S (pre k (S)) = 1 and pre k (S) = x i for some 1 ≤ i ≤ m, (iii) occ S (suf k (S)) = 1 and suf k (S) = x j for some 0 ≤ j ≤ m − 1, or (iv) occ S (pre k (S)) = occ S (suf k (S)) = 2 and there exists 1 ≤ i ≤ j ≤ m − 1 such that pre k (S) = x i and suf k (S) = x j .
Proof. First we prove the if direction. We will show that for all S ∈ S and its corresponding walk g, if one of the four conditions hold, then w is not a subwalk of g. If (i) holds, then w is trivially not a subwalk of g. Now, if pre k (S) = x i for some 1 ≤ i ≤ m and x i is visited only once by g, If (ii) holds, then g starts with x i but never visits x i again, therefore (x 0 , . . . , x i ) is not a subwalk of g. Hence, w is not a subwalk of g. Similarly, if (iii) holds, then (x j , . . . , x m ) is not a subwalk of g and hence w is not a subwalk of g. If (iv) holds, then Lemma A.3 implies that w is not a subwalk of g. Now we prove the only if direction. We will show that for all S ∈ S and their corresponding walk g, if w is not a subwalk of g, then one of the four conclusions hold. By Lemma A.2.(iv), either (1) g does not contain any k-mer from w, (2) pre k (S) ∈ {x 1 , . . . , x m }, or (3) suf k (S) ∈ {x 0 , . . . , x m−1 }. In case of (1), g trivially does not contain w, and condition (i) is satisfied. In case of (2), let i ∈ [1, m] be an integer such that x i = pre k (S). By Lemma A.2.(v), occ S (x i ) is either 1 or 2. If occ S (x i ) = 1, then condition (ii) immediately holds. If occ S (x i ) = 2, then Lemma A.3 implies that there exists an integer j ∈ [i, m − 1] that satisfies condition (iv). In case of (3), let j ∈ [0, m − 1] be an integer such that x j = suf k (S). Again, by Lemma A.2.(v), occ S (x j ) is either 1 or 2. If occ S (x j ) = 1, then condition (iii) immediately holds. If occ S (x j ) = 2, then Lemma A.3 implies that there exists an integer i ∈ [i, m − 1] that satisfies condition (iv). Corollary 1. Let X be a string and let w = (x 0 , . . . , x m ) be a unitig in G basic (sp k (X)). Then spell(w) is not a substring of X iff one of the following holds: 2. occ X (pre k (X)) = occ X (suf k (X)) = 2, pre k (X) = x i , suf k (X) = x j for some 0 < i ≤ j < m.
Moreover, this can hold for at most one unitig in G basic (sp k (X)).
Proof. We can apply Theorem 1 to set S = {X}. Since X must contain all k-mers of w, w is unsafe if and only if condition (ii), (iii) or (iv) from Theorem 1 holds for S = X. First, assume Condition (ii) is true for X. Then by Theorem 1, w is unsafe. Consider the walk g corresponding to X. Because g begins at x i and all vertices in G basic (K) must be in g at least once, (x i , . . . , x m ) is a subwalk of g. This is the one and only occurrence of x i in g. Since x i is the first vertex in g occuring only once, x i−1 cannot precede x i . Hence, x i−1 must be the end of g, i.e., suf k (S) = x i−1 . Note that, this is the one and only occurrence of x i−1 in g. Thus, Condition (iii) is also true for X. With a symmetric argument, we can show that if Condition (iii) is satisfied, then Condition (ii) is satisfied. Combining both gives us the first condition of the corollary. Finally, observe that Condition (iv) is identical to Condition 2 in the corollary. The fact that these conditions can hold for at most one unitig follows directly from the fact that there is only one vertex for pre k (S) in the graph.
Formal definition of the case of Figure 3 In Section 5, we quantify the number of unsafe unitigs that fall into the case of Figure 3. To make this precise, we give a formal classification for this case. Let X be a genome and let S be a set of its sequenced segments. We say that an unsafe walk w = (x 0 , . . . , x m ) satisfies the case of Figure 3 if (i) there exists 0 < i ≤ j < m such that ψ = (x i , . . . , x j ) is a unitig in G basic (sp k (X)), (ii) spell(ψ) occurs at least twice in X, (iii) in one of the occurrences, the k-mer preceding spell(ψ) is not in S, (iv) in another of the occurrences, the k-mer following spell(ψ) is not in S, (v) there exists S ∈ S and an integer i ′ ∈ [i, j] such that spell((x i ′ , . . . , x j )) is a suffix of S, and (vi) there exists S ∈ S and an integer j ′ ∈ [i ′ − 1, j] such that spell((x i , . . . , x j ′ )) is a suffix of S.

B The relationship of G dbl (K) and G bid (K): full exposition
In this section, we will prove Theorem 2. We start by providing additional definitions that are necessary to understand the proofs in this section.
Let K be a set of k-mers. A unitig in a directed graph that is not a proper subwalk of another unitig that ends at the same vertex is said to be prefix-maximal; a unitig that is not a proper subwalk of another unitig that starts with the same vertex is said to be suffix-maximal. Notice that a unitig is maximal iff it is both prefix-and suffix-maximal.
Let (u, s) be a vertex-side in G bid (K). We define d il (u, s) to indicate the presence of an inverted loop, i.e. d il (u, s) = 1 if there is an inverted loop incident to side (u, s) and d il (u, s) = 0 otherwise. A unitig t in G bid (K) is prefix-maximal if it is not a proper subwalk of another unitig that ends at the same vertex-side as t. A unitig is suffix-maximal if it is not a proper subwalk of another unitig that starts with the same vertex-side as t. Note that a unitig is maximal iff it is both prefix-and suffix-maximal.
We will prove Theorem 2 by first building a collection of Lemmas. First, we make a simple observation. A palindrome must have an even number of characters, otherwise there is a middle character that would need to be equal to its own reverse complement. Hence, a palindromic walk, in either the doubled or the bidirected graph must have an even number of nucleotides.
Lemma B.1. Let K be a set of k-mers.
1. For all palindromic walks w = (x 0 , . . . , x n ) in G dbl (K), k and n have the same parity.
2. For all palindromic walks t = (u 0 , s 0 , . . . , u n , s n ) in G bid (K), k and n have the same property.
Proof. A palindromic string must have an even number of nucleotides. The number of nucleotides in spell(w) and in spell(t) is k + n, Hence the parity of k and n must be the same.
From here on out, we proceed by first proving Lemmas for the directed de Bruijn graphs (both the regular one and the doubled one) (Appendix B.1), then proving Lemmas for the bidirected graph (Appendix B.2), then proving Lemmas which connect the two types of graphs (Appendix B.3), and, finally, proving Theorem 2 (Appendix B.4).

B.1 Directed graph
First, we make the observation that unitigs cannot repeat vertices unless they are a simple cycle. This is generally stated without proof, but the statement is actually not true when unitigs are allowed to be periodic cycles. In our definition of unitig, we forbid this case, allowing us to prove the observation.
Lemma B.2. For all unitigs w in a directed graph, either w is a simple cycle or it does not repeat any vertices.
Proof. Let w = (x 0 , . . . , x n ) be a unitig. Suppose that w repeats a vertex. Let 0 ≤ j ≤ n be the smallest value for which there exists 0 ≤ i < j such that x i = x j . If i > 0, then x i has x i−1 and x j−1 as an in-neighbor. By the minimality of our choice of i, x i−1 ̸ = x j−1 , and hence d − (i) ≥ 2. This contradicts that w is a unitig. If i = 0, then let j + 1 ≤ ℓ ≤ n − 1 be the largest index greater than j such that x ℓ = x ℓ mod (j+1) . In other words, ℓ is the first place after x j where the unitig is about to "fall off the cycle". If such an ℓ does not exist, then either j = n and w is a simple cycle, or w is a simple periodic cycle, contradicting the definition of a unitig. Otherwise, the vertex x ℓ has as out-neighbors both x ℓ+1 and x ℓ+1 mod (j+1) . By the choice of ℓ, these out-neighbors are distinct and hence d + (x ℓ ) ≥ 2. This contradicts that w is a unitig.
A very simple property in the doubled graph is is that the in-degree (respectively, out-degree) of a vertex is equal to the out-degree (respectively, in-degree) of its reverse complement. Lemma B.3. Let K be a set of k-mers and let x be a vertex in G dbl (K).
Proof. Observe that for all vertices y in the G dbl (K), there is an edge from x to y in G dbl (K) iff there is an edge from y to x. This is true even if x = y and these two edges are identical. Hence We defined maximal unitigs as those that are not proper sub-walks of other unitigs. We can give an equivalent definition for directed graphs, in terms of vertex degrees. Since it is widely known, we state it without proof.
Lemma B.4. Let G be a directed graph and let w = (x 0 , . . . , x n ) be a unitig in G. Then (i) w is prefix-maximal if and only if d − (x 0 ) ̸ = 1 or there exists a vertex x ′ that has an edge to x 0 and d + (x ′ ) > 1.
(ii) w is suffix-maximal if and only if d + (x n ) ̸ = 1 or there exists a vertex x ′ that has an edge from x n and d − (x ′ ) > 1.
Palindromic unitigs play a special role in Theorem 2. We observe that in a palindromic unitig of the doubled graph, the only edge from a k-mer to its reverse complement is the middle one.
Lemma B.5. Let K be a set of k-mers with odd k. Let w = (x 0 , . . . , x n ) be a palindromic unitig in G dbl (K) that is not a simple cycle. Then for all 0 ≤ i ≤ n − 1, we have that We also observe that a maximal unitig that is not a palindrome cannot contain within it a palindrome of length ≥ k.
Lemma B.6. A non-palindromic maximal unitig w in G dbl (K) cannot contain a proper sub-unitig that is palindromic.
Proof. For the sake of contradiction, let z be a proper sub-unitig of w that is a palindrome. First suppose that there exists a k-mer y such that y precedes z in w and y follows z in w. In that case, observe that the walk (y, z, y) is also a sub-unitig of w and also a palindrome. We can then extend z in this way until no longer possible, i.e. there do not exist a k-mer y such that y precedes z in w and y follows z in w. Let w ′ be this maximally extended walk. Note that by construction, w ′ is a sub-unitig of w and it is proper because w ′ is palindromic and w is not. Let the first vertex of w ′ be x, and, hence, the last one is x.
Consider the case when w starts with x. Because w ̸ = w ′ , there must exist an out-neighbor u of x in w. Its mirror must also exist, i.e. an edge from u to x. Lemma B.4 states that x is the first vertex of a maximal unitig, it must either (a) have one other in-neighbor besides u or (b) u must have at least one other out-neighbor besides x. For case (a), Lemma B.3 implies that In either case, the degrees of x or of u contradict the definition of being part of a unitig. The case when w ends with x is symmetric and omitted. Now consider the case when w does not start with x and does not end with x. Let a be the vertex preceding x in w, and let b be the vertex following x in w. There exist a mirror edge from b to x. Since w ′ was chosen so that it cannot be extended, a ̸ = b. Hence x has two distinct in-neighbors, a and b. Since w contains x as a non-first vertex, this contradicts that w is a unitig.

B.2 Bidirected graph
As is the case with directed graphs (Lemma B.4), there is a definition of maximality for bidirected unitigs that has to do with degrees rather than sub-unitigs. We are not aware of this equivalence being explicitly proven, so we do so here: Lemma B.7. Let K be a set of canonical k-mers. Let t = (u 0 , s 0 , . . . , u n , s n ) be a unitig in G bid (K). Then Proof. We will only prove (i) since the proof of (ii) is symmetric. First, we prove the only if direction. We need to consider three cases. The first case is when d(u 0 , s 0 ) ̸ = 1. If d(u 0 , s 0 ) = 0, then t is prefix-maximal because there is no other walk of which it is a subwalk with the same last vertex-side (u n , s n ). The second case is when d(u 0 , s 0 ) > 1. Consider any walk t ′ that ends in (u n , s n ) and of which t is a proper subwalk. Observe that (u 0 , s 0 ) would not be the first vertex-side of t ′ . Therefore, since d(u 0 , s 0 ) > 1, t ′ cannot be a unitig and t must be prefix-maximal. The third case is when (u 0 , s 0 ) has degree one and (u ′ , s ′ ) is its only neighbor. Again, consider any walk t ′ that ends in (u n , s n ) and of which t is a proper subwalk. Observe that (u ′ , 1 − s ′ ) belongs to t ′ but is not the last vertex-side of t ′ . Therefore, since we assumed that d(u ′ , s ′ ) > 1, t ′ cannot be a unitig and t must be prefix-maximal.
To prove the if direction we prove the contrapositive. In other words, we will show that if the degree of (u 0 , s 0 ) is one and its sole neighbor (u ′ , s ′ ) also has degree at most 1, then t is not prefix-maximal. First, observe that t ′ = (u ′ , 1 − s ′ , u 0 , s 0 , . . . , u n , s n ) is a valid walk, since the edge {(u ′ , s ′ ), (u 0 , s 0 )} exists. Then, observe that the degree of (u ′ , s ′ ) is exactly one because it has degree at most one (by our assumption) and also has a neighbor (i.e. (u 0 , s 0 )). Therefore, the degree requirements for t ′ being a unitig are fulfilled. Finally, observe that t is a proper subwalk of t ′ ending in the same vertex-side, (u n , s n ). Therefore, t is not prefix-maximal.
In a bidirected graph, a walk and its reverse are either both unitigs or not and, if they are, are either both are maximal or not.
Lemma B.8. Let K be a set of canonical k-mers and let w be a unitig in G bid (K).
Proof. Let (u 0 , s 0 , . . . , u n , s n ) = w and (u ′ 0 , s ′ 0 , . . . , u ′ n , s ′ n ) = rev(w). For (i), by definition of rev, we have that u ′ i = u n−i and s ′ n = 1 − s n−i . Applying the definition of unitig to w, we get that These can be equivalently stated as If we change the index variables, these can be equivalently restated as This is precisely the definition of rev(w) being a unitig. For (ii) and (iii), first observe that Lemma B.7 gives an alternate, equivalent, definition for prefix-and suffix-maximal. For (ii), observe that if apply the alternate definition of suffix-maximal to rev(w) and plug in that u ′ n = u 0 and s ′ n = 1 − s 0 , we get precisely the alternate definition of w being prefix-maximal. For (iii), observe that if apply the alternate definition of prefix-maximal to rev(w) and plug in that u ′ 0 = u n and s ′ 0 = 1 − s n , we get precisely the alternate definition of w being suffix-maximal.
While we showed that it is natural for the doubled graph to have a palindromic unitig, this is impossible in a bidirected graph. Lemma B.9. Let K be a set of canonical k-mers, with k odd. Then a unitig of G bid (K) cannot be a palindrome.
Proof. Let t = (u 0 , s 0 , . . . , u n , s n ) be a palindromic walk. By Lemma B.1, n is odd, and so n ≥ 1. For convenience, let m = (n − 1)/2. By definition, spell(t) = spell(t). In particular, the two "central" k-mers of spell(t) must be reverse complements of each other. Formally, orient(lab(u m ), s m ) = orient(lab(u m+1 ), s m+1 ). Since the labels of vertices in a bidirected graph are distinct, lab(u m ) ̸ = lab(u m+1 ) and hence s m = 1 − s m+1 . Applying the definition of a bidirected walk to t, we get that {(u m , 1 − s m ), (u m+1 , s m+1 )} is an edge. The fact that s m = 1 − s m+1 implies that this edge is an inverted loop incident to (u m , 1 − s m ). Thus d(u m , 1 − s m ) ≥ 2, implying that t does not satisfy the definition of being a unitig.

B.3 Connecting the directed and bidirected graphs
So far, we have proven properties of the doubled graph and of the bidirected graph separately; in this section, we prove lemmas about the relationship between the two graphs, when k is odd. Recall that for a k-mer x ∈ K, we defined F V (x) = (u, s), where (u, s) is the unique vertex-side in G bid (K) such that lab(u) = orient(x, s).
Lemma B.10. Let K be a set of canonical k-mers where k is odd. F V is a bijection between vertices of G dbl (K) and vertex-sides of G bid (K).
Proof. To show that F V is a bijection, we will show that for all vertex-sides (u, s) in G bid (K), there exists a unique k-mer x in G dbl (K) such that F V (x) = (u, s). Consider a value of x such that F V (x) = (u, s). By definition, lab(u) = orient(x, s)). Since k is odd and x is not a palindrome, the value of x satisfying this must be unique. By construction of G dbl (K) and G bid (K), k must be a vertex in G dbl (K). Further, if x = orient(lab(u), s), then orient(x, s) = orient(orient(lab(u), s), s) = lab(u) and so x satisfies the condition that F V (x) = (u, s).
We will use F −1 V to denote the inverse of F V , which was shown in Lemma B.10 is F −1 V (u, s) = orient(lab(u), s). We will use x F V ⇐ = ⇒ (u, s) to denote that a vertex x of G dbl (K) and a vertex-side (u, s) in G bid (K) are associated with each other by F V .
Recall that for two G dbl (K) k-mers x 1 and x 2 , we define the mapping . Though the mapping is not a bijection, it preserves the property of being an edge in the respective graph 2 : Lemma B.11. Let K be a set of canonical k-mers where k is odd. Let x 1 and x 2 be vertices in G dbl (K). We have that ( Proof. By the definition of bidirected edges, F E (x 1 , x 2 ) = {(u 1 , 1 − s 1 ), (u 2 , s 2 )} is an edge iff suf (orient(lab(u 1 ), s 1 )) = pre(orient(lab(u 2 ), s 2 )). ( Recall that by the definition of F E , lab(u 1 ) = orient(x 1 , s 1 ) and lab(u 2 ) = orient(x 2 , s 2 ). We can therefore rewrite Equation (1) equivalently as suf (orient(orient(x 1 , s 1 ), s 1 )) = pre(orient(orient(x 2 , s 2 ), s 2 )). (2) Now, using the fact that orient(orient(y, s), s) = y, for all y and s, we can rewrite Equation (2) as Since we obtained Equation (3) from Equation (1) using equivalent transformations, it shows that the two statements are equivalent and completes the proof.
One particular case of Lemma B.11 that we will often invoke is that there is an edge from x to x in G dbl (K) if and only if there is an inverted loop incident to (u, 1 − s) in G bid (K). Now recall that F W is defined as a function that maps a walk w = (x 0 , . . . , x n ) in G dbl (K) to a sequence F W (w) = (u 0 , s 0 , . . . , u n , s n ), with (u i , s i ) = F V (x i ) for all 0 ≤ i ≤ n. We show that F W (w) is in fact a walk in G bid (K) and, moreover, F W is a bijection from the set of walks in G dbl (K) to the set of walks in G bid (K).
Lemma B.12. Let K be a set of canonical k-mers where k is odd. F W is a spell-preserving bijection from the set of walks in G dbl (K) to the set of walks in G bid (K).
Proof. Let w = (x 0 , . . . , x n ) be a walk in G dbl (K) and let (u i , s i ) = F V (x i ) for all 0 ≤ i ≤ n. We will first show that F W (w) = (u 0 , s 0 , . . . , u n , s n ) is a walk in G bid (K). By definition of F V , F W (w) is a sequence of vertex-sides. Consider the edge from x i to x i−1 , for all 1 ≤ i ≤ n. By Lemma B.11, there is an edge {(u i−1 , 1−s i−1 ), (u i , s i )} in G bid (K). This shows that every two consecutive vertexsides in F W (w) are connected by an edge, thus completing the proof that F W (w) is a walk. The fact that it is spell preserving follows from its definition.
To show that F W is a bijection, we need to show that for all walks t = (u 0 , s 0 , . . . , u n , s n ) in G bid (K), there exists a unique walk w in G dbl (K) such that t = F W (w). Let w = (x 0 , . . . , x n ) be an arbitrary walk in G dbl (K). In order for F W (w) = t, we need that F V (x i ) = (u i , s i ) for all 0 ≤ i ≤ n. Because F V is bijection (Lemma B.10), there is exactly one value of x i to satisfy this, and that is Given the above proof, we can write the inverse of F W as F −1 W (u 0 , s 0 , . . . , u n , s n ) = (orient(lab(u 0 ), s 0 ), . . . , orient(lab(u n ), s n )). We will use w F W ⇐ = ⇒ t to denote that a walk w in G dbl (K) and a walk t in G bid (K) are associated with each other by F W .
Notice that if k were to be even, then Lemma B.12 would not hold. In particular, Let x ∈ K be a palindrome k-mer and let u be the vertex in G bid (K) such that lab(u) = x. Then both of the walks (u, 0) and (u, 1) would spell x, while in the G dbl (K) there would only be one walk that spells x.
Since unitigs are defined in terms of degrees, it is useful to first understand how the degrees of vertices in G dbl (K) relate to the degrees of vertex sides in G bid (K).
Lemma B.13. Let K be a set of canonical k-mers where k is odd. Let x be a vertex in G dbl (K) and let (u, s) be a vertex-side is G bid (K) such that x F V ⇐ = ⇒ (u, s). Then, Proof. For proving part (i), we will first prove an upper bound and then a matching lower bound. We start with the upper bound. Let Y be the set of all out-neighbors of x which are not equal to x. Note that Y may contain x. Let Y ′ = {F V (y) | y ∈ Y } and observe that since In the second case, assume that there exists an edge (x, x). Lemma B.11 says that there is an inverted loop incident to side (u, 1 − s), so d il (u, 1 − s) = 1. An inverted loop adds 2 to the degree of (u, 1 − s), i.e. d(u, 1 − s) ≥ |Y ′ | + 2; it also contributes 1 to out-degree of x, i.e. d + (x) = |Y | + 1.
Putting these together, we get For the lower bound, let Z ′ be the set of all vertex-sides (u ′ , s ′ ) such that (u ′ , s ′ ) ̸ = (u, 1 − s) and there is an edge By Lemma B.11, for every z ∈ Z, there is an edge from x to z in G dbl (K) and therefore d + (x) ≥ |Z| = |Z ′ |. Now we show that d(u, 1 − s) ≤ d + (x) + d il (u, 1 − s) by considering two cases. In the first case, assume that there is no inverted loop touching (u, 1−s). Then, d(u, 1−s) = |Z ′ | and d il (u, 1−s) = 0. We can therefore write d(u, In the second case, assume there exists an inverted loop touching (u, 1 − s). In this case, d(u, 1 − s) = |Z ′ | + 2. By Lemma B.11, there is an edge from x to x and x / ∈ Z. Thus, d + (x) ≥ |Z| + 1. Putting this together, d(u, For part (ii), observe that F V (x) = (u, 1 − s). We can then apply part (i) of this theorem to x, u, and 1 − s, and get that d An immediate consequence of the degree-preserving lemma is that if F (w) is a unitig, then so is w. The converse is not always true however.
Lemma B.14. Let K be a set of canonical k-mers where k is odd. Let w = (x 0 , . . . , x n ) and t = (u 0 , s 0 , . . . , u n , s n ) be two walks related by w (i) If t is a unitig, then w is a unitig.
(ii) If w is a unitig and for all 1 ≤ i ≤ n, x i−1 ̸ = x i , then t is a unitig.
Proof. For (i), when n = 0, w is trivially a unitig because it has only one vertex. For n > 0, since t is a unitig, d(u i , s i ) = 1 for 0 < i ≤ n. Moreover, since an inverted loop would make a degree ≥ 2, we have d il (u i , s i ) = 0. Using Lemma B.13, d − (x i ) = 1. Similarly, for all 0 ≤ i < n, d(u i , 1 − s i ) = 1, d il (u i , 1 − s i ) = 0, and Lemma B.13 gives that d + (x i ) = 1. Hence w is a unitig.
For (ii), first observe that there is no inverted loop incident to (u i , s i ), for 1 ≤ i ≤ n. If that were the case, then Lemma B.11 implies that there is an edge from x i to x i . Since w is a unitig, the only in-neighbor of x i is x i−1 . Hence, x i−1 = x i , which contradicts the conditions of the Lemma.
Similarly, we can relate the maximality of unitigs in G dbl (K) and G bid (K). A maximal unitig in G dbl (K) is maximal in G bid (K), on the condition that is a unitig in G bid (K); however, the other direction only holds with a restrictive condition.
Lemma B.15. Let K be a set of canonical k-mers where k is odd. Let w = (x 0 , . . . , x n ) and t = (u 0 , s 0 , . . . , u n , s n ) be two walks related by w (i) If t is prefix-maximal and has no lonely inverted loop at the first endpoint side, then w is prefix-maximal.
(ii) If w is prefix-maximal, then t is prefix-maximal.
(iii) If t is suffix-maximal and has no lonely inverted loop at the last endpoint side, then w is suffix-maximal.
(iv) If w is suffix-maximal, then t is suffix-maximal.
and Lemma B.11 implies that there is an edge from x ′ to x 0 in G dbl (K). Observe that because d(u 0 , s 0 ) < 2, e is not an inverted loop. Therefore, (u ′ , s ′ ) has at least one incident edge that is not an inverted loop. Because an inverted loop adds at least two to the degree, d(u ′ , s ′ ) − d il (u ′ , s ′ ) > 1. Thus, Lemma B.13 implies that d + (x ′ ) > 1. By Lemma B.4, w is a prefix-maximal unitig.
For (ii), suppose for the sake of contradiction that t is not prefix-maximal. Then Lemma B.7 implies that d(u 0 , s 0 ) = 1 and there exists a vertex-side (u ′ , s ′ ) with d(u ′ , s ′ ) = 1 and an edge Note that d il (u 0 , s 0 ) = d il (u ′ , s ′ ) = 0 because vertex-sides with degree 1 cannot have an inverted loop incident to them. Lemma B.13 then implies that d − (x 0 ) = d(u 0 , s 0 ) = 1 and d + (x ′ ) = d(u ′ , s ′ ) = 1. In addition, Lemma B.11 applied to e says that there is an edge from x ′ to x. By Lemma B.4, these facts imply that w is not prefix-maximal, which is a contradiction.
Theorem 2 has a condition that there are no circular unitigs. We now show that this implies that a unitig in G bid (K) cannot have lonely inverted loops incident to both of the endpoint sides.
Lemma B.16. Let K be a set of canonical k-mers where k is odd. Let w = (x 0 , . . . , x n ) be a walk in G dbl (K) such that F W (w) is a unitig. If the two endpoint sides of F W (w) have lonely inverted loops incident on them, then w ′ = (x 0 , . . . , x n , x n , . . . , x 0 , x 0 ) is a circular unitig in G dbl (K).
Proof. First, to show that w ′ is a walk in G dbl (K), we need to show that there exist edges (x 0 , x 0 ) and (x n , x n ). This follows by applying Lemma B.11 to the inverted loop edges at the endpoints of F (w), i.e. to {(u 0 , s 0 ), (u 0 , s 0 )} and {(u n , 1 − s n ), (u n , 1 − s n )}.
Second, to show that w ′ is a unitig, we will show that all the necessary vertex degrees are 1. By Lemma B.14, w is a unitig, and hence d + (x i ) = 1 for all 0 ≤ i < n and d − ( Because the endpoint sides of F (w) each have a lonely inverted loop, d(u 0 , s 0 ) = 2 and d(u n , 1 − s n ) = 2. Applying Lemma B.13, Applying Lemma B.3 to all these, we get that d − (x i ) = 1 for all 0 ≤ i ≤ n and d + (x i ) = 1 for all 0 ≤ i ≤ n.

B.4 Proof of Theorem 2
Theorem 2. Let K be a set of canonical k-mers where k is odd and G dbl (K) does not contain a circular unitig.
(i) The function F W is a bijection from D non-pal to B no-loop .
(ii) The function rev is a bijection between B last-loop and B first-loop .
(iii) head is a bijection from D pal and B last-loop Proof.
(i) We already know from Lemma B.12 that F W is a bijection between walks in G dbl (K) and G bid (K). It remains to show that (1) For a unitig w that is maximal and non-palindromic in G dbl (K), F W (w) ∈ B no-loop .
(2) For a unitig t ∈ B no-loop , F −1 (t) is a maximal and non-palindromic unitig in G dbl (K).
First, we prove (1). Because w is a non-palindromic maximal unitig, by Lemma B.6, there is no edge 0 ≤ i < n such that x i = x i+1 , because then (x i , x i+1 ) would be a palindromic sub-unitig of w. Hence we can apply Lemma B.14 to say that F W (w) is a unitig and we can apply Lemma B.15 to say that F W (w) is maximal. Hence F W (w) ∈ B. To show that F W (w) / ∈ B 2 ∩ B 3 , first assume for the sake of contradiction that there is a lonely inverted loop at the last endpoint side of F W (w). Then by Lemma B.11 there is an edge from x n to x n . By Lemma B.13, This is a contradiction. The argument that there is no lonely inverted loop at the first endpoint side of F W (w) is symmetric and omitted. Now, we prove (2). Let w = F −1 (t). Since t is a unitig, Lemma B.14 implies that w is a unitig also. Moreover, Lemma B.9 implies that t is non-palindromic; since F W is spelling preserving (Lemma B.12), w is also non-palindromic. Since the Theorem assumes that G dbl (K) does not have circular unitigs, Lemma B.16 implies that t cannot have a lonely inverted loop at both endpoints. Since t / ∈ B 2 ∪ B 3 , it also cannot have an inverted loop at exactly one endpoint. We can therefore apply Lemma B.15 to get that w is maximal.
(ii) Observe that rev is by definition a function that is its own inverse and is a bijection on the set of walks in G bid (K). Furthermore, Lemma B.8 implies that rev remains a bijection when restricted to maximal unitigs in G bid (K). Finally, observe that for a walk t, the first (respectively, last) endpoint side of t is the last (respectively, first) endpoint side of rev(t).
These facts together imply that rev is a bijection between B first-loop and B last-loop .
(iii) To show that head is a bijection we show (1) for all w ∈ D pal , head(w) ∈ B last-loop , (2) for all t ∈ B last-loop , there exists a w ∈ D pal such that head(w) ∈ B last-loop .
(3) the above w is unique.
First, we prove (1). Let w = (x 0 , . . . , x n ). By Lemma B.1, n is odd and at least 1. Let m = (n − 1)/2 and let h ≜ (x 0 , . . . , x m ). Since w is a palindromic unitig and, by the conditions of the Theorem, non-circular, Lemma B.5 implies that for all 0 ≤ i < n, x i ̸ = x i+1 . Then by Lemma B.14, head(w) = F W (h) is a unitig. Simultaneously, because w is a maximal unitig, h is a prefix-maximal unitig. Lemma B.15 then implies that F W (h) is prefix-maximal. Next we prove (2). Let (u 0 , s 0 , . . . , u n , s n ) = t and let x i = F −1 V (u i , s i ). Let w = (x 0 , . . . , x n , x n , . . . , x 0 ) be a sequence of vertices in G dbl (K). We will first show that w is a walk, then that it is palindromic, then that it is a unitig, and finally that it is maximal. Note that w is equivalently defined to be the concatenation of F −1 W (t) with F −1 W (rev(t)). Applying Lemma B.12, the sequences (x 0 , . . . , x n ) and (x n , . . . , x 0 ) are walks. Since t is in B last-loop , there is an inverted loop incident to (u n , 1 − s n ). By Lemma B.11, this implies there is an edge from x n to x n in G dbl (K). Therefore, w is a walk. It is palindromic by its definition. Since t is a unitig, by Lemma B.8, rev(t) is a unitig. Now applying Lemma B.14, w and rev(w) are both unitigs. Because the inverted loop is lonely, d(u n , 1 − s n ) = 2, and by Lemma B.13, d + (x n ) = 1. Applying Lemma B.3, d − (x n ) = 1. Hence w is a unitig.
As t is in B last-loop , this implies that no lonely inverted loop is incident to (u 0 , s 0 ). We can apply Lemma B.15 to get that F −1 (t) is prefix-maximal. Because w starts with F −1 (t), w is also prefix-maximal. By Lemma B.8, F −1 (rev(w)) is suffix-maximal. Because w ends with F −1 (rev(w)), w is also suffix-maximal. Hence, w is maximal.

C Experimental details
Choice of k parameter for the assemblers: To ensure that the results across the assemblers are comparable, we set the k parameter in a way so that the set of unitigs constructed are as close as possible. The ideal way is to set k such that the underlying k-mer sets K used for all assemblers are same. However, there was a practical limitation for that. We note that both SPAdes and MEGAHIT are a multi-k assemblers, so the k parameter is just the maximum allowed k-mer size. When we pass the value k to the assemblers, both SPAdes and MEGAHIT use k-mer set and (k + 1)-mer set to construct unitigs, whereas bcalm, ABySS, and minia uses a node-centric de Bruijn graph with only k-mer sets as vertices. As such, we found that the output unitigs of SPAdes and MEGAHIT with a value of k are more similar to unitigs of bcalm and ABySS created with k + 1. We also note that SPAdes and MEGAHIT only allow odd k, which is why we needed to use an even k for G dbl .
In Table 3, we therefore passed k = 74 to bcalm and k = 73 to SPAdes and MEGAHIT. Since Theorem 1 is valid for all k, this was not an issue for Table 3. We used the default parameter for minimum k-mer coverage for both assemblers.
For Table 6, we passed k = 31 to all assemblers, since Theorem 2 only applies when the vertex lengths are of odd k. Since SPAdes and MEGAHIT by default use both k-mer and (k + 1)-mer set to construct unitigs, the number of palindromic unitigs (433) differs from the number in minia and ABySS (440). However, this is not a problem because we are not comparing the numbers between assemblers but only within assemblers.