/** * creates a clade system from a tree (using a pre-specified order of sequences) * * @param idGroup sequence order for the matrix * @param tree */ public static CladeSystem getClades(IdGroup idGroup, Tree tree) { tree.createNodeList(); int size = tree.getInternalNodeCount() - 1; CladeSystem cladeSystem = new CladeSystem(idGroup, size); boolean[][] clades = cladeSystem.getCladeArray(); for (int i = 0; i < size; i++) { getClade(idGroup, tree.getInternalNode(i), clades[i]); } return cladeSystem; }
public static void calculateCladeProbabilities(Tree tree, CladeSystem[] cladeSystems) { CladeSystem cladeSystem = getClades(cladeSystems[0].getIdGroup(), tree); for (int i = 0; i < tree.getInternalNodeCount() - 1; i++) { Node node = tree.getInternalNode(i); boolean[] clade = cladeSystem.getClade(i); if (node.isRoot()) throw new RuntimeException("Root node does not have clade probability!"); int cladeCount = 0; for (int j = 0; j < cladeSystems.length; j++) { if (cladeSystems[j].hasClade(clade)) cladeCount += 1; } double pr = (double) cladeCount / (double) cladeSystems.length; tree.setAttribute(node, AttributeNode.CLADE_PROBABILITY, new Double(pr)); } }