From c0002bbf3939815aee2d97a4cab483b5bdc258cd Mon Sep 17 00:00:00 2001 From: Lars-B Date: Wed, 19 Nov 2025 10:44:24 -0800 Subject: [PATCH 1/3] Target tree option now does what it should, CompEvol/BeastFX#105 --- .../app/treeannotator/TreeAnnotator.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/beastfx/app/treeannotator/TreeAnnotator.java b/src/beastfx/app/treeannotator/TreeAnnotator.java index 4986153..9ffe7a3 100644 --- a/src/beastfx/app/treeannotator/TreeAnnotator.java +++ b/src/beastfx/app/treeannotator/TreeAnnotator.java @@ -36,7 +36,6 @@ import beast.base.core.Description; import beast.base.core.Input; import beast.base.core.Log; -import beast.base.evolution.alignment.TaxonSet; import beast.base.evolution.tree.Node; import beast.base.evolution.tree.Tree; import beast.base.evolution.tree.TreeParser; @@ -553,12 +552,8 @@ public void run(final int burninPercentage, topologySettingService = getTopologySettingService(); nodeHeightSettingService = getNodeHeightSettingService(); - // Get citations, only print if eihter of them is not empty. - - + // Get citations, only print if either of them is not empty. String nodeCitation = nodeHeightSettingService.getCitations(); - - String topoCitation = topologySettingService.getCitations(); if (!nodeCitation.isBlank() || !topoCitation.isBlank()) { @@ -619,11 +614,17 @@ public void run(final int burninPercentage, } } - Tree targetTree = topologySettingService.setTopology(treeSet, progressStream, this); + Tree targetTree; + if (targetTreeFileName != null) { + treeSet = new FastTreeSet(targetTreeFileName, 0); + treeSet.reset(); + targetTree = treeSet.next(); + } else { + targetTree = topologySettingService.setTopology(treeSet, progressStream, this); + } - cladeSystem = getCladeSystem(targetTree); - + // progressStream.println("Collecting node information..."); // progressStream.println("0 25 50 75 100"); // progressStream.println("|--------------|--------------|--------------|--------------|"); @@ -692,10 +693,18 @@ public void run(final int burninPercentage, System.out; targetTree.init(stream); stream.println(); - - stream.print("tree TREE_" + - topologySettingService.getServiceName() + "_" + - nodeHeightSettingService.getServiceName() + " = "); + + if (targetTreeFileName != null) { + int dotIndex = targetTreeFileName.lastIndexOf('.'); + String treeName = (dotIndex == -1) ? targetTreeFileName : targetTreeFileName.substring(0, dotIndex); + stream.print("tree TREE_" + + treeName + "_" + + nodeHeightSettingService.getServiceName() + " = "); + } else { + stream.print("tree TREE_" + + topologySettingService.getServiceName() + "_" + + nodeHeightSettingService.getServiceName() + " = "); + } int[] dummy = new int[1]; String newick = targetTree.getRoot().toSortedNewick(dummy, true); stream.print(newick); @@ -1175,7 +1184,7 @@ private void annotate2DHPDAttribute(Node node, String preLabel, String postLabel private final List beastObjects = new ArrayList<>(); Set attributeNames = new HashSet<>(); - TaxonSet taxa = null; +// TaxonSet taxa = null; static boolean processBivariateAttributes = true; @@ -1453,20 +1462,16 @@ public void run() throws Exception { hpd2D = hpd2DInput.get(); if (hpd2D <= 0 || hpd2D >=1) { Log.err.println("hpd2D is a fraction and should be in between 0.0 and 1.0."); - System.exit(1); + System.exit(1); } processBivariateAttributes = true; } - -// Target target = Target.MAX_CLADE_CREDIBILITY; -// if (targetInput.get() != null) { -// target = Target.USER_TARGET_TREE; -// targetTreeFileName = arguments.getStringOption("target"); -// } + if (targetInput.get() != null) { + targetTreeFileName = targetInput.get(); + } final List args2 = filesInput.get(); - switch (args2.size()) { case 2: From 776f6097c85304e3b27f126b21441ac6027d5380 Mon Sep 17 00:00:00 2001 From: Lars-B Date: Wed, 19 Nov 2025 12:12:23 -0800 Subject: [PATCH 2/3] Cleaner fix: no need to pass target twice --- .../app/treeannotator/TreeAnnotator.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/beastfx/app/treeannotator/TreeAnnotator.java b/src/beastfx/app/treeannotator/TreeAnnotator.java index 9ffe7a3..f489e04 100644 --- a/src/beastfx/app/treeannotator/TreeAnnotator.java +++ b/src/beastfx/app/treeannotator/TreeAnnotator.java @@ -614,15 +614,17 @@ public void run(final int burninPercentage, } } - Tree targetTree; if (targetTreeFileName != null) { - treeSet = new FastTreeSet(targetTreeFileName, 0); - treeSet.reset(); - targetTree = treeSet.next(); - } else { - targetTree = topologySettingService.setTopology(treeSet, progressStream, this); + String current = topologySettingService.getServiceName(); + String required = UserTargetTreeTopologyService.SERVICE_NAME; + if (!required.equals(current)) { + System.out.println("Setting topology to be the target tree..."); + topologyInput.setValue("target", this); + topologySettingService = getTopologySettingService(); + } } + Tree targetTree = topologySettingService.setTopology(treeSet, progressStream, this); cladeSystem = getCladeSystem(targetTree); // progressStream.println("Collecting node information..."); @@ -685,7 +687,7 @@ public void run(final int burninPercentage, progressStream.println("Writing annotated tree...."); - + processMetaData(targetTree.getRoot()); try { final PrintStream stream = outputFileName != null ? @@ -694,17 +696,9 @@ public void run(final int burninPercentage, targetTree.init(stream); stream.println(); - if (targetTreeFileName != null) { - int dotIndex = targetTreeFileName.lastIndexOf('.'); - String treeName = (dotIndex == -1) ? targetTreeFileName : targetTreeFileName.substring(0, dotIndex); - stream.print("tree TREE_" + - treeName + "_" + - nodeHeightSettingService.getServiceName() + " = "); - } else { - stream.print("tree TREE_" + + stream.print("tree TREE_" + topologySettingService.getServiceName() + "_" + nodeHeightSettingService.getServiceName() + " = "); - } int[] dummy = new int[1]; String newick = targetTree.getRoot().toSortedNewick(dummy, true); stream.print(newick); From 45e5f001f51c4ea7f83e249847e2df4856d5ce56 Mon Sep 17 00:00:00 2001 From: Lars-B Date: Wed, 19 Nov 2025 12:27:59 -0800 Subject: [PATCH 3/3] clean up, removing the targetTreeFileName parameter --- .../app/treeannotator/TreeAnnotator.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/beastfx/app/treeannotator/TreeAnnotator.java b/src/beastfx/app/treeannotator/TreeAnnotator.java index f489e04..d94bd28 100644 --- a/src/beastfx/app/treeannotator/TreeAnnotator.java +++ b/src/beastfx/app/treeannotator/TreeAnnotator.java @@ -60,7 +60,7 @@ public class TreeAnnotator extends beast.base.inference.Runnable { final public Input burnInPercentageInput = new Input<>("burnin", "percentage of trees to used as burn-in (and will be ignored)", 10); final public Input limitInput = new Input<>("limit", "the minimum posterior probability for a node to be annotated", 0.0); final public Input topologyInput = new Input<> ("topology", "name of the method for determining topology", "MCC"); - final public Input targetInput = new Input<> ("target", "target_file_name, specifies a user target tree to be annotated"); + final public Input targetInput = new Input<> ("target", "target_file_name, specifies a user target tree to be annotated", ""); final public Input forceDiscreteInput = new Input<> ("forceDiscrete", "forces integer traits to be treated as discrete traits."); final public Input lowMemInput = new Input<> ("lowMem", "use less memory, which is a bit slower."); final public Input hpd2DInput = new Input<> ("hpd2D", "the HPD interval to be used for the bivariate traits"); @@ -543,8 +543,6 @@ public void run(final int burninPercentage, // HeightsSummary heightsOption, double posteriorLimit, double hpd2D, - // Target targetOption, - String targetTreeFileName, String inputFileName, String outputFileName ) throws IOException { @@ -614,11 +612,11 @@ public void run(final int burninPercentage, } } - if (targetTreeFileName != null) { + if (targetInput.get() != null && !targetInput.get().isEmpty()) { String current = topologySettingService.getServiceName(); String required = UserTargetTreeTopologyService.SERVICE_NAME; if (!required.equals(current)) { - System.out.println("Setting topology to be the target tree..."); + Log.info("Setting topology to be the target tree..."); topologyInput.setValue("target", this); topologySettingService = getTopologySettingService(); } @@ -1390,8 +1388,7 @@ public void run() throws Exception { for (String versionFile : versionFileInput.get()) { BEASTClassLoader.addServices(versionFile); } - - String targetTreeFileName = null; + String inputFileName = null; String outputFileName = null; @@ -1461,10 +1458,6 @@ public void run() throws Exception { processBivariateAttributes = true; } - if (targetInput.get() != null) { - targetTreeFileName = targetInput.get(); - } - final List args2 = filesInput.get(); switch (args2.size()) { @@ -1483,9 +1476,7 @@ public void run() throws Exception { } try { - run(burninPercentage, lowMem, posteriorLimit, hpd2D, targetTreeFileName, inputFileName, outputFileName); - //} catch (IOException e) { - // throw e; + run(burninPercentage, lowMem, posteriorLimit, hpd2D, inputFileName, outputFileName); } catch (Exception e) { e.printStackTrace(); }