+### The next function transforms an object of class "prop.part" so
+### that the vectors which are identical in terms of split are aggregated.
+### For instance if n = 5 tips, 1:2 and 3:5 actually represent the same
+### split though they are different clades. The aggregation is done
+### arbitrarily. The call to ONEwise() insures that all splits include
+### the first tip.
+postprocess.prop.part <- function(x)
+{
+ n <- length(x[[1]])
+ N <- length(x)
+ w <- attr(x, "number")
+
+ drop <- logical(N)
+ V <- numeric(n)
+ for (i in 2:(N - 1)) {
+ if (drop[i]) next
+ A <- x[[i]]
+ for (j in (i + 1):N) {
+ if (drop[j]) next
+ B <- x[[j]]
+ if (length(A) + length(B) != n) next
+ V[] <- 0L
+ V[A] <- 1L
+ V[B] <- 1L
+ if (all(V == 1L)) {
+ drop[j] <- TRUE
+ w[i] <- w[i] + w[j]
+ }
+ }
+ }
+ if (any(drop)) {
+ labels <- attr(x, "labels")
+ x <- x[!drop]
+ w <- w[!drop]
+ attr(x, "number") <- w
+ attr(x, "labels") <- labels
+ class(x) <- "prop.part"
+ }
+ ONEwise(x)
+}
+
+### This function changes an object of class "prop.part" so that they
+### all include the first tip. For instance if n = 5 tips, 3:5 is
+### changed to 1:2.
+ONEwise <- function(x)
+{
+ n <- length(x[[1L]])
+ v <- 1:n
+ for (i in 2:length(x)) {
+ y <- x[[i]]
+ if (y[1] != 1) x[[i]] <- v[-y]
+ }
+ x
+}
+