R/propose.R

Defines functions vector_to_graph graph_to_vector try_to_add all_graphs remove_duplicates canonise_graph rename_nodes invent_name load_admixture_information save_admixture_information flow root_graph break_graph make_an_outgroup add_an_admixture2 add_an_admixture add_a_leaf fit_graph_list fit_permutations_and_graphs symmetry_8_IV symmetry_8_III symmetry_8_II symmetry_8_I symmetry_7_V symmetry_7_IV symmetry_7_III symmetry_7_II symmetry_7_I symmetry_6_XVIII symmetry_6_XVII symmetry_6_XVI symmetry_6_XV symmetry_6_XIV symmetry_6_XIII symmetry_6_XII symmetry_6_XI symmetry_6_X symmetry_6_IX symmetry_6_VIII symmetry_6_VII symmetry_6_VI symmetry_6_V symmetry_6_IV symmetry_6_III symmetry_6_II symmetry_6_I symmetry_5_VII symmetry_5_VI symmetry_5_V symmetry_5_IV symmetry_5_III symmetry_5_II symmetry_5_I symmetry_4_IX symmetry_4_VIII symmetry_4_VII symmetry_4_VI symmetry_4_V symmetry_4_IV symmetry_4_III symmetry_4_II symmetry_4_I make_permutations

Documented in add_a_leaf add_an_admixture add_an_admixture2 all_graphs canonise_graph fit_graph_list fit_permutations_and_graphs graph_to_vector make_an_outgroup make_permutations remove_duplicates rename_nodes vector_to_graph

#' 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}.
#'
#' @seealso \code{\link{four_leaves_graphs}}
#' @seealso \code{\link{five_leaves_graphs}}
#' @seealso \code{\link{six_leaves_graphs}}
#' @seealso \code{\link{seven_leaves_trees}}
#' @seealso \code{\link{eight_leaves_trees}}
#' @seealso \code{\link{fit_permutations_and_graphs}}
#' @seealso \code{\link{add_a_leaf}}
#' @seealso \code{\link{add_an_admixture}}
#' @seealso \code{\link{add_an_admixture2}}
#'
#' @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
#' \code{\link{make_an_outgroup}}.
#' 
#' @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
#' 
#' @seealso \code{\link{all_graphs}}
#' @seealso \code{\link{make_permutations}}
#' @seealso \code{\link{fit_permutations_and_graphs}}
#' @seealso \code{\link{fit_graph_list}}
#' @seealso \code{\link{add_a_leaf}}
#' @seealso \code{\link{add_an_admixture}}
#' @seealso \code{\link{add_an_admixture2}}
#' @seealso \code{\link{make_an_outgroup}}
#'
#' @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")
      ))
      admixtures <- NULL
      result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)  
    }
    if (permutations == FALSE) {result <- result[[1]]}
    result
  },

  # one admixture event
  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"),
        admixture_edge("M", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a")
      ))
      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"),
        admixture_edge("M", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a")
      ))
      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"),
        admixture_edge("M", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a")
      ))
      result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)  
    }
    if (permutations == FALSE) {result <- result[[1]]}
    result
  },
  
  # two admixture events
  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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "w", "b")
      ))
      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"),
        admixture_edge("M", "y", "z"),
        admixture_edge("N", "y", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a"),
        admix_props("N", "y", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "w", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "w", "y", "b")
      ))
      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"),
        admixture_edge("M", "y", "z"),
        admixture_edge("N", "M", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a"),
        admix_props("N", "M", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "z", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "z", "w", "b")
      ))
      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"),
        admixture_edge("M", "z", "w"),
        admixture_edge("N", "w", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "w", "a"),
        admix_props("N", "w", "y", "b")
      ))
      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"),
        admixture_edge("M", "x", "w"),
        admixture_edge("N", "z", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "w", "a"),
        admix_props("N", "z", "y", "b")
      ))
      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"),
        admixture_edge("M", "y", "w"),
        admixture_edge("N", "M", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "w", "a"),
        admix_props("N", "M", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "M", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "M", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "w", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "w", "y", "b")
      ))
      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"),
        admixture_edge("M", "z", "w"),
        admixture_edge("N", "z", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "w", "a"),
        admix_props("N", "z", "w", "b")
      ))
      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"),
        admixture_edge("M", "y", "z"),
        admixture_edge("N", "y", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a"),
        admix_props("N", "y", "w", "b")
      ))
      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"),
        admixture_edge("M", "y", "N"),
        admixture_edge("N", "w", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "N", "a"),
        admix_props("N", "w", "z", "b")
      ))
      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"),
        admixture_edge("M", "z", "w"),
        admixture_edge("N", "M", "x")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "w", "a"),
        admix_props("N", "M", "x", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "w", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "w", "y", "b")
      ))
      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"),
        admixture_edge("M", "z", "w"),
        admixture_edge("N", "z", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "w", "a"),
        admix_props("N", "z", "w", "b")
      ))
      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"),
        admixture_edge("M", "w", "y"),
        admixture_edge("N", "z", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "w", "y", "a"),
        admix_props("N", "z", "M", "b")
      ))
      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"),
        admixture_edge("M", "y", "z"),
        admixture_edge("N", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a"),
        admix_props("N", "y", "z", "b")
      ))
      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"),
        admixture_edge("M", "z", "x"),
        admixture_edge("N", "y", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "x", "a"),
        admix_props("N", "y", "M", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "M", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "M", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "y", "z", "b")
      ))
      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"),
        admixture_edge("M", "y", "z"),
        admixture_edge("N", "M", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a"),
        admix_props("N", "M", "w", "b")
      ))
      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"),
        admixture_edge("M", "z", "w"),
        admixture_edge("N", "M", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "w", "a"),
        admix_props("N", "M", "w", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "z", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "z", "y", "b")
      ))
      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"),
        admixture_edge("M", "y", "w"),
        admixture_edge("N", "w", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "w", "a"),
        admix_props("N", "w", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "M", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "M", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "y", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "y", "b")
      ))
      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"),
        admixture_edge("M", "w", "z"),
        admixture_edge("N", "M", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "w", "z", "a"),
        admix_props("N", "M", "y", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "M", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "M", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "y", "z", "b")
      ))
      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
#' \code{\link{make_an_outgroup}}.
#' 
#' @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
#' 
#' @seealso \code{\link{all_graphs}}
#' @seealso \code{\link{make_permutations}}
#' @seealso \code{\link{fit_permutations_and_graphs}}
#' @seealso \code{\link{fit_graph_list}}
#' @seealso \code{\link{add_a_leaf}}
#' @seealso \code{\link{add_an_admixture}}
#' @seealso \code{\link{add_an_admixture2}}
#' @seealso \code{\link{make_an_outgroup}}
#'
#' @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")
      ))
      admixtures <- NULL
      result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)  
    }
    if (permutations == FALSE) {result <- result[[1]]}
    result
  },
  
  # one admixture
  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"),
        admixture_edge("M", "y", "w")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "w", "a")
      ))
      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"),
        admixture_edge("M", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a")
      ))
      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"),
        admixture_edge("M", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a")
      ))
      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"),
        admixture_edge("M", "x", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a")
      ))
      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"),
        admixture_edge("M", "x", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a")
      ))
      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"),
        admixture_edge("M", "x", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a")
      ))
      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"),
        admixture_edge("M", "x", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a")
      ))
      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"),
        admixture_edge("M", "y", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "y", "z", "a")
      ))
      result[[j]] <- agraph(leaves, inner_nodes, edges, admixtures)  
    }
    if (permutations == FALSE) {result <- result[[1]]}
    result
  },
  
  # two admixtures
  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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "z", "v"),
        admixture_edge("N", "u", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "v", "a"),
        admix_props("N", "u", "M", "b")
      ))
      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"),
        admixture_edge("M", "x", "u"),
        admixture_edge("N", "v", "u")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "u", "a"),
        admix_props("N", "v", "u", "b")
      ))
      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"),
        admixture_edge("M", "x", "u"),
        admixture_edge("N", "v", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "u", "a"),
        admix_props("N", "v", "z", "b")
      ))
      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"),
        admixture_edge("M", "z", "u"),
        admixture_edge("N", "v", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "u", "a"),
        admix_props("N", "v", "y", "b")
      ))
      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"),
        admixture_edge("M", "z", "u"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "u", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "z", "y"),
        admixture_edge("N", "v", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "y", "a"),
        admix_props("N", "v", "M", "b")
      ))
      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"),
        admixture_edge("M", "z", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "z", "y"),
        admixture_edge("N", "z", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "y", "a"),
        admix_props("N", "z", "v", "b")
      ))
      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"),
        admixture_edge("M", "z", "v"),
        admixture_edge("N", "M", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "v", "a"),
        admix_props("N", "M", "v", "b")
      ))
      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"),
        admixture_edge("M", "z", "v"),
        admixture_edge("N", "v", "u")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "v", "a"),
        admix_props("N", "v", "u", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "v", "u")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "v", "u", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "v", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "v", "M", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "z", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "z", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "y"),
        admixture_edge("N", "x", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "y", "a"),
        admix_props("N", "x", "v", "b")
      ))
      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"),
        admixture_edge("M", "z", "u"),
        admixture_edge("N", "M", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "u", "a"),
        admix_props("N", "M", "v", "b")
      ))
      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"),
        admixture_edge("M", "u", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "u", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "u", "y"),
        admixture_edge("N", "u", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "u", "y", "a"),
        admix_props("N", "u", "v", "b")
      ))
      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"),
        admixture_edge("M", "R", "u"),
        admixture_edge("N", "z", "y")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "R", "u", "a"),
        admix_props("N", "z", "y", "b")
      ))
      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"),
        admixture_edge("M", "z", "y"),
        admixture_edge("N", "u", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "y", "a"),
        admix_props("N", "u", "M", "b")
      ))
      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"),
        admixture_edge("M", "z", "y"),
        admixture_edge("N", "z", "u")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "y", "a"),
        admix_props("N", "z", "u", "b")
      ))
      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"),
        admixture_edge("M", "z", "u"),
        admixture_edge("N", "z", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "z", "u", "a"),
        admix_props("N", "z", "v", "b")
      ))
      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"),
        admixture_edge("M", "u", "y"),
        admixture_edge("N", "v", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "u", "y", "a"),
        admix_props("N", "v", "M", "b")
      ))
      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"),
        admixture_edge("M", "u", "y"),
        admixture_edge("N", "z", "v")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "u", "y", "a"),
        admix_props("N", "z", "v", "b")
      ))
      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"),
        admixture_edge("M", "x", "u"),
        admixture_edge("N", "u", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "u", "a"),
        admix_props("N", "u", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "u", "z")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "u", "z", "b")
      ))
      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"),
        admixture_edge("M", "x", "z"),
        admixture_edge("N", "u", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "x", "z", "a"),
        admix_props("N", "u", "M", "b")
      ))
      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"),
        admixture_edge("M", "u", "z"),
        admixture_edge("N", "u", "M")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "u", "z", "a"),
        admix_props("N", "u", "M", "b")
      ))
      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"),
        admixture_edge("M", "u", "y"),
        admixture_edge("N", "y", "R")
      ))
      admixtures <- admixture_proportions(c(
        admix_props("M", "u", "y", "a"),
        admix_props("N", "y", "R", "b")
      ))
      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