Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
rambaut committed Jan 22, 2025
1 parent 3b8ada4 commit dc78f74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 182 deletions.
129 changes: 0 additions & 129 deletions src/dr/app/tools/treeannotator/CAHeights.java

This file was deleted.

22 changes: 10 additions & 12 deletions src/dr/app/tools/treeannotator/HIPSTRTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ private double findHIPSTRTree(BiClade clade, double penaltyThreshold) {

assert clade.getSize() > 1;

// double cladeScore = Math.log(clade.getCredibility() + penaltyThreshold);
double cladeScore = Math.log(clade.getCredibility() + penaltyThreshold) + clade.getCredibility() >= 0.5 ? 1.0E10 : 0.0;
double cladeScore = Math.log(clade.getCredibility() + penaltyThreshold);
// double cladeScore = Math.log(clade.getCredibility() + penaltyThreshold) + clade.getCredibility() >= 0.5 ? 1.0E10 : 0.0;

Map<Pair<BiClade, BiClade>, Double> ties = new HashMap<>();
Map<Pair<BiClade, BiClade>, Double> ties;
if (breakTies) {
ties = new HashMap<>();
}

// if it is not a tip
if (clade.getSize() > 2) {
Expand All @@ -75,7 +78,7 @@ private double findHIPSTRTree(BiClade clade, double penaltyThreshold) {
for (Pair<BiClade, BiClade> subClade : clade.getSubClades()) {
BiClade left = subClade.first;

double leftScore = Math.log(1.5);
double leftScore = Math.log(1.0 + penaltyThreshold);
// double leftScore = 0.0);
if (left.getSize() > 1) {
leftScore = credibilityCache.getOrDefault(left, Double.NaN);
Expand All @@ -87,7 +90,7 @@ private double findHIPSTRTree(BiClade clade, double penaltyThreshold) {

BiClade right = subClade.second;

double rightScore = Math.log(1.5);
double rightScore = Math.log(1.0 + penaltyThreshold);
// double rightScore = 0.0;
if (right.getSize() > 1) {
rightScore = credibilityCache.getOrDefault(right, Double.NaN);
Expand All @@ -110,8 +113,7 @@ private double findHIPSTRTree(BiClade clade, double penaltyThreshold) {
clade.bestLeft = right;
clade.bestRight = left;
}
// ties.put(new Pair<>(left, right), Math.max(left.getCredibility(), right.getCredibility()));
ties.put(new Pair<>(left, right), left.getCredibility() * right.getCredibility());
ties.put(new Pair<>(left, right), (left.getCredibility() + penaltyThreshold) * (right.getCredibility() + penaltyThreshold));
}
}
} else {
Expand Down Expand Up @@ -148,11 +150,7 @@ private double findHIPSTRTree(BiClade clade, double penaltyThreshold) {
Pair<BiClade, BiClade> subClade = clade.getSubClades().stream().findFirst().get();
clade.bestLeft = subClade.first;
clade.bestRight = subClade.second;

if (clade.bestLeft.getTaxon().getId().contains("EPI_ISL_477006")) {
System.out.println("EPI_ISL_477006");
}
cladeScore += 2 * Math.log(1.5);
cladeScore += 2 * Math.log(1.0 + penaltyThreshold);
}

clade.bestSubTreeScore = cladeScore;
Expand Down
60 changes: 19 additions & 41 deletions src/dr/app/tools/treeannotator/TreeAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,18 @@ public class TreeAnnotator extends BaseTreeTool {

// Messages to stderr, output to stdout
private static PrintStream progressStream = System.err;
private static final boolean extendedMetrics = true;
private static final boolean extendedMetrics = false;

private final CollectionAction collectionAction;
private final AnnotationAction annotationAction;

private TaxonList taxa = null;
private int totalTrees;
private int totalTreesUsed;
private long maxState;

enum Target {
MAX_CLADE_CREDIBILITY("Maximum clade credibility tree"),
HIPSTR("Highest independent posterior subtree reconstruction (HIPSTR)"),
MAX_CLADE_CREDIBILITY("Maximum clade credibility tree"),
USER_TARGET_TREE("User target tree");

String desc;
Expand All @@ -94,10 +93,9 @@ public String toString() {
}

enum HeightsSummary {
MEDIAN_HEIGHTS("Median heights"),
MEAN_HEIGHTS("Mean heights"),
KEEP_HEIGHTS("Keep target heights"),
CA_HEIGHTS("Common Ancestor heights");
MEDIAN_HEIGHTS("Median heights"),
KEEP_HEIGHTS("Keep target heights");

String desc;

Expand All @@ -118,6 +116,7 @@ public TreeAnnotator(final int burninTrees,
final long burninStates,
final HeightsSummary heightsOption,
final double posteriorLimit,
final double hipstrPenalty,
final double[] hpd2D,
final boolean computeESS,
final Target targetOption,
Expand Down Expand Up @@ -195,7 +194,7 @@ public TreeAnnotator(final int burninTrees,
}
case HIPSTR: {
progressStream.println("Finding highest independent posterior subtree reconstruction (HIPSTR) tree...");
targetTree = getHIPSTRTree(cladeSystem, 0.5);
targetTree = getHIPSTRTree(cladeSystem, hipstrPenalty);
break;
}
default: throw new IllegalArgumentException("Unknown targetOption");
Expand All @@ -220,10 +219,6 @@ public TreeAnnotator(final int burninTrees,

annotateTargetTree(targetCladeSystem, heightsOption, targetTree);

if (heightsOption == HeightsSummary.CA_HEIGHTS) {
setNodeHeightsCA(targetCladeSystem, targetTree);
}

writeAnnotatedTree(outputFileName, targetTree);

long timeElapsed = (System.currentTimeMillis() - totalStartTime) / 1000;
Expand Down Expand Up @@ -285,6 +280,7 @@ private int readTrees(String inputFileName, int burninTrees, long burninStates,
// if burnin has been specified in states, try to parse it out...
String name = tree.getId().trim();

long maxState;
if (name.startsWith("STATE_")) {
state = Long.parseLong(name.split("_")[1]);
maxState = state;
Expand Down Expand Up @@ -601,24 +597,6 @@ private void annotateTargetTree(CladeSystem cladeSystem, HeightsSummary heightsO
progressStream.println();
}

private void setNodeHeightsCA(CladeSystem cladeSystem, MutableTree targetTree) {
throw new UnsupportedOperationException("CA node heights is not supported in treeannotator X");
// long startTime = System.currentTimeMillis();
// progressStream.println("Setting node heights...");
// progressStream.println("0 25 50 75 100");
// progressStream.println("|--------------|--------------|--------------|--------------|");
//
// int stepSize = totalTrees / 60;
// if (stepSize < 1) stepSize = 1;
//
// CAHeights caHeights = new CAHeights(this);
// caHeights.setTreeHeightsByCA(targetTree, inputFileName, burnin);
//
// long timeElapsed = (System.currentTimeMillis() - startTime) / 1000;
// progressStream.println("* [" + timeElapsed + " secs]");
// progressStream.println();
}

private void writeAnnotatedTree(String outputFileName, MutableTree targetTree) {
progressStream.println("Writing annotated tree...");

Expand Down Expand Up @@ -782,6 +760,7 @@ public static void main(String[] args) throws IOException {
burninStates,
heightsOption,
posteriorLimit,
0.0,
hpd2D,
computeESS,
targetOption,
Expand All @@ -808,10 +787,10 @@ public static void main(String[] args) throws IOException {

Arguments arguments = new Arguments(
new Arguments.Option[]{
new Arguments.StringOption("type", new String[]{"mcc", "hipstr"}, false, "an option of 'mcc' or 'hipstr'"),
new Arguments.StringOption("heights", new String[]{"keep", "median", "mean", "ca"}, false,
new Arguments.StringOption("type", new String[] {"hipstr", "mcc"}, false, "an option of 'hipstr' (default) or 'mcc'"),
new Arguments.RealOption("penalty", "the hipstr clade credibility penalty (default 0.0)"),
new Arguments.StringOption("heights", new String[] {"keep", "median", "mean", "ca"}, false,
"an option of 'keep', 'median' or 'mean' (default)"),
//"an option of 'keep', 'median', 'mean' or 'ca' (default)"),
new Arguments.LongOption("burnin", "the number of states to be considered as 'burn-in'"),
new Arguments.IntegerOption("burninTrees", "the number of trees to be considered as 'burn-in'"),
new Arguments.RealOption("limit", "the minimum posterior probability for a node to be annotated"),
Expand Down Expand Up @@ -887,9 +866,13 @@ public static void main(String[] args) throws IOException {
}
}

Target target = Target.MAX_CLADE_CREDIBILITY;
if (arguments.hasOption("type") && arguments.getStringOption("type").equalsIgnoreCase("HIPSTR")) {
target = Target.HIPSTR;
Target target = Target.HIPSTR;
if (arguments.hasOption("type") && arguments.getStringOption("type").equalsIgnoreCase("MCC")) {
target = Target.MAX_CLADE_CREDIBILITY;
}
double hipstrPenalty = 0.0;
if (arguments.hasOption("penalty")) {
hipstrPenalty = arguments.getRealOption("penalty");
}

if (arguments.hasOption("target")) {
Expand Down Expand Up @@ -923,6 +906,7 @@ public static void main(String[] args) throws IOException {
burninStates,
heights,
posteriorLimit,
hipstrPenalty,
hpd2D,
computeESS,
target,
Expand All @@ -940,12 +924,6 @@ public static void main(String[] args) throws IOException {
// progressStream.println("Loaded user target tree.");
}

if (heights == HeightsSummary.CA_HEIGHTS) {
progressStream.println("\nUsed Clade Height option - citation: " +
"Heled and Bouckaert: 'Looking for trees in the forest: " +
"summary tree from posterior samples'. BMC Evolutionary Biology 2013 13:221.");
}

System.exit(0);
}

Expand Down

0 comments on commit dc78f74

Please sign in to comment.