Generating normal networks via leaf insertion and nearest neighbor interchange

Background Galled trees are studied as a recombination model in theoretical population genetics. This class of phylogenetic networks has been generalized to tree-child networks and other network classes by relaxing a structural condition imposed on galled trees. Although these networks are simple, their topological structures have yet to be fully understood. Results It is well-known that all phylogenetic trees on n taxa can be generated by the insertion of the n-th taxa to each edge of all the phylogenetic trees on n−1 taxa. We prove that all tree-child (resp. normal) networks with k reticulate nodes on n taxa can be uniquely generated via three operations from all the tree-child (resp. normal) networks with k−1 or k reticulate nodes on n−1 taxa. Applying this result to counting rooted phylogenetic networks, we show that there are exactly \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\frac {(2n)!}{2^{n} (n-1)!}-2^{n-1} n!$\end{document}(2n)!2n(n−1)!−2n−1n! binary phylogenetic networks with one reticulate node on n taxa. Conclusions The work makes two contributions to understand normal networks. One is a generalization of an enumeration procedure for phylogenetic trees into one for normal networks. Another is simple formulas for counting normal networks and phylogenetic networks that have only one reticulate node.


Background
Phylogenetic networks have been used to date both vertical and horizontal genetic transfers in evolutionary genomics and population genetics in the past two decades [1][2][3]. A rooted phylogenetic network (RPN) is a directed acyclic digraph in which all the sink nodes are of indegree 1 and a unique source node is designated as the root, where the former represent a set of taxa (e.g, species, genes, or individuals in a population) and the latter represents the least common ancestor of the taxa. Moreover, the other nodes in a RPN are divided into tree nodes and reticulate nodes, where reticulate nodes represent reticulate evolutionary events such as horizontal genetic transfers and genetic recombination.
The topological properties of RPNs are much more complicated than phylogenetic trees [2,4,5]. Therefore, different mathematical issues arise in the study of inserting the n-th taxa in every edge of all the phylogenetic trees on n − 1 taxa. We prove that all TCNs with k reticulate nodes on n taxa can be uniquely generated via three operations from TCNs with k − 1 or k reticulate nodes on n − 1 taxa (Theorem 1, "Generating TCNs and normal networks" section). Using this fact, we obtain recurrence formulas for counting TCNs and normal networks ("Counting formulas" section). In particular, simple formulas are given for the number of RPNs and normal networks with one reticulate node, respectively.

Basic notation
A RPN over a finite set of taxa X is an acyclic digraph such that: • there is a unique node of indegree 0 and outdegree 1, called the root; • there are exactly |X| nodes of outdegree 0 and indegree 1, called the leaves of the RPN, each being labeled with a unique taxon in X ; • each non-leaf/non-root node is either a reticulate node that is of indegree 2 and outdegree 1, or a tree node that is of indegree 1 and outdegree 2; and • there are no parallel edges between a pair of nodes.
Two RPNs are drawn in Fig. 1, where each edge is directed away from the root and both the root and edge orientation are omitted. For a RPN N, we use V(N), R(N), T (N) and E(N) to denote the set of all nodes, the set of reticulate nodes and the set of tree nodes and the set of directed edges for N, respectively.
Let u ∈ V(N) and v ∈ V(N). The node u is said to be a parent (resp. a child) of v if (u, v) ∈ E(N) (resp. (v, u) ∈ E(N)). Every reticulate node r has a unique child, named c(r), whereas every tree node t has a unique parent, named p(t). Furthermore, u is an ancestor of v or, equivalently, v is below u if there is a direct path from the network root to v that contains u. We say that u and v are incomparable if neither of them is an ancestor of the other.
It is a reticulate edge if v is a reticulate node and a tree edge otherwise. Hence, a tree edge leads to either a tree node or a leaf.
A phylogenetic tree is simply a RPN with no reticulate nodes.
A TCN is a RPN in which every non-leaf node has a child that is a tree node or a leaf or, equivalently, there is a path from every non-leaf node to some leaf that consists only of tree edges. Both RPNs in Fig. 1 are tree-child.
A normal network is a TCN in which every reticulate node satisfies the following condition: (The normal condition) The two parents are incomparable.
The first PRN in Fig. 1 is not normal, as a parent of the left most reticulate node is an ancestor of the other in the network.

Generating TCNs and normal networks
We define the following rearrangement operations for TCNs N on [ 1, n], which are illustrated in Fig. 2: insert a new node w to subdivide e and attach Leaf n + 1 below w as its child. The resulting network is denoted by Leaf-Insert(N, e, n + 1), in which w is a tree node. • Reticulation insertion For a pair of tree edges e 1 = (u 1 , v 1 ) and e 2 = (u 2 , v 2 ) of N, which are not necessarily distinct, insert a new node w 1 to subdivide e 1 and a new node w 2 to subdivide e 2 , attach a new reticulate node r as the common child of w 1 and w 2 and make Leaf (n + 1) to be the child of r. In this case, we say that r straddles e 1 and e 2 . We use Ret-Insert(N, e 1 , e 2 , n + 1) to denote the resulting network. We simply write Ret-Insert(N, e, n + 1) if e 1 = e 2 = e. • Child rotation Let r be a reticulate node with parents u ∈ T (N) and v. If u is not an ancestor of v, exchange the unique child of r and the other child of u. The resulting network is denoted by C-Rotate(N, u, r).
Note that a child rotation is a special case of the rNNI rearrangement introduced by Gambette et al. in [12]. Let T CN k (n) denote the set of TCNs with k reticulations on [ 1, n].  Proof The second statement is a special case of the first. Let e 1 = (u, v) and e 2 = (x, y). Since e 1 and e 2 are tree edges, both v and y are tree nodes or leaves. Let r be the added reticulate node. Then the parents of r have v and y as their child, respectively, the nodes u and x have the parents of r as their tree node child; Leaf n + 1 is the tree child r. Additionally, all the other nodes have the same children as in M. Therefore, Ret-Insert (M, e 1 , e 2 , n + 1) is a TCN.

Proposition 2
Let M ∈ T CN k+1 (n + 1). Assume that r ∈ R(M) and its parents are u and v such that u is not an ancestor of v in M. Then, C-Rotate (M, u, r) ∈ T CN k+1 (n + 1).
Proof Let M = C-Rotate (M, u, r). Since u is a parent of r and M is tree-child, u is a tree node. Let w be the other child of u and let z be the unique child of r. Since M is treechild, z and w are tree nodes (see Fig. 2). The tree node z becomes the child of u Therefore, every node also has a child that is a tree node or a leaf in M .
By definition, w becomes a child of r and z becomes a tree node child of u in M . If M contains a directed cycle C, C must contain v and w, implying that u is an ancestor of v in M, a contradiction. Therefore, M is acyclic and M ∈ T CN k+1 (n + 1).
is the child of a reticulate node r, N can then be obtained from an M ∈ T CN k (n) via a reticulation insertion.
(ii) If Leaf (n + 1) is the child of a tree node t and the sibling of n+1 is also a tree node, N can then obtained from an M ∈ T CN k+1 (n) via a leaf insertion.
is a child of a tree node t and the sibling of n + 1 is a reticulate node, N can then be obtained from an M ∈ T CN k+1 (n + 1) via a child rotation.
Proof (i) Let r have parents u 1 and u 2 in N. Since N is a TCN, u 1 and u 2 are tree nodes and so are their children other than r. Let w i and v i be the parent and the child of u i such that v i = r, respectively, for each i = 1, 2. Since r is a reticulate node, v 1 and v 2 are tree nodes. Without loss of generality, we assume that u 2 is not the parent of u 1 . There are two cases for consideration.
If u 1 is the parent of u 2 , then u 1 = w 2 and u 2 = v 1 (Fig. 3a). Removing Leaf (n + 1), u 1 and u 2 (together with incident edges) and adding an edge e = (w 1 , v 2 ) produce a TCN M with k reticulations such that N = Ret-Insert (M, e, n + 1).
If u 1 is not the parent of u 2 , then, w 1 = u 2 (Fig. 3b). After removing Leaf n + 1, u 1 and u 2 (together with incident edges) and adding two edges (ii) Let u be the parent of t and let v be the sibling of Leaf n + 1 (Fig. 3c). By assumption, v is a tree node. After removing t and Leaf (n + 1) (together with incident edges) and adding e = (u, v), we obtain a TCN M ∈ T CN k+1 (n) such that N = Leaf-Insert (M, (u, v), n + 1).
(iii) Let y be the sibling of n + 1 that is a reticulate node (Fig. 3d). Let z be the child of y and let M = C-Rotate (N, t, y). Since z is below y and y is below t in N, neither attaching the tree node z below t nor attaching Leaf (n + 1) below y generates a directed cycle in M. Hence, M ∈ T CN k+1 (n + 1) in which Leaf (n + 1) is the child of a reticulate node y such that N = C-Rotate (M, t, y).  3 An illustration of the proof of Proposition 3. a The reticulate node parent r of n + 1 has two adjacent parents. b The reticulate node parent r of n + 1 has two non-adjacent parents. c The parent and sibling of n + 1 are both a tree node. d The parent of n + 1 is a tree node, whereas the sibling of n + 1 is a reticulate node (ii) Ret-Insert N 1 , e 1 , e 1 , n + 1 is identical to Ret-Insert N 2 , e 2 , e 2 , n + 1 iff N 1 = N 2 .
(iii) Assume the parent of Leaf n is a reticulate node N 1 , e 1 , n + 1) and M 2 = Leaf-Insert (N 2 , e 2 , n + 1) such that M 1 = M 2 . Then, there exists a node mapping φ from M 1 to M 2 such that (i) it maps a leaf in M 1 to the same leaf and (ii) (φ(u), φ(v)) ∈ E(M 2 ) if and only if (u, v) ∈ E(M 1 ). Since n + 1 is inserted as a leaf, φ maps the parent p 1 of (n+1) in M 1 to the parent p 2 of n + 1 in M 2 , implying that φ induces an isomorphic mapping from N 1 to N 2 . This proves the necessity condition. The sufficient condition is straightforward.
(ii) and (iii) Both statement can be proved similarly. The proposition is proved. Figure 4 show how to generate the left TCN given in Fig. 1.

Main theorems
Taken together, Propositions 1-4 imply the following theorem.
Theorem 1 Each TCN of T CN k+1 (n + 1) can be obtained from either (i) a unique TCN of T CN k+1 (n) by attaching Leaf n + 1 to a tree edge or (ii) a unique TCN N ∈ T CN k (n) by applying one of the following operations: (a) Insertion of a reticulate node r with the child Leaf (n + 1) into a tree edge or straddling two tree edges; (b) Insert r into a tree edge (u, v), as described in (a), and then conduct the child rotation to switch the child of r and the tree node child of v. (c) Insert r straddling two tree edges e = (u , v ) and e = (u , v ), as described in (a), and then conduct the child rotation to switch the child of r and the tree node child of v (resp. v ) if u (resp. u ) is not an ancestor of u (resp. u ).
If we restrict the operations on normal networks, we obtain all the normal networks in T CN k+1 (n + 1). However, inserting a reticulate node and then applying the child rotation may lead to a scenario that a reticulation no longer satisfy the normal condition (Fig. 5). Hence, the child-rotation operation should be taken after some verification when all normal networks are enumerated.
Theorem 2 Each normal network of T CN k+1 (n + 1) can be obtained from either (i) a unique normal network in T CN k+1 (n) by attaching Leaf n + 1 to a tree edge or (ii) a unique normal network N ∈ T CN k (n) by applying one of the following operations for each pair of incomparable edges e 1 = (u 1 , v 1 ) and e 2 = (u 2 , v 2 ) in N: (c) Insert r as described in (a) and then conduct the child rotation to make v 2 to be the child of r and n + 1 the child of p 2 , respectively, unless a reticulate edge (x, y) exists in N such that: (c.1) y is below v 2 ; (c.2) x is not an ancestor of v 2 ; (c.3) x is an ancestor of v 1 .
Proof The statement for normal networks is based on the fact that if N is obtained from N vis one of the three operations given in Theorem 1, that the normality of N implies the normality of N .
The conditions in (b) and (c) are used to exclude the child rotations that make the normal condition invalid for some existing reticulate nodes in the generated TCN.

Counting formulas
Let N be a TCN. For a pair of edges (u 1 , v 1 ) and (u 2 , v 2 ) of N, they are incomparable if neither of v 1 and v 2 is an ancestor of the other. Let u(N) be the number of unordered pairs of incomparable edges in N and let: Define a n,k to be |T CN k (n)|, 0 ≤ k < n and b n,k to be the number of normal networks in TCN k (n), 0 ≤ k < n.
Theorem 3 (i) The a n,k can be calculated through the following recurrence formula: where a 2,0 = 1 and u n−1,k−1 is defined in Eq. ( 1).
(ii) The b n,1 can be calculated through the following recurrence formula: where u n−1,0 is the total number of unordered pairs of incomparable edges in all the phylogenetic trees on n − 1 taxa.
Proof (i) The unique tree on two taxa is a TCN and thus a 2,0 = 1.

Fig. 5
Illustration the undesired condition in Theorem 2 that prevents from applying s a child rotation. Here, the reticulate node r and its child Leaf 4 are first inserted into the tree edges entering v 1 and v 2 (i.e. 2) in a normal network (top), generating a normal network (middle). But, child rotation to left leads to a tree-child network that is no longer normal (bottom), in which y does not satisfy the normal condition Each TCN of T CN k (n − 1) has 2n + k − 3 tree edges and Leaf n can be attached to each of these edges. The first term of the right hand side of Eq. (2) counts the TCNs obtained by applying the leaf insertion in Theorem 1.
Consider N ∈ T CN k−1 (n − 1). N has n − 1 leaves, n + k − 3 tree nodes, and thus 2n + k − 4 tree edges. The reticulation insertion can be used on a single edge or a pair of edges in N. Thus, we can insert a reticulate node r with the child Leaf n in 2n+k−4+ 2n+k−4 2 = (2n+k−3)(2n+ k − 4)/2 possible ways. After the insertion of r in a tree edge (u, v), we can apply a child rotation to exchange Leaf n with v, as u is not an ancestor of v after r was inserted. Similarly, after r is connected to a pair of edges e 1 and e 2 , we can apply a child rotation once if one edge is below the other and in two possible ways if neither is an ancestor of the other.
In summary, for each unordered pair of tree edges (e 1 , e 2 ), we can generate three different tree child networks with k reticulations on [ 1, n] if they are incomparable and two otherwise. Thus, we have the second and third terms of the formula.
In the case that n > 2 and k ≤ n − 2, Eq. (3) for b n,1 follows from the following two facts: • Only two incomparable edges in normal networks in T CN k−1 (n − 1) can be used to generate normal networks in T CN k (n); • For each unordered pair of incomparable edges in a tree on [ 1, n − 1], three normal networks can be obtained by applying insertion of reticulate node and two child rotations.
Unfortunately, we do not know how to obtain a simple formula for b n,k in general. By Theorem 3, one still can compute the number of normal networks with k reticulate nodes on [ 1, n], b n,k , by enumeration. For each 1 ≤ k ≤ n − 2 and 3 ≤ n ≤ 7, b n,k is listed in Table 1.
It is challenging to obtain a simple formula for counting u n,k for arbitrary k. But we can find a closed formula for u n,0 and thus obtain a recurrence formula for a n,1 and b n,1 . Lemma 1 For any n ≥ 2, the total number of unordered pairs of incomparable edges in all the phylogenetic trees on n taxa is: Proof Let T be a phylogenetic tree on [ 1, n − 1] and let O(T) denote the set of ordered pairs of comparable edges in T, where that (x, y) ∈ O(T) means the edge x is above the edge y. Then, it is not hard to verify: Assume T is obtained from T by attaching Leaf n in an edge e = (u, v). In T , the parent w of Leaf n is the tree node inserted in e, implying that e is subdivided into two edges of T : Since T has 2n − 3 edges, where LI(T, n) denotes the set of 2n − 3 phylogenetic trees that are obtained by a Leaf-Insertion on T. Let c n be the total number of unordered pairs of comparable edges in all the phylogenetic trees on n taxa. Clearly, c 2 = 2. Since there are (2n−4)! 2 n−2 (n−2)! phylogenetic trees with n − 1 leaves, which each have 2n − 3 edges, Eq. (5) implies: Therefore, where (2k)! (k+1)!k! is the k-th Catalan number C k that is equal to the integral appearing above ( [31]). Since there are (2n−2)! 2 n−1 (n−1)! phylogenetic trees on [ 1, n] each having (2n−1) edges, Theorem 4 For any n ≥ 3, the numbers of TCNs and normal networks with exactly one reticulate node on n taxa are: a n,1 = (2n)! 2 n (n − 1)! − 2 n−1 n! ( 6 ) and b n,1 = (n + 2)(2n)! 2 n n! − 3 · 2 n−1 n! , respectively.

Remark 1
Every RPN with exactly one reticulate node is a TCN. Therefore, a n,1 is actually the number of RPNs with one reticulate node.

Conclusions
It is well-known that all phylogenetic trees on n taxa can be generated by the insertion of the n-th taxa in each edge of all the phylogenetic trees on the first n − 1 taxa. The main result of this work is a generalization of this fact into TCNs. This leads to a simple procedure for enumerating both normal networks and TCNs, the C-code for which is available upon request. It is fast enough to count all the normal networks on eight taxa. Recently, Cardona et al. introduced a novel operation to enumerate TCNs. Their program was successfully used to compute the exact number of tree-child networks on six taxa. Although our program is faster than theirs, it still cannot be used to count TCNs on eight taxa on a PC.
Another contribution of this work is Eq. (6) and (7) for counting RPNs with exactly one reticulate node. Semple and Steel [30] presented formulas for counting unrooted networks with one reticulate node. Since an unrooted networks can be oriented into a different number of RPNs, it is note clear how to use their results to derive a formula for the count of RPNs. Bouvel et al. [26] presented a formula for counting RPNs with one reticulate node. Our formula is much simpler than the formula given in [26].
Lastly, the following problem is open: Is there a simple formula like Eq. (6) for the count of TCNs with k reticulate nodes on n taxa for each k > 1?

Availability of data and materials
Data sharing is not applicable to this article as no datasets were generated or analysed during the current study.

Ethics approval and consent to participate
This research did not involve any human subjects, human material, or human data. The ethics approval is not applicable.

Consent for publication
Not applicable.