Debian Codegraph @

src/dr/app/beauti/options/TreeModelOptions.java

raw symbols SCIP
1 /*
2 * TreeModelOptions.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beauti.options;
27
28
29 import dr.app.beauti.types.PriorType;
30 import dr.evolution.util.Taxa;
31
32 import java.util.List;
33
34
35 /**
36 * @author Alexei Drummond
37 * @author Andrew Rambaut
38 * @author Walter Xie
39 * @version $Id$
40 */
41 public class TreeModelOptions extends ModelOptions {
42 private static final long serialVersionUID = 5328826852511460749L;
43
44 // Instance variables
45 private final BeautiOptions options;
46
47
48 public TreeModelOptions(BeautiOptions options) {
49 this.options = options;
50
51 initModelParametersAndOpererators();
52 }
53
54 @Override
55 public void initModelParametersAndOpererators() {
56
57 }
58
59 @Override
60 public List<Parameter> selectParameters(List<Parameter> params) {
61 return params;
62 }
63
64 @Override
65 public List<Operator> selectOperators(List<Operator> ops) {
66 return ops;
67 }
68
69 @Override
70 public String getPrefix() {
71 return null;
72 }
73
74 public double getExpectedAvgBranchLength(double rootHeight) {
75 double sum = 0;
76 int taxonCount = options.taxonList.getTaxonCount();
77
78 for (int i = 2; i <= taxonCount; i++) {
79 sum += (double) 1 / i;
80 }
81
82 return rootHeight * sum / (double) (2 * taxonCount - 2);
83 }
84
85 public int isNodeCalibrated(PartitionTreeModel treeModel) {
86 if (treeModel == null) {
87 return -1;
88 }
89 if (isNodeCalibrated(treeModel.getParameter("treeModel.rootHeight"))) {
90 return 0; // root node
91 } else if (options.getKeysFromValue(options.taxonSetsTreeModel, treeModel).size() > 0) {
92 Taxa taxonSet = (Taxa) options.getKeysFromValue(options.taxonSetsTreeModel, treeModel).get(0);
93 Parameter tmrca = options.statistics.get(taxonSet);
94 if (tmrca != null && isNodeCalibrated(tmrca)) {
95 return 1; // internal node (tmrca) with a proper prior
96 }
97 return -1;
98 } else {
99 return -1;
100 }
101 }
102
103 public boolean isNodeCalibrated(Parameter parameter) {
104 return (parameter.taxaId != null && hasProperPriorOn(parameter)) // param.taxa != null is TMRCA
105 || (parameter.getBaseName().endsWith("treeModel.rootHeight") && hasProperPriorOn(parameter));
106 }
107
108 private boolean hasProperPriorOn(Parameter para) {
109 return para.priorType == PriorType.EXPONENTIAL_PRIOR
110 || (para.priorType == PriorType.UNIFORM_PRIOR && para.uniformLower > 0 && para.uniformUpper < Double.POSITIVE_INFINITY)
111 || para.priorType == PriorType.LAPLACE_PRIOR
112 || para.priorType == PriorType.NORMAL_PRIOR
113 || para.priorType == PriorType.LOGNORMAL_PRIOR
114 || para.priorType == PriorType.GAMMA_PRIOR
115 || para.priorType == PriorType.INVERSE_GAMMA_PRIOR
116 || para.priorType == PriorType.BETA_PRIOR
117 || para.priorType == PriorType.CTMC_RATE_REFERENCE_PRIOR
118 || para.priorType == PriorType.LOGNORMAL_HPM_PRIOR
119 || para.priorType == PriorType.POISSON_PRIOR;
120 }
121
122 }