コード例 #1
0
  /**
   * Simulates a coalescent tree from a set of subtrees.
   *
   * @param subtrees an array of tree to be used as subtrees
   * @param model the demographic model to use
   * @param rootHeight an optional root height with which to scale the whole tree
   * @param preserveSubtrees true of subtrees should be preserved
   * @return a simulated coalescent tree
   */
  public SimpleTree simulateTree(
      Tree[] subtrees, DemographicModel model, double rootHeight, boolean preserveSubtrees) {

    SimpleNode[] roots = new SimpleNode[subtrees.length];
    SimpleTree tree;

    for (int i = 0; i < roots.length; i++) {
      roots[i] = new SimpleNode(subtrees[i], subtrees[i].getRoot());
    }

    // if just one taxonList then finished
    if (roots.length == 1) {
      tree = new SimpleTree(roots[0]);
    } else {
      tree = new SimpleTree(simulator.simulateCoalescent(roots, model.getDemographicFunction()));
    }

    if (!Double.isNaN(rootHeight) && rootHeight > 0.0) {
      if (preserveSubtrees) {
        limitNodes(tree, rootHeight - 1e-12);
        tree.setRootHeight(rootHeight);
      } else {
        attemptToScaleTree(tree, rootHeight);
      }
    }

    return tree;
  }
コード例 #2
0
 /**
  * Simulates a coalescent tree, given a taxon list.
  *
  * @param taxa the set of taxa to simulate a coalescent tree between
  * @param model the demographic model to use
  * @return a simulated coalescent tree
  */
 public SimpleTree simulateTree(TaxonList taxa, DemographicModel model) {
   return simulator.simulateTree(taxa, model.getDemographicFunction());
 }