| 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.TreeTrait; |
| 31 |
import dr.evolution.tree.TreeUtils; |
| 32 |
import dr.evolution.util.TaxonList; |
| 33 |
import dr.inference.loggers.LogColumn; |
| 34 |
import dr.inference.loggers.Loggable; |
| 35 |
|
| 36 |
import java.util.Set; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public class AncestralTrait implements Loggable { |
| 46 |
|
| 47 |
public AncestralTrait(String name, TreeTrait ancestralTrait, Tree tree, TaxonList taxa) throws TreeUtils.MissingTaxonException { |
| 48 |
this.name = name; |
| 49 |
this.tree = tree; |
| 50 |
this.ancestralTrait = ancestralTrait; |
| 51 |
if (taxa != null) { |
| 52 |
this.leafSet = TreeUtils.getLeavesForTaxa(tree, taxa); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
public Tree getTree() { |
| 57 |
return tree; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public String getAncestralState() { |
| 64 |
|
| 65 |
NodeRef node; |
| 66 |
if (leafSet != null) { |
| 67 |
node = TreeUtils.getCommonAncestorNode(tree, leafSet); |
| 68 |
if (node == null) throw new RuntimeException("No node found that is MRCA of " + leafSet); |
| 69 |
} else { |
| 70 |
node = tree.getRoot(); |
| 71 |
} |
| 72 |
|
| 73 |
return ancestralTrait.getTraitString(tree, node); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public LogColumn[] getColumns() { |
| 84 |
LogColumn[] columns = new LogColumn[1]; |
| 85 |
columns[0] = new LogColumn.Abstract(name) { |
| 86 |
|
| 87 |
protected String getFormattedValue() { |
| 88 |
return getAncestralState(); |
| 89 |
} |
| 90 |
}; |
| 91 |
return columns; |
| 92 |
} |
| 93 |
|
| 94 |
private final Tree tree; |
| 95 |
private final TreeTrait ancestralTrait; |
| 96 |
private final String name; |
| 97 |
private Set<String> leafSet = null; |
| 98 |
|
| 99 |
} |