Skip to contents

as.Splits() converts a phylogenetic tree to a Splits object representing its constituent bipartition splits.

Usage

as.Splits(x, tipLabels = NULL, ...)

# S3 method for class 'phylo'
as.Splits(x, tipLabels = NULL, asSplits = TRUE, ...)

# S3 method for class 'multiPhylo'
as.Splits(x, tipLabels = unique(unlist(TipLabels(x))), asSplits = TRUE, ...)

# S3 method for class 'Splits'
as.Splits(x, tipLabels = NULL, ...)

# S3 method for class 'list'
as.Splits(x, tipLabels = NULL, asSplits = TRUE, ...)

# S3 method for class 'matrix'
as.Splits(x, tipLabels = NULL, ...)

# S3 method for class 'logical'
as.Splits(x, tipLabels = NULL, ...)

# S3 method for class 'character'
as.Splits(x, tipLabels = NULL, ...)

# S3 method for class 'Splits'
as.logical(x, tipLabels = attr(x, "tip.label"), ...)

Arguments

x

Object to convert into splits: perhaps a tree of class phylo. If a logical matrix is provided, each row will be considered as a separate split.

tipLabels

Character vector specifying sequence in which to order tip labels. Label order must (currently) match to combine or compare separate Splits objects.

...

Presently unused.

asSplits

Logical specifying whether to return a Splits object, or an unannotated two-dimensional array (useful where performance is paramount).

Value

as.Splits() returns an object of class Splits, or (if asSplits = FALSE) a two-dimensional array of raw objects, with each bit specifying whether or not the leaf corresponding to the respective bit position is a member of the split. Splits are named according to the node at the non-root end of the edge that defines them. In rooted trees, the child of the rightmost root edge names the split.

See also

Examples

splits <- as.Splits(BalancedTree(letters[1:6]))
summary(splits)
#> 3 bipartition splits dividing 6 tips, a .. f
#>      123456
#>  8   ***...
#>  9   **....
#>  11  ...**.
#> 
#>  Tip 1: a	 Tip 2: b	 Tip 3: c	 Tip 4: d	 Tip 5: e	
#>  Tip 6: f	
TipsInSplits(splits)
#>  8  9 11 
#>  3  2  2 
summary(!splits)
#> 3 bipartition splits dividing 6 tips, a .. f
#>      123456
#>  8   ...***
#>  9   ..****
#>  11  ***..*
#> 
#>  Tip 1: a	 Tip 2: b	 Tip 3: c	 Tip 4: d	 Tip 5: e	
#>  Tip 6: f	
TipsInSplits(!splits)
#>  8  9 11 
#>  3  4  4 

length(splits + !splits)
#> [1] 6
length(unique(splits + !splits))
#> [1] 3

summary(c(splits[[2:3]], !splits[[1:2]]))
#> 4 bipartition splits dividing 6 tips, a .. f
#>      123456
#>  9   **....
#>  11  ...**.
#>  8   ...***
#>  9   ..****
#> 
#>  Tip 1: a	 Tip 2: b	 Tip 3: c	 Tip 4: d	 Tip 5: e	
#>  Tip 6: f	

moreSplits <- as.Splits(PectinateTree(letters[6:1]), tipLabel = splits)
print(moreSplits, details = TRUE)
#> 3 bipartition splits dividing 6 tips, a .. f
#>      123456
#>  9   ****..
#>  10  ***...
#>  11  **....
match(splits, moreSplits)
#> [1]  2  3 NA
moreSplits %in% splits
#>     9    10    11 
#> FALSE  TRUE  TRUE 

as.Splits("....**", letters[1:6])
#> 1 bipartition split dividing 6 tips, a .. f