From 0e9723447b86bdc77f15f2ff45cfe59053e093fe Mon Sep 17 00:00:00 2001 From: rbouckaert Date: Mon, 6 Jan 2025 11:43:20 +1300 Subject: [PATCH] make TreeWithMetaDataLogger produce correct nr of commas. fixes #1177 --- src/beast/base/evolution/TreeWithMetaDataLogger.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/beast/base/evolution/TreeWithMetaDataLogger.java b/src/beast/base/evolution/TreeWithMetaDataLogger.java index d20fee13..35ab6ae6 100644 --- a/src/beast/base/evolution/TreeWithMetaDataLogger.java +++ b/src/beast/base/evolution/TreeWithMetaDataLogger.java @@ -123,11 +123,15 @@ String toNewick(Node node, List metadataList, BranchRateModel.Base bra if (someMetaDataNeedsLogging) { buf2.append("[&"); if (metadataList.size() > 0) { + boolean needsComma = false; for (Function metadata : metadataList) { if (metadata instanceof Parameter) { Parameter p = (Parameter) metadata; int dim = p.getMinorDimension1(); if (p.getMinorDimension2() > node.getNr()) { + if (needsComma) { + buf2.append(","); + } buf2.append(((BEASTObject) metadata).getID()); buf2.append('='); if (dim > 1) { @@ -152,19 +156,21 @@ String toNewick(Node node, List metadataList, BranchRateModel.Base bra buf2.append(metadata.getArrayValue(node.getNr())); } } + needsComma = true; } else { } } else { if (metadata.getDimension() > node.getNr()) { + if (needsComma) { + buf2.append(","); + } buf2.append(((BEASTObject) metadata).getID()); buf2.append('='); buf2.append(metadata.getArrayValue(node.getNr())); + needsComma = true; } } - if (buf2.length() > 2 && metadataList.indexOf(metadata) < metadataList.size() - 1) { - buf2.append(","); - } } if (buf2.length() > 2 && branchRateModel != null) { buf2.append(",");