| 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.treestat.statistics; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evolution.tree.TreeUtils; |
| 31 |
import dr.evolution.util.*; |
| 32 |
|
| 33 |
import java.util.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class TMRCASummaryStatistic extends AbstractTreeSummaryStatistic { |
| 42 |
|
| 43 |
private TMRCASummaryStatistic() { |
| 44 |
this.taxonList = null; |
| 45 |
} |
| 46 |
|
| 47 |
public void setTaxonList(TaxonList taxonList) { |
| 48 |
this.taxonList = taxonList; |
| 49 |
} |
| 50 |
|
| 51 |
public double[] getSummaryStatistic(Tree tree) { |
| 52 |
if (taxonList == null) { |
| 53 |
return new double[] { tree.getNodeHeight(tree.getRoot()) }; |
| 54 |
} |
| 55 |
try { |
| 56 |
Set<String> leafSet = TreeUtils.getLeavesForTaxa(tree, taxonList); |
| 57 |
NodeRef node = TreeUtils.getCommonAncestorNode(tree, leafSet); |
| 58 |
if (node == null) throw new RuntimeException("No node found that is MRCA of " + leafSet); |
| 59 |
return new double[] { tree.getNodeHeight(node) }; |
| 60 |
} catch (TreeUtils.MissingTaxonException e) { |
| 61 |
throw new RuntimeException("Missing taxon!"); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
public String getSummaryStatisticName() { |
| 66 |
if (characterState != null) { |
| 67 |
return "tMRCA(" + characterState + ")"; |
| 68 |
} else if (taxonList != null) { |
| 69 |
return "tMRCA(" + taxonList.getId() + ")"; |
| 70 |
} else { |
| 71 |
return "tMRCA"; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
public String getSummaryStatisticDescription() { |
| 76 |
if (characterState != null) { |
| 77 |
return "The time of the most recent common ancestor of the character state " + characterState; |
| 78 |
} else if (taxonList != null) { |
| 79 |
return "The time of the most recent common ancestor of the given taxon list"; |
| 80 |
} |
| 81 |
return "The time of the most recent common ancestor of a set of taxa. In order to use this statistic, a taxon set must be defined (see the Taxon Set tab)."; |
| 82 |
} |
| 83 |
|
| 84 |
public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); } |
| 85 |
public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); } |
| 86 |
public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); } |
| 87 |
public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); } |
| 88 |
public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); } |
| 89 |
|
| 90 |
public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() { |
| 91 |
|
| 92 |
public TreeSummaryStatistic createStatistic() { |
| 93 |
return new TMRCASummaryStatistic(); |
| 94 |
} |
| 95 |
|
| 96 |
public String getSummaryStatisticName() { |
| 97 |
return "tMRCA"; |
| 98 |
} |
| 99 |
|
| 100 |
public String getSummaryStatisticDescription() { |
| 101 |
return "The time of the most recent common ancestor"; |
| 102 |
} |
| 103 |
|
| 104 |
public String getSummaryStatisticReference() { |
| 105 |
return "-"; |
| 106 |
} |
| 107 |
|
| 108 |
public boolean allowsPolytomies() { return true; } |
| 109 |
|
| 110 |
public boolean allowsNonultrametricTrees() { return true; } |
| 111 |
|
| 112 |
public boolean allowsUnrootedTrees() { return false; } |
| 113 |
|
| 114 |
public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.GENERAL; } |
| 115 |
|
| 116 |
public boolean allowsWholeTree() { return true; } |
| 117 |
|
| 118 |
public boolean allowsCharacter() { return false; } |
| 119 |
|
| 120 |
public boolean allowsCharacterState() { return false; } |
| 121 |
|
| 122 |
public boolean allowsTaxonList() { return true; } |
| 123 |
}; |
| 124 |
|
| 125 |
private String characterState = null; |
| 126 |
private TaxonList taxonList = null; |
| 127 |
} |
| 128 |
|