-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing logging in XML for relaxed clock #161 LinguaPhylo/linguaP…
- Loading branch information
Showing
4 changed files
with
105 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
lphybeast/src/main/java/lphybeast/tobeast/LoggerUtils.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,19 @@ | ||
package lphybeast.tobeast; | ||
|
||
import beast.base.evolution.RateStatistic; | ||
import beast.base.evolution.branchratemodel.BranchRateModel; | ||
import beast.base.evolution.tree.TreeInterface; | ||
|
||
public class LoggerUtils { | ||
|
||
public static RateStatistic createRateStatistic(String id, BranchRateModel branchRateModel, TreeInterface tree) { | ||
// <log id="" ... branchratemodel="@" tree="@"/> | ||
RateStatistic rateStatistic = new RateStatistic(); | ||
rateStatistic.setInputValue("branchratemodel", branchRateModel); | ||
rateStatistic.setInputValue("tree", tree); | ||
rateStatistic.initAndValidate(); | ||
rateStatistic.setID(id); | ||
return rateStatistic; | ||
} | ||
|
||
} |
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
71 changes: 71 additions & 0 deletions
71
lphybeast/src/main/java/lphybeast/tobeast/loggers/MetaDataTreeLogger.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,71 @@ | ||
package lphybeast.tobeast.loggers; | ||
|
||
import beast.base.core.BEASTInterface; | ||
import beast.base.evolution.TreeWithMetaDataLogger; | ||
import beast.base.evolution.branchratemodel.BranchRateModel; | ||
import beast.base.evolution.tree.TreeInterface; | ||
import beast.base.inference.Logger; | ||
import com.google.common.collect.Multimap; | ||
import lphy.core.model.GraphicalModelNode; | ||
import lphybeast.BEASTContext; | ||
|
||
import java.util.Objects; | ||
|
||
import static java.lang.Math.toIntExact; | ||
|
||
/** | ||
* Log branch rates with tree. | ||
* @see TreeWithMetaDataLogger | ||
* @author Walter Xie | ||
*/ | ||
public class MetaDataTreeLogger implements TreeLoggerHelper { | ||
// add extra tree logger for AncestralStateTreeLikelihood | ||
final protected BranchRateModel branchRateModel; | ||
final protected BEASTContext context; | ||
final TreeInterface tree; | ||
String fileName; | ||
|
||
public MetaDataTreeLogger(BranchRateModel branchRateModel, TreeInterface tree, BEASTContext context) { | ||
this.branchRateModel = Objects.requireNonNull(branchRateModel); | ||
this.tree = Objects.requireNonNull(tree); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public Logger createLogger(long logEvery, Multimap<BEASTInterface, GraphicalModelNode<?>> elements) { | ||
Logger logger = new Logger(); | ||
// Must convert to int | ||
logger.setInputValue("logEvery", toIntExact(logEvery)); | ||
logger.setInputValue("fileName", getFileName()); | ||
logger.setInputValue("mode", "tree"); | ||
|
||
TreeWithMetaDataLogger treeWithMetaDataLogger = new TreeWithMetaDataLogger(); | ||
treeWithMetaDataLogger.setInputValue("tree", tree); | ||
treeWithMetaDataLogger.setInputValue("branchratemodel", branchRateModel); | ||
|
||
logger.setInputValue("log", treeWithMetaDataLogger); | ||
logger.initAndValidate(); | ||
|
||
logger.setID("TreeWithMetaDataLogger." + tree.getID()); | ||
elements.put(logger, null); | ||
return logger; | ||
} | ||
|
||
@Override | ||
public TreeInterface getTree() { | ||
return tree; | ||
} | ||
|
||
@Override | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
@Override | ||
public void setFileName(String fileStem, boolean isMultiple) { | ||
if (isMultiple) // multi-partitions and unlink trees | ||
fileName = fileStem + "_with_rates." + getTree().getID() + ".trees"; | ||
else | ||
fileName = fileStem + "_with_rates.trees"; | ||
} | ||
} |