| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class TreeModelOptions extends ModelOptions { |
| 42 |
private static final long serialVersionUID = 5328826852511460749L; |
| 43 |
|
| 44 |
|
| 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; |
| 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; |
| 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)) |
| 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 |
} |