コード例 #1
0
 /*.................................................................................................................*/
 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");
   }
 }
コード例 #2
0
 /*.................................................................................................................*/
 public String getStringForTree(int ic) {
   if (treesBlock == null) return "";
   Tree tree = treesBlock.getTree(ic);
   if (tree == null) return "";
   if (tree.hasPolytomies(tree.getRoot())) return "Yes";
   else return "No";
 }
コード例 #3
0
ファイル: DepthFirst.java プロジェクト: nursh/SearchTree
  public DepthFirst() {

    myTree = new Tree();
    presentNode = myTree.getRoot();
    traversedNodes = new ArrayList<>();
    nodes = new LinkedList<>();
    nodes.add(presentNode);
  }
コード例 #4
0
 /**
  * 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;
   }
 }
コード例 #5
0
ファイル: Tester.java プロジェクト: liubonan/Interview_Java
  public static void out(Tree t) {
    Queue<Node> q = new LinkedList<Node>();
    q.add(t.getRoot());

    while (!q.isEmpty()) {
      Node pop = q.remove();
      if (pop.getLeft() != null) q.add(pop.getLeft());
      if (pop.getRight() != null) q.add(pop.getRight());
      System.out.println(pop.getData());
    }
  }
コード例 #6
0
ファイル: Tester.java プロジェクト: liubonan/Interview_Java
  public static void main(String[] args) {
    Tree t = new Tree();
    Node root = new Node(1);
    root.setLeft(new Node(2));
    root.setRight(new Node(3));
    root.getLeft().setLeft(new Node(4));
    root.getRight().setLeft(new Node(5));
    root.getRight().setRight(new Node(6));
    root.getRight().getRight().setRight(new Node(7));

    t.setRoot(root);
    out(t);
    System.out.println();
    t.reverse(t.getRoot());
    out(t);
  }