| 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.evomodel.branchmodel.lineagespecific; |
| 27 |
|
| 28 |
import dr.evolution.tree.*; |
| 29 |
import dr.evomodel.branchmodel.BranchModel; |
| 30 |
import dr.evomodel.substmodel.SubstitutionModel; |
| 31 |
import dr.evomodel.tree.TreeModel; |
| 32 |
import dr.inference.model.CompoundParameter; |
| 33 |
import dr.inference.model.Parameter; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class BranchSpecificTrait implements TreeTraitProvider { |
| 41 |
|
| 42 |
private Helper helper; |
| 43 |
private TreeModel treeModel; |
| 44 |
|
| 45 |
public BranchSpecificTrait( |
| 46 |
TreeModel treeModel, |
| 47 |
Parameter uCategories, |
| 48 |
CompoundParameter uniqueParameters, |
| 49 |
final String parameterName) { |
| 50 |
|
| 51 |
this.treeModel = treeModel; |
| 52 |
helper = new Helper(); |
| 53 |
|
| 54 |
TreeTrait<Double> uTrait = new TreeTrait.D() { |
| 55 |
|
| 56 |
@Override |
| 57 |
public String getTraitName() { |
| 58 |
return parameterName; |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public dr.evolution.tree.TreeTrait.Intent getIntent() { |
| 63 |
return Intent.BRANCH; |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public Double getTrait(Tree tree, NodeRef node) { |
| 68 |
|
| 69 |
double value = 0.0; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
return null; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
public BranchSpecificTrait( |
| 92 |
TreeModel treeModel, |
| 93 |
final BranchModel branchModel, |
| 94 |
|
| 95 |
final String parameterName |
| 96 |
) { |
| 97 |
|
| 98 |
this.treeModel = treeModel; |
| 99 |
helper = new Helper(); |
| 100 |
|
| 101 |
|
| 102 |
TreeTrait<Double> uTrait = new TreeTrait.D() { |
| 103 |
|
| 104 |
@Override |
| 105 |
public String getTraitName() { |
| 106 |
return parameterName; |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
public dr.evolution.tree.TreeTrait.Intent getIntent() { |
| 111 |
return Intent.BRANCH; |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
public Double getTrait(Tree tree, NodeRef branch) { |
| 116 |
|
| 117 |
double value = 0.0; |
| 118 |
|
| 119 |
int[] uCats = branchModel.getBranchModelMapping(branch).getOrder(); |
| 120 |
int category = uCats[0]; |
| 121 |
|
| 122 |
SubstitutionModel substmodel = branchModel.getSubstitutionModels().get(category); |
| 123 |
value = (Double) substmodel.getVariable(0).getValue(0); |
| 124 |
|
| 125 |
|
| 126 |
return value; |
| 127 |
|
| 128 |
} |
| 129 |
}; |
| 130 |
|
| 131 |
helper.addTrait(uTrait); |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
public TreeTrait[] getTreeTraits() { |
| 136 |
return helper.getTreeTraits(); |
| 137 |
} |
| 138 |
|
| 139 |
public TreeTrait getTreeTrait(String key) { |
| 140 |
return helper.getTreeTrait(key); |
| 141 |
} |
| 142 |
|
| 143 |
public String toString() { |
| 144 |
|
| 145 |
String annotatedTree = TreeUtils.newick(treeModel, |
| 146 |
new TreeTraitProvider[] { this }); |
| 147 |
|
| 148 |
return annotatedTree; |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
} |