| 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.tree; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evolution.tree.TreeUtils; |
| 31 |
import dr.evolution.util.Taxon; |
| 32 |
import dr.evolution.util.TaxonList; |
| 33 |
import dr.inference.model.Statistic; |
| 34 |
|
| 35 |
import java.util.ArrayList; |
| 36 |
import java.util.List; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public class ExternalLengthStatistic extends TreeStatistic { |
| 46 |
|
| 47 |
public ExternalLengthStatistic(String name, Tree tree, TaxonList taxa) throws TreeUtils.MissingTaxonException { |
| 48 |
super(name); |
| 49 |
this.tree = tree; |
| 50 |
int m = taxa.getTaxonCount(); |
| 51 |
int n = tree.getExternalNodeCount(); |
| 52 |
|
| 53 |
for (int i = 0; i < m; i++) { |
| 54 |
|
| 55 |
Taxon taxon = taxa.getTaxon(i); |
| 56 |
NodeRef node = null; |
| 57 |
boolean found = false; |
| 58 |
for (int j = 0; j < n; j++) { |
| 59 |
|
| 60 |
node = tree.getExternalNode(j); |
| 61 |
if (tree.getNodeTaxon(node).getId().equals(taxon.getId())) { |
| 62 |
|
| 63 |
found = true; |
| 64 |
break; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
if (!found) { |
| 69 |
throw new TreeUtils.MissingTaxonException(taxon); |
| 70 |
} |
| 71 |
|
| 72 |
leafSet.add(node); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public void setTree(Tree tree) { |
| 77 |
this.tree = tree; |
| 78 |
} |
| 79 |
|
| 80 |
public Tree getTree() { |
| 81 |
return tree; |
| 82 |
} |
| 83 |
|
| 84 |
public int getDimension() { |
| 85 |
return leafSet.size(); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public double getStatisticValue(int dim) { |
| 92 |
NodeRef node = leafSet.get(dim); |
| 93 |
return tree.getBranchLength(node); |
| 94 |
} |
| 95 |
|
| 96 |
private Tree tree = null; |
| 97 |
private List<NodeRef> leafSet = new ArrayList<NodeRef>(); |
| 98 |
|
| 99 |
} |