#' List of permutations.
#'
#' List of permutations of given elements.
#'
#' @param populations  A vector (of populations for example) of length between 4 and 8.
#'
#' @return A list of different permutations of the elements of \code{x}.
#'
#'
#' @examples
#' \donttest{
#' # The number of permutations of n elements is n!. Take 0! = 1, 1! = 1, 2! = 2
#' # and 3! = 6 for granted. Now we can estimate e:
#' FOUR <- length(make_permutations(c(1, 2, 3, 4)))
#' FIVE <- length(make_permutations(c(1, 2, 3, 4, 5)))
#' SIX <- length(make_permutations(c(1, 2, 3, 4, 5, 6)))
#' SEVEN <- length(make_permutations(c(1, 2, 3, 4, 5, 6, 7)))
#' EIGHT <- length(make_permutations(c(1, 2, 3, 4, 5, 6, 7, 8)))
#' 1/1 + 1/1 + 1/2 + 1/6 + 1/FOUR + 1/FIVE + 1/SIX + 1/SEVEN + 1/EIGHT
#' # Hey that was pretty close!
#' }
#'
#' @export
make_permutations <- function(populations) {
if (length(populations) == 1) {
P <- list(populations[1])
} else {
P <- list()
for (j in seq(1, length(populations))) {
endings <- make_permutations(populations[-j])
for (end in endings) {
P[[length(P) + 1]] <- c(populations[j], end)
}
}
}
return(P)
}

#' Four leaves graphs.
#'
#' Kind of obsolete since the introduction of \code{\link{all_graphs}}.
#' A comprehensive listing of all the \eqn{37} admixture graphs with four leaves and
#' at most two admixture events. Our convention is that the position of the root does
#' not matter (as long as it's not after an admixture event) and that graphs that have
#' \emph{eyes}, two inner nodes with the property that all the paths between any two
#' leaves visits both or neither of them, are excluded. The reason is that the \eqn{f}
#' statistics  can't detect the exact position of the root or distinguish between an
#' eye and a simple branch. The position of the root can be moved later with the function
#'
#' @format A list of functions on four leaves and a parameter \code{permutations} which
#'         is \code{FALSE} by default.
#'         The outputs of these functions are either single \code{\link{agraph}} objects
#'         with the input vector as leaves, or if \code{permutations} is \code{TRUE},
#'         lists of all the possible \code{\link{agraph}} objects with that leaf set up
#'         to symmetry.
#'
#' @family graphs
#'
#'
#' @examples
#' \donttest{
#' # While the usage of this function is pretty self-explanatory, let's plot all the graphs
#' # just for browsing.
#' for (i in seq(1, length(four_leaves_graphs))) {
#'   graph <- four_leaves_graphs[[i]](c("A", "B", "C", "D"))
#'   # This is how you include quotation marks in strings by the way:
#'   title <- paste("four_leaves_graphs[[", i, "]](c(\"A\", \"B\", \"C\", \"D\"))", sep = "")
#'   plot(graph, color = "tomato3", title = title)
#' }
#' }
#'
#' @export
four_leaves_graphs <- list(
# single tree
tree_1 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 3
leaf_permutations <- symmetry_4_VI(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge(leaves[1], "R"),
edge(leaves[2], "x"),
edge(leaves[3], "y"),
edge(leaves[4], "y")
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_1 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge(leaves[1], "R"),
edge(leaves[2], "y"),
edge(leaves[3], "M"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_2 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("y", "R"),
edge("z", "R"),
edge("w", "z"),
edge(leaves[1], "y"),
edge(leaves[2], "M"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_3 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 6
leaf_permutations <- symmetry_4_III(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("y", "R"),
edge("z", "R"),
edge("w", "M"),
edge(leaves[1], "y"),
edge(leaves[2], "w"),
edge(leaves[3], "w"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_1 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_2 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "w"),
edge(leaves[3], "N"),
edge(leaves[4], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_3 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "M"),
edge(leaves[1], "R"),
edge(leaves[2], "N"),
edge(leaves[3], "w"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_4 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "w"),
edge(leaves[4], "N"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_5 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "y"),
edge(leaves[3], "N"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_6 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "y"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_7 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_8 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "w"),
edge(leaves[4], "N"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_9 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "y"),
edge(leaves[3], "N"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_10 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "N"),
edge(leaves[3], "w"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_11 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "y"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "N"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_12 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "M"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "w"),
edge(leaves[4], "N"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_13 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 6
leaf_permutations <- symmetry_4_III(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("w", "y"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_14 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_15 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 24
leaf_permutations <- symmetry_4_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "y"),
edge(leaves[1], "R"),
edge(leaves[2], "w"),
edge(leaves[3], "M"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_16 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_V(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "y"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "w"),
edge(leaves[4], "N"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_17 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "M"),
edge(leaves[1], "x"),
edge(leaves[2], "w"),
edge(leaves[3], "N"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_18 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 6
leaf_permutations <- symmetry_4_III(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "y"),
edge(leaves[1], "R"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_19 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "w"),
edge(leaves[3], "N"),
edge(leaves[4], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_20 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "N"),
edge(leaves[1], "R"),
edge(leaves[2], "M"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_21 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 6
leaf_permutations <- symmetry_4_VIII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "N"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_22 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_V(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "N"),
edge(leaves[1], "x"),
edge(leaves[2], "w"),
edge(leaves[3], "w"),
edge(leaves[4], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_23 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "N"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_24 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "N"),
edge(leaves[3], "w"),
edge(leaves[4], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_25 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "y"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "N"),
edge(leaves[4], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_26 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_V(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "M"),
edge(leaves[1], "x"),
edge(leaves[2], "w"),
edge(leaves[3], "w"),
edge(leaves[4], "N"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_27 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_28 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_V(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "N"),
edge(leaves[1], "x"),
edge(leaves[2], "w"),
edge(leaves[3], "w"),
edge(leaves[4], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_29 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "N"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_30 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "N"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_31 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "w"),
edge(leaves[3], "N"),
edge(leaves[4], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_32 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "x"),
edge(leaves[1], "w"),
edge(leaves[2], "N"),
edge(leaves[3], "y"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_33 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 12
leaf_permutations <- symmetry_4_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "x"),
edge(leaves[1], "w"),
edge(leaves[2], "N"),
edge(leaves[3], "z"),
edge(leaves[4], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
}
)

symmetry_4_I <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
output <- rbind(output, candidate)
}
output <- output[-1, ]
output
}

symmetry_4_II <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[1] < num[4]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_III <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[1] < num[4] &&
num[2] < num[3]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_IV <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[3] < num[4]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_V <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[2] < num[3]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_VI <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[1] < num[2] &&
num[3] < num[4] &&
num[1] + 10*num[2] < num[3] + 10*num[4]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_VII <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[2] < num[4]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_VIII <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[1] < num[2] &&
num[3] < num[4]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

symmetry_4_IX <- function(leaves) {
output <- character(4)
all_permutations <- make_permutations(leaves)
for (candidate in all_permutations) {
sorted <- sort(candidate)
num <- numeric(0)
for (j in seq(1, 4)) {
num[j] <- match(candidate[j], sorted)
}
if (num[1] < num[3]) {
output <- rbind(output, candidate)
}
}
output <- output[-1, ]
output
}

#' Five leaves graphs.
#'
#' Kind of obsolete since the introduction of \code{\link{all_graphs}}.
#' A comprehensive listing of all the \eqn{132} admixture graphs with five leaves and
#' at most two admixture events. Our convention is that the position of the root does
#' not matter (as long as it's not after an admixture event) and that graphs that have
#' \emph{eyes}, two inner nodes with the property that all the paths between any two
#' leaves visits both or neither of them, are excluded. The reason is that the \eqn{f}
#' statistics can't detect the exact position of the root or distinguish between an eye
#' and a simple branch. The position of the root can be moved later with the function
#'
#' @format A list of functions on five leaves and a parameter \code{permutations} which
#'         is \code{FALSE} by default.
#'         The outputs of these functions are either single \code{\link{agraph}} objects
#'         with the input vector as leaves, or if \code{permutations} is \code{TRUE},
#'         lists of all the possible \code{\link{agraph}} objects with that leaf set up
#'         to symmetry.
#'
#' @family graphs
#'
#'
#' @examples
#' \donttest{
#' # While the usage of this function is pretty self-explanatory, let's plot all the graphs
#' # just for browsing.
#' for (i in seq(1, length(five_leaves_graphs))) {
#'   graph <- five_leaves_graphs[[i]](c("A", "B", "C", "D", "E"))
#'   # This is how you include quotation marks in strings by the way:
#'   title <- paste("five_leaves_graphs[[", i, "]](c(\"A\", \"B\", \"C\", \"D\", \"E\"))",
#'                  sep = "")
#'   plot(graph, color = "purple", title = title)
#' }
#' }
#'
#' @export
five_leaves_graphs <- list(
# tree
tree_1 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 15
leaf_permutations <- symmetry_5_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge(leaves[1], "R"),
edge(leaves[2], "x"),
edge(leaves[3], "y"),
edge(leaves[4], "z"),
edge(leaves[5], "z")
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_1 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "y"),
edge(leaves[3], "M"),
edge(leaves[4], "w"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_2 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "M"),
edge(leaves[1], "R"),
edge(leaves[2], "y"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_3 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_III(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "y"),
edge(leaves[3], "M"),
edge(leaves[4], "w"),
edge(leaves[5], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_4 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 15
leaf_permutations <- symmetry_5_IV(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("w", "y"),
edge(leaves[1], "z"),
edge(leaves[2], "z"),
edge(leaves[3], "M"),
edge(leaves[4], "w"),
edge(leaves[5], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_5 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_V(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "y"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "z"),
edge(leaves[4], "w"),
edge(leaves[5], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_6 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_VI(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_7 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_III(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("w", "z"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "z"),
edge(leaves[4], "w"),
edge(leaves[5], "w"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

one_admixture_8 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "w", "M")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("w", "R"),
edge(leaves[1], "M"),
edge(leaves[2], "y"),
edge(leaves[3], "w"),
edge(leaves[4], "w"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_1 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "N"),
edge(leaves[3], "v"),
edge(leaves[4], "y"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_2 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "u"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_3 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "z"),
edge("v", "z"),
edge(leaves[1], "u"),
edge(leaves[2], "x"),
edge(leaves[3], "M"),
edge(leaves[4], "N"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_4 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "N"),
edge(leaves[3], "v"),
edge(leaves[4], "u"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_5 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("u", "z"),
edge("v", "z"),
edge(leaves[1], "N"),
edge(leaves[2], "u"),
edge(leaves[3], "x"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_6 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "z"),
edge(leaves[2], "x"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_7 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "y"),
edge("v", "u"),
edge(leaves[1], "z"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_8 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("u", "y"),
edge("v", "u"),
edge(leaves[1], "z"),
edge(leaves[2], "x"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_9 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "v"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "N"),
edge(leaves[2], "z"),
edge(leaves[3], "x"),
edge(leaves[4], "y"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_10 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "N"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "v"),
edge(leaves[2], "z"),
edge(leaves[3], "x"),
edge(leaves[4], "y"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_11 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "z"),
edge("y", "x"),
edge("z", "R"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "y"),
edge(leaves[2], "M"),
edge(leaves[3], "R"),
edge(leaves[4], "N"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_12 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_13 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "z"),
edge("v", "y"),
edge(leaves[1], "x"),
edge(leaves[2], "u"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_14 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "z"),
edge("v", "M"),
edge(leaves[1], "x"),
edge(leaves[2], "v"),
edge(leaves[3], "N"),
edge(leaves[4], "z"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_15 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "v"),
edge(leaves[4], "N"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_16 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "x"),
edge("v", "u"),
edge(leaves[1], "z"),
edge(leaves[2], "M"),
edge(leaves[3], "v"),
edge(leaves[4], "N"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_17 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "x"),
edge("v", "y"),
edge(leaves[1], "z"),
edge(leaves[2], "M"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_18 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "u"),
edge(leaves[3], "v"),
edge(leaves[4], "N"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_19 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "z"),
edge("v", "M"),
edge(leaves[1], "x"),
edge(leaves[2], "u"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_20 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "N"),
edge(leaves[3], "v"),
edge(leaves[4], "u"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_21 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "y"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "N"),
edge(leaves[4], "u"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_22 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "y"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "z"),
edge(leaves[3], "M"),
edge(leaves[4], "N"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_23 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "v"),
edge("u", "y"),
edge("v", "u"),
edge(leaves[1], "x"),
edge(leaves[2], "M"),
edge(leaves[3], "z"),
edge(leaves[4], "N"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_24 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "z"),
edge(leaves[2], "u"),
edge(leaves[3], "v"),
edge(leaves[4], "N"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_25 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "z"),
edge("v", "M"),
edge(leaves[1], "z"),
edge(leaves[2], "u"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_26 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "z"),
edge(leaves[2], "N"),
edge(leaves[3], "v"),
edge(leaves[4], "u"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_27 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "M"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "N"),
edge(leaves[2], "v"),
edge(leaves[3], "u"),
edge(leaves[4], "z"),
edge(leaves[5], "y"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_28 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("u", "y"),
edge("v", "u"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_29 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("u", "z"),
edge("v", "M"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "N"),
edge(leaves[4], "v"),
edge(leaves[5], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_30 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("u", "z"),
edge("v", "z"),
edge(leaves[1], "R"),
edge(leaves[2], "v"),
edge(leaves[3], "N"),
edge(leaves[4], "M"),
edge(leaves[5], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_31 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("u", "z"),
edge("v", "M"),
edge(leaves[1], "v"),
edge(leaves[2], "u"),
edge(leaves[3], "N"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_32 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "v"),
edge(leaves[2], "x"),
edge(leaves[3], "N"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_33 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 120
leaf_permutations <- symmetry_5_VII(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "x"),
edge("u", "M"),
edge("v", "N"),
edge(leaves[1], "v"),
edge(leaves[2], "x"),
edge(leaves[3], "u"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_34 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("u", "y"),
edge("v", "M"),
edge(leaves[1], "R"),
edge(leaves[2], "N"),
edge(leaves[3], "v"),
edge(leaves[4], "u"),
edge(leaves[5], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_35 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "R"),
edge(leaves[2], "z"),
edge(leaves[3], "v"),
edge(leaves[4], "N"),
edge(leaves[5], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_36 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "y"),
edge("u", "z"),
edge("v", "u"),
edge(leaves[1], "R"),
edge(leaves[2], "N"),
edge(leaves[3], "v"),
edge(leaves[4], "M"),
edge(leaves[5], "x"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_37 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "y"),
edge("v", "N"),
edge(leaves[1], "v"),
edge(leaves[2], "x"),
edge(leaves[3], "M"),
edge(leaves[4], "z"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_38 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "M"),
edge("v", "u"),
edge(leaves[1], "v"),
edge(leaves[2], "x"),
edge(leaves[3], "N"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_39 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "z"),
edge("v", "N"),
edge(leaves[1], "v"),
edge(leaves[2], "x"),
edge(leaves[3], "u"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_40 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "R"),
edge("z", "y"),
edge("u", "x"),
edge("v", "N"),
edge(leaves[1], "v"),
edge(leaves[2], "x"),
edge(leaves[3], "z"),
edge(leaves[4], "y"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_41 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "x"),
edge("u", "z"),
edge("v", "N"),
edge(leaves[1], "v"),
edge(leaves[2], "z"),
edge(leaves[3], "u"),
edge(leaves[4], "M"),
edge(leaves[5], "v"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_42 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 30
leaf_permutations <- symmetry_5_II(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M", "N")
edges <- parent_edges(c(
edge("x", "R"),
edge("y", "x"),
edge("z", "M"),
edge("u", "y"),
edge("v", "R"),
edge(leaves[1], "N"),
edge(leaves[2], "z"),
edge(leaves[3], "u"),
edge(leaves[4], "v"),
edge(leaves[5], "z"),
))
))
result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)
}
if (permutations == FALSE) {result <- result[[1]]}
result
},

two_admixtures_43 <- function(leaves, permutations = FALSE) {
if (permutations == TRUE) {
P <- 60
leaf_permutations <- symmetry_5_I(leaves)
} else {
P <- 1
leaf_permutations <- rbind(leaves)
}
result <- vector(mode = "list", length = P)
for (j in seq(1, P)) {
leaves <- leaf_permutations[j, ]
inner_nodes <- c("R", "x", "y", "z", "u", "v", "M",