Trees

class Trees(trees=None, taxNames=[])

A bunch of trees, all with the same taxNames.

This class would be good for doing things that you might want to do with a bunch of trees rather than just a single tree. For example, you might want to write out the trees to a nexus file but use a translation to keep the size of the file down – this class knows how to do that.

You can start this up in two ways:

tt = Trees()           # All the trees in var.trees
tt = Trees(myTreeList) # All the trees in myTreeList

This class insists on knowing the taxNames. If the list of taxNames is provided when you instantiate a Trees object, then it uses that list. (A good place to get such a list might be an alignment object, as myAlignment.taxNames).

tt = Trees(taxNames=myTaxNamesList)

Otherwise it looks for a taxNames attribute in the first tree.

checkTaxNames()

Check that all trees have all taxNames.

consel(rankByInputOrder=False, clobber=False, quiet=1, tidy=1, returnResults=False)

Use Shimo’s consel programs to compare trees.

The trees in self should all be optimized, and all should have models attached.

Self, the Trees object, should have a Data object attached, as self.data.

The default is to rank the output by support. You might rather have the output be in the same order as the input. Which output format is determined by the ‘rankByInputOrder’ arg.

The analysis produces various files. Whether they are overwritten if they already exist is controlled by the arg ‘clobber’. The default is to refuse to overwrite.

The consel programs produce lots of informative rubbish on the screen. Setting ‘quiet=1’ or ‘quiet=True’, (the default) sends that output to the bit bucket. The output of consel is a table, and that table is output to the screen, unless you set ‘quiet=2’, in which case it is not output to the screen.

The ‘tidy’ arg says whether to delete intermediate files, including consel_out.ci, consel_out.pv, consel_out.rmt, consel_out.vt, and the site likelihoods ‘sitelh’ file. By default it is ‘tidy=1’, (equivalent to ‘tidy=True’), meaning delete them. If you set ‘tidy=2’ then even the ouput file ‘conselOut’ is deleted.

Usually the results table will be printed to the screen (unless quiet=2), and also put in a file ‘conselOut’ (unless tidy=2), and nothing is returned. If you want the numbers, set returnResults=True, and then this method will return a list of tuples of strings of the results table contents.

dump()

Print summary info about self.

getTreesWithSplit(someTaxa)

Return a list of trees that have a split.

The arg someTaxa is a list of taxNames that define the split that you are looking for. It returns a list, not a Trees object. (If no trees are found, it returns an empty list.)

inputTreesToSuperTreeDistances(inputTrees, latex=False)

Make a table of supertree distances.

See the method Tree.Tree.inputTreesToSuperTreeDistances(), which gives supertree distances from a set of input trees to a single Tree. This Trees method does the same for a bunch of trees, outputting the results in a table.

And it returns the results as a list of lists as well.

nTax
rell(bootCount=10000, seedIsPid=1)

This compares several trees by the RELL method.

The trees in self should all be optimized, and all should have models attached.

Self, the Trees object, should have a Data object attached, as self.data.

Calculations are done in C, so it is fast. It uses the gsl random number generator. Setting the seedIsPid (ie turning it on) is appropriate, and is the default.

setTaxNames(theTaxNames=None)

Sets and checks taxNames for self and all trees in self.

You can provide the taxNames as the arg theTaxNames, or if you do not then it looks for a taxNames list in the first tree. If it does not find one there, it makes a list from the first tree, and sorts it.

This propagates self.taxNames to all trees in self.trees, and then calls self.checkTaxNames().

topologyDistanceMatrix(metric='sd')

Returns a DistanceMatrix object showing topology distances.

Uses the Tree.Tree.topologyDistance() method to compare trees. That method returns distances between pairs of trees, and this method simply collates those distances into a DistanceMatrix.DistanceMatrix object, which is returned.

See Tree.Tree.topologyDistance() for an explanation of the different metrics. The metrics are given in var.topologyDistanceMetrics

trackSplitsFromTree(theTree, windowSize=200, stride=100, fName='trackSplitsOut.py')

See how slits from theTree changes over the trees in self.

This looks at how some splits change over the trees in self (self is a Trees object). The splits that are tracked are the ones in the arg theTree. If you only wanted to track one split, you could supply such a tree with only that one split.

It uses a moving window, given by the windowSize arg. The stride is the distance between centers of the windows. So in the default, with windowSize=200 and stride=100, the first trees looked at will be from 0–199, and the second window will be from 100 – 299. Note that because the stride is less than the windowSize, there are overlapping windows.

The output is to a python file, which you can examine or plot later.

treeProbabilities(writeNexus=False)

Order the trees in self by frequency of occurrence.

This provides a posterior probability for the tree topology if trees are sampled from an MCMC. The tree with the highest number of occurrences is the MAP tree.

If writeNexus is True a Nexus tree file called treeProbabilities.nex is written with tree posterior probabilities as weights. If that file exists, it will be silently over-written!

The tree probs list of lists is returned.

(Thanks to Cymon Cox for this method.)

writeNewick(fName='intree')

Write out the list of trees in Newick format.

Good for phylip and puzzle. Long names are not modified, which might get you into trouble.

writeNexus(fName=None, append=0, withTranslation=0, writeTaxaBlock=1, likeMcmc=0)

Write the trees out in NEXUS format, in a trees block.

If fName is None, the default, it is written to sys.stdout.

#NEXUS is written unless we are append-ing.