Skip to content

Commit

Permalink
set ids of trees parsed from NEXUS file. fixes CompEvol/BeastFX#87
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Sep 16, 2024
1 parent fe85402 commit c520aaf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/beast/base/parser/NexusParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,20 @@ protected void parseTreesBlock(final BufferedReader fin) throws IOException {
}

// read trees
int current = 0;
while (nextCommand != null && !nextCommand.isEndOfBlock()) {
if (nextCommand.isCommand("tree")) {
String treeString = nextCommand.arguments;
final int i = treeString.indexOf('(');


String id = "" + current;
try {
id = treeString.substring(5, i).split("=")[0].trim();
} catch (Exception e) {
// ignore
}

if (i > 0) {
treeString = treeString.substring(i);
}
Expand All @@ -546,8 +556,11 @@ protected void parseTreesBlock(final BufferedReader fin) throws IOException {
listener.treeParsed(trees.size(), treeParser);
}

treeParser.setID(id);

// this must come after listener or trees.size() gives the wrong index to treeParsed
trees.add(treeParser);
current++;

}
nextCommand = readNextCommand(fin);
Expand Down

0 comments on commit c520aaf

Please sign in to comment.