Constraints

class Constraints(taxNames, constraintTree=None, rooting=False)[source]

A container for tree topology constraints.

Constraints are defined with a partially-resolved tree. We can then use a constraints object to ask whether a query tree has those constraints. In addition a constrained rooting may be defined, and we can then ask whether a query tree is consistent with that rooting. So for example we can use this to enforce a bifurcating root in a fixed position, where the content of the two clades off the root is fixed, but where the topology within the two clades can vary. (Also possible with a biRoot’ed tree.)

Init args —

taxNames

A list of taxNames in the same order as in the data or alignment, and the same order as in other tree or trees objects.

constraintTree

A partially resolved tree object that describes the constraints. You need to include all the taxNames, but they do not need to be in a particular order.

rooting

(Boolean – False by default) A constraint tree can define the root (possibly with other constraints as well). If rooting is set, a biRooted constraint tree should be biRooted, and a triRooted constraint tree should be triRooted. You need to include all the taxNames.

For example, this will constrain A+C, without rooting, in a random biRoot’ed tree:

tNames = list("ABCDE")
cTree = func.readAndPop("((A, C), B, D, E);")
constr = Constraints(tNames, constraintTree=cTree, rooting=False)
t = func.randomTree(taxNames=tNames, constraints=constr, biRoot=True)

A biRooted cTree might be ((A,B,C),(D,E,F)); while a triRooted cTree might be (A,B,(C,D,E)); or ((A,B,C),(D,E,F),(G,H,I)); If you turn on rooting, then those rootings will be enforced.

Constraints can be nested, done with the constraintTree description, as for example (A,B,(C,D,(E,F),G)). You can have nested constraints when rooting is set.

You can pass a Constraints object to p4.func.randomTree() and to Mcmc() to enforce constraints.

areConsistentWithTree(aTree)[source]

Ask whether aTree is consistent with the constraints in self

It is the responsibility of the caller to aTree.makeSplitKeys()

Returns True or False

areConsistentWithTreeRoot(aTree)[source]

Ask if aTree root is consistent with constraints

Additionally checks whether the degree of the root (ie biRoot, triRoot, etc) of aTree is the same as self.cTree.

Returns True or False

dump()[source]

A summary