/** * Returns a new object indicating the states at the tips (used whether or not History is * reconstruction) */ public CharacterDistribution getStatesAtTips(Tree tree) { if (observedStates != null) return (CharacterDistribution) observedStates.getAdjustableClone(); else { ContinuousAdjustable d = new ContinuousAdjustable(tree.getTaxa(), tree.getTaxa().getNumTaxa()); d.setItemsAs(this); fillDistribution(tree, tree.getRoot(), d); return d; } }
/*.................................................................................................................*/ public void modifyTree(Tree tree, MesquiteTree modified, RandomBetween rng) { if (tree == null || modified == null) return; if (tree.getTaxa().anySelected()) { // error fixed in 1. 12 int[] terminals = tree.getTerminalTaxa(tree.getRoot()); if (terminals == null) return; int numTerminals = 0; for (int i = 0; i < terminals.length; i++) if (tree.getTaxa().getSelected(terminals[i])) numTerminals++; if (numTerminals > numExcluded) { int[] selTerminals = new int[numTerminals]; int icount = 0; for (int i = 0; i < terminals.length; i++) if (tree.getTaxa().getSelected(terminals[i])) { selTerminals[icount] = terminals[i]; icount++; } terminals = selTerminals; for (int it = 0; it < numExcluded; it++) { int taxon = -1; int count = 0; int ntries = 100000; while (terminals[taxon = rng.randomIntBetween(0, numTerminals - 1)] < 0 && count < ntries) { count++; } if (count >= ntries) discreetAlert( "ERROR: Rarefy tree failed to find taxon to delete in " + ntries + " tries."); else { int nT = modified.nodeOfTaxonNumber(terminals[taxon]); modified.deleteClade(nT, false); terminals[taxon] = -1; } } } else MesquiteMessage.warnUser( "Sorry, the tree could not be rarefied because more taxa are to be excluded than those available"); } else { int numTerminals = tree.numberOfTerminalsInClade(tree.getRoot()); if (numTerminals > numExcluded) { for (int it = 0; it < numExcluded; it++) { int taxon = rng.randomIntBetween(0, numTerminals - it - 1); int nT = modified.getTerminalNode(modified.getRoot(), taxon); modified.deleteClade(nT, false); } } else MesquiteMessage.warnUser( "Sorry, the tree could not be rarefied because more taxa are to be excluded than those available"); } }
/** * This readjust procedure can be called to readjust the size of storage of states of a character * for nodes. */ public CharacterHistory adjustSize(Tree tree) { if (tree.getNumNodeSpaces() == this.getNumNodes()) return this; else { ContinuousHistory soc = new ContinuousHistory( tree.getTaxa(), tree.getNumNodeSpaces(), (ContinuousData) getParentData()); soc.setItemsAs(this); soc.setParentData(getParentData()); soc.setParentCharacter(getParentCharacter()); ((CharacterStates) soc).setExplanation(getExplanation()); return soc; } }
/*.................................................................................................................*/ public void calculateNumber( Tree tree1, Tree tree2, MesquiteNumber result, MesquiteString resultString) { if (result == null) return; clearResultAndLastResult(result); if (tree1 == null) return; if (tree2 == null) return; int numTaxa = tree1.getTaxa().getNumTaxa(); double[][] patristic1 = null; patristic1 = p1.calculatePatristic( tree1, numTaxa, patristic1); // for this tree calculate patristic distances (number of nodes separating // terminals; no branch lengths) double[][] patristic2 = null; patristic2 = p2.calculatePatristic( tree2, numTaxa, patristic2); // for this tree calculate patristic distances (number of nodes separating // terminals; no branch lengths) double correl = offDiagonalPMCorrelationFILTERED(patristic1, patristic2); if (isDistance && (MesquiteDouble.isCombinable(correl))) correl = -correl + 1.0; // shifting 1 to -1 to be 0 to 2 to act as distance result.setValue(correl); if (resultString != null) { if (isDistance) resultString.setValue( "Patristic correlation (converted to distance): " + result.toString()); else resultString.setValue("Patristic correlation: " + result.toString()); } saveLastResult(result); saveLastResultString(resultString); }
/** gets the current matrix. */ public CharacterDistribution getCurrentCharacter(Tree tree) { if (tree == null) return null; else return getCurrentCharacter(tree.getTaxa()); }
/* -- the following are a preliminary attempt to allow matrix sources to know exactly what tree the matrix will be used with. These can be overridden by modules to do simulations on the trees, or to see if there is a simulated matrix attached to the tree, or what ---*/ public void initialize(Tree tree) { if (tree == null) return; else initialize(tree.getTaxa()); }
@Override public Set<Taxon> getTaxa() { return source.getTaxa(); }