| 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.Tree; |
| 29 |
import dr.evolution.tree.TreeUtils; |
| 30 |
import dr.evolution.util.TaxonList; |
| 31 |
import dr.inference.model.BooleanStatistic; |
| 32 |
|
| 33 |
import java.util.Collections; |
| 34 |
import java.util.Set; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class MonophylyStatistic extends TreeStatistic implements BooleanStatistic { |
| 45 |
|
| 46 |
public MonophylyStatistic(String name, Tree tree, TaxonList taxa, TaxonList ignore) throws TreeUtils.MissingTaxonException { |
| 47 |
|
| 48 |
this(name, tree, taxa, ignore, false); |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
public MonophylyStatistic(String name, Tree tree, TaxonList taxa, TaxonList ignore, boolean inverse) throws TreeUtils.MissingTaxonException { |
| 53 |
|
| 54 |
super(name); |
| 55 |
this.tree = tree; |
| 56 |
this.leafSet = TreeUtils.getLeavesForTaxa(tree, taxa); |
| 57 |
if (ignore != null) { |
| 58 |
this.ignoreLeafSet = TreeUtils.getLeavesForTaxa(tree, ignore); |
| 59 |
} else { |
| 60 |
this.ignoreLeafSet = Collections.emptySet(); |
| 61 |
} |
| 62 |
this.inverse = inverse; |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
public void setTree(Tree tree) { |
| 67 |
this.tree = tree; |
| 68 |
} |
| 69 |
|
| 70 |
public Tree getTree() { |
| 71 |
return tree; |
| 72 |
} |
| 73 |
|
| 74 |
public int getDimension() { |
| 75 |
return 1; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public double getStatisticValue(int dim) { |
| 82 |
return getBoolean(dim) ? 1.0 : 0.0; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public boolean getBoolean(int dim) { |
| 89 |
boolean monophyletic = TreeUtils.isMonophyletic(this.tree, this.leafSet, this.ignoreLeafSet); |
| 90 |
if (inverse){ |
| 91 |
return !monophyletic; |
| 92 |
} else { |
| 93 |
return monophyletic; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
private Tree tree = null; |
| 98 |
private Set<String> leafSet = null; |
| 99 |
private Set<String> ignoreLeafSet = null; |
| 100 |
private boolean inverse = false; |
| 101 |
|
| 102 |
} |