-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
lphy-base/src/main/java/lphy/base/function/tree/InternalNodesID.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters