R: Force a tree to match a constraint

ImposeConstraint {TreeTools} | R Documentation

## Force a tree to match a constraint

### Description

Modify a tree such that it matches a specified constraint. This is at present a somewhat crude implementation that attempts to retain much of the structure of `tree` whilst guaranteeing compatibility with each entry in `constraint`.

### Usage

    ImposeConstraint(tree, constraint)

    AddUnconstrained(constraint, toAdd, asPhyDat = TRUE)

### Arguments

`tree` | A tree of class `phylo`.
`constraint` | An object of class `phyDat`; returned trees will be perfectly compatible with each character in `constraint`. See vignette for further examples.
`toAdd` | Character vector specifying taxa to add to constraint.
`asPhyDat` | Logical: if `TRUE`, return a `phyDat` object; if `FALSE`, return a matrix.

### Value

`ImposeConstraint()` returns a tree of class `phylo`, consistent with `constraint`.

### Functions

- `AddUnconstrained`: Expand a constraint to include unconstrained taxa.

### Author(s)

Martin R. Smith (martin.smith@durham.ac.uk)

### See Also

Other tree manipulation: `AddTip()`, `CollapseNode()`, `ConsensusWithout()`, `DropTip()`, `EnforceOutgroup()`, `KeptPaths()`, `KeptVerts()`, `LeafLabelInterchange()`, `MakeTreeBinary()`, `RenumberTips()`, `RenumberTree()`, `Renumber()`, `RootTree()`, `SingleTaxonTree()`, `SortTree()`, `Subtree()`

### Examples

    tips <- letters[1:9]
    tree <- as.phylo(1, 9, tips)
    plot(tree)

    constraint <- StringToPhyDat('0000?1111 000111111 0000??110', tips, FALSE)
    plot(ImposeConstraint(tree, constraint))

[Package TreeTools version 1.7.0 Index]