Beispiel #1
0
  private void writeNode(Tree tree, NodeRef node, boolean attributes, Map<String, Integer> idMap) {
    if (tree.isExternal(node)) {
      int k = node.getNumber() + 1;
      if (idMap != null) k = idMap.get(tree.getTaxonId(k - 1));

      out.print(k);
    } else {
      out.print("(");
      writeNode(tree, tree.getChild(node, 0), attributes, idMap);
      for (int i = 1; i < tree.getChildCount(node); i++) {
        out.print(",");
        writeNode(tree, tree.getChild(node, i), attributes, idMap);
      }
      out.print(")");
    }

    if (writeAttributesAs == AttributeType.BRANCH_ATTRIBUTES && !tree.isRoot(node)) {
      out.print(":");
    }

    if (attributes) {
      Iterator<?> iter = tree.getNodeAttributeNames(node);
      if (iter != null) {
        boolean first = true;
        while (iter.hasNext()) {
          if (first) {
            out.print("[&");
            first = false;
          } else {
            out.print(",");
          }
          String name = (String) iter.next();
          out.print(name + "=");
          Object value = tree.getNodeAttribute(node, name);
          printValue(value);
        }
        out.print("]");
      }
    }

    if (writeAttributesAs == AttributeType.NODE_ATTRIBUTES && !tree.isRoot(node)) {
      out.print(":");
    }

    if (!tree.isRoot(node)) {
      double length = tree.getBranchLength(node);
      if (formatter != null) {
        out.print(formatter.format(length));
      } else {
        out.print(length);
      }
    }
  }
  /** Calculates the actual rates corresponding to the category indices. */
  protected void setupRates() {

    // System.out.println("BRRRTTZZZ " + distributionIndexParameter.getValue(0));
    for (int i = 0; i < tree.getNodeCount(); i++) {
      // rates[i] = distributionModel.quantile(rateCategoryQuantiles.getNodeValue(
      // rateCategoryQuantiles.getTreeModel(), rateCategoryQuantiles.getTreeModel().getNode(i) ));
      if (!tree.isRoot(tree.getNode(i))) {

        if (useQuantilesForRates) {
            /* Using quantiles to represent rates */
          rates[tree.getNode(i).getNumber()] =
              distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].quantile(
                  rateCategoryQuantiles.getNodeValue(tree, tree.getNode(i)));
        } else {
            /* Not using quantiles to represent rates. This is practically useless for anything else other than simulation */
          rates[tree.getNode(i).getNumber()] =
              rateCategoryQuantiles.getNodeValue(tree, tree.getNode(i));
        }
      }
    }
    /*System.out.print(distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].getClass().getName() + "\t" + (int) Math.round(distributionIndexParameter.getValue(0)) + "\t" + rates[1] + "\t" + rateCategoryQuantiles.getNodeValue(tree, tree.getNode(1)));// + "\t" + distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].);
    if(distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].getClass().getName().equals("dr.inference.distribution.LogNormalDistributionModel")) {
        LogNormalDistributionModel lndm = (LogNormalDistributionModel) distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))];
        System.out.println("\t" + lndm.getS());
    }
    else if (distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].getClass().getName().equals("dr.inference.distribution.InverseGaussianDistributionModel")) {
        InverseGaussianDistributionModel lndm = (InverseGaussianDistributionModel) distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))];
        System.out.println("\t" + lndm.getS());
    }*/
    if (normalize) computeFactor();
  }
 @Override
 public int getSibling(int i) {
   NodeRef n = tree.getNode(i);
   if (tree.isRoot(n)) return RootedTree.NULL;
   NodeRef p = tree.getParent(n);
   int c1 = tree.getChild(p, 0).getNumber();
   int c2 = tree.getChild(p, 1).getNumber();
   return n.getNumber() == c2 ? c1 : c2;
 }
  double calculateNorm(Tree tree) {

    double time = 0.0;
    double rateTime = 0.0;
    for (int i = 0; i < tree.getNodeCount(); i++) {

      NodeRef node = tree.getNode(i);

      if (!tree.isRoot(node)) {

        double branchTime = tree.getBranchLength(node);

        rateTime += getRawBranchRate(tree, node) * branchTime;
        time += branchTime;
      }
    }
    return rateTime / time;
  }
Beispiel #5
0
  public double[] getSummaryStatistic(Tree tree) {

    double externalLength = 0.0;
    double internalLength = 0.0;

    int externalNodeCount = tree.getExternalNodeCount();
    for (int i = 0; i < externalNodeCount; i++) {
      NodeRef node = tree.getExternalNode(i);
      externalLength += tree.getBranchLength(node);
    }

    int internalNodeCount = tree.getInternalNodeCount();
    for (int i = 0; i < internalNodeCount; i++) {
      NodeRef node = tree.getInternalNode(i);
      if (!tree.isRoot(node)) {
        internalLength += tree.getBranchLength(node);
      }
    }
    return new double[] {internalLength + externalLength};
  }
 @Override
 public boolean isRoot(int i) {
   return tree.isRoot(tree.getNode(i));
 }
 public double getBranchRate(final Tree tree, final NodeRef node) {
   assert !tree.isRoot(node) : "root node doesn't have a rate!";
   // int rateCategory = (int) Math.round(rateCategories.getNodeValue(tree, node));
   return rates[node.getNumber()] * scaleFactor;
 }