-
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 LPhyBEAST for UCLN LinguaPhylo/linguaPhylo#488
- Loading branch information
Showing
3 changed files
with
52 additions
and
17 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
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
43 changes: 43 additions & 0 deletions
43
lphybeast/src/main/java/lphybeast/tobeast/generators/UCLNRelaxedClockToBEAST.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,43 @@ | ||
package lphybeast.tobeast.generators; | ||
|
||
import beast.base.core.BEASTInterface; | ||
import beast.base.evolution.branchratemodel.UCRelaxedClockModel; | ||
import beast.base.inference.distribution.LogNormalDistributionModel; | ||
import beast.base.inference.parameter.RealParameter; | ||
import lphy.base.distribution.UCLN; | ||
import lphy.base.evolution.tree.TimeTree; | ||
import lphy.core.model.Value; | ||
import lphybeast.BEASTContext; | ||
import lphybeast.GeneratorToBEAST; | ||
|
||
public class UCLNRelaxedClockToBEAST implements GeneratorToBEAST<UCLN, UCRelaxedClockModel> { | ||
@Override | ||
public UCRelaxedClockModel generatorToBEAST(UCLN ucln, BEASTInterface value, BEASTContext context) { | ||
|
||
UCRelaxedClockModel ucRelaxedClockModel = new UCRelaxedClockModel(); | ||
|
||
LogNormalDistributionModel logNormDist = new LogNormalDistributionModel(); | ||
logNormDist.setInputValue("M", context.getAsRealParameter(ucln.getUclnMean())); | ||
logNormDist.setInputValue("S", context.getAsRealParameter(ucln.getUclnSigma())); | ||
logNormDist.initAndValidate(); | ||
ucRelaxedClockModel.setInputValue("distr", logNormDist); | ||
|
||
Value<TimeTree> tree = ucln.getTree(); | ||
ucRelaxedClockModel.setInputValue("tree", context.getBEASTObject(tree)); | ||
|
||
if (value instanceof RealParameter rates) { | ||
ucRelaxedClockModel.setInputValue("rates", rates); | ||
} else throw new IllegalArgumentException("Value sampled from LPhy UCLN should be mapped to RealParameter ! " + value); | ||
|
||
ucRelaxedClockModel.initAndValidate(); | ||
return ucRelaxedClockModel; | ||
} | ||
|
||
@Override | ||
public Class<UCLN> getGeneratorClass() { return UCLN.class; } | ||
|
||
@Override | ||
public Class<UCRelaxedClockModel> getBEASTClass() { | ||
return UCRelaxedClockModel.class; | ||
} | ||
} |