Skip to content

Commit

Permalink
Log internal node sequences #518
Browse files Browse the repository at this point in the history
  • Loading branch information
walterxie committed Aug 20, 2024
1 parent 60d82db commit ad81a76
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void toNewick(TimeTreeNode node, StringBuilder builder, boolean includeS
toNewick(node.getChildren().get(0), builder, includeSingleChildNodes);
} else {
if (node.isLeaf()) {
builder.append(node.id);
builder.append(node.getId());
// update to handle more than one element in metaData
addMetaData(node, builder);
} else {
Expand All @@ -144,6 +144,10 @@ private void toNewick(TimeTreeNode node, StringBuilder builder, boolean includeS
}
builder.append(")");
}

if (!node.isLeaf() && node.getId() != null)
builder.append(node.getId());

if (node.isRoot()) {
builder.append(":0.0;");
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package lphy.base.function.tree;

import lphy.base.evolution.tree.TimeTree;
import lphy.base.evolution.tree.TimeTreeNode;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorCategory;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;

import static lphy.base.evolution.EvolutionConstants.treeParamName;

/**
* A function to set internal nodes id given a tree
*/
public class InternalNodesID extends DeterministicFunction<TimeTree> {

public InternalNodesID(@ParameterInfo(name = treeParamName,
description = "the tree to set internal nodes id.") Value<TimeTree> tree) {
setParam(treeParamName, tree);
}

@GeneratorInfo(name = "setInternalNodesID", category = GeneratorCategory.TREE,
description = "set internal nodes id given a tree.")
public Value<TimeTree> apply() {

Value<TimeTree> tree = getParams().get(treeParamName);

// do deep copy
TimeTree newTree = new TimeTree(tree.value());

for (TimeTreeNode node : newTree.getInternalNodes()) {
if (node.getId() == null) // set index as id
node.setId(String.valueOf(node.getIndex()));
}

return new Value<>(null, newTree, this);
}
}
10 changes: 4 additions & 6 deletions lphy-base/src/main/java/lphy/base/spi/LPhyBaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import lphy.base.function.datatype.StandardDatatypeFunction;
import lphy.base.function.io.*;
import lphy.base.function.taxa.*;
import lphy.base.function.tree.ExtantTree;
import lphy.base.function.tree.MigrationCount;
import lphy.base.function.tree.Newick;
import lphy.base.function.tree.PruneTree;
import lphy.base.function.tree.*;
import lphy.core.model.BasicFunction;
import lphy.core.model.GenerativeDistribution;
import lphy.core.spi.LPhyCoreImpl;
Expand Down Expand Up @@ -91,8 +88,9 @@ public List<Class<? extends BasicFunction>> declareFunctions() {
SelectSitesByMissingFraction.class, RemoveTaxa.class,
VariableSites.class, InvariableSites.class, CopySites.class,
// Tree
LocalBranchRates.class, ExtantTree.class, PruneTree.class, LocalClock.class,
SubstituteClade.class, MRCA.class, LabelClade.class,//NodeCount.class, TreeLength.class,
LocalBranchRates.class, LocalClock.class,
ExtantTree.class, PruneTree.class, InternalNodesID.class,
SubstituteClade.class, MRCA.class, LabelClade.class, //NodeCount.class, TreeLength.class,
// Matrix
BinaryRateMatrix.class, MigrationMatrix.class, MigrationCount.class,
// IO
Expand Down

0 comments on commit ad81a76

Please sign in to comment.