-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
170 additions
and
59 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
103 changes: 49 additions & 54 deletions
103
phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/GompertzToBEAST.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 |
---|---|---|
@@ -1,54 +1,49 @@ | ||
package phylonco.lphybeast.tobeast.generators; | ||
|
||
import beast.base.core.BEASTInterface; | ||
import beast.base.evolution.tree.coalescent.PopulationFunction; | ||
import beast.base.inference.parameter.RealParameter; | ||
import lphy.core.model.Generator; | ||
import lphybeast.BEASTContext; | ||
import lphybeast.GeneratorToBEAST; | ||
import phylonco.beast.evolution.populationmodel.GompertzGrowth; | ||
|
||
public class GompertzToBEAST implements GeneratorToBEAST<GompertzGrowth, phylonco.beast.evolution.populationmodel.GompertzGrowth> { | ||
// <populationModel id="gompertzPopulationModel" spec="phylonco.beast.evolution.populationmodel.GompertzGrowth"> | ||
// <parameter name="f0" idref="f0"/> | ||
// <parameter name="NInfinity" idref="NInfinity"/> | ||
// <parameter name="b" idref="b"/> | ||
// </populationModel> | ||
|
||
@Override | ||
public phylonco.beast.evolution.populationmodel.GompertzGrowth generatorToBEAST(GompertzGrowth gompertzGrowth, BEASTInterface value, BEASTContext context) { | ||
phylonco.beast.evolution.populationmodel.GompertzGrowth beastGompertzGrowth = new phylonco.beast.evolution.populationmodel.GompertzGrowth(); | ||
|
||
double f0 = gompertzGrowth.getF0(); | ||
|
||
|
||
double b = gompertzGrowth.getGrowthRateB(); | ||
double NInfinity = gompertzGrowth.getNInfinity(); | ||
|
||
RealParameter f0Param = new RealParameter(Double.toString(f0)); | ||
RealParameter bParam = new RealParameter(Double.toString(b)); | ||
RealParameter NInfinityParam = new RealParameter(Double.toString(NInfinity)); | ||
|
||
beastGompertzGrowth.setInputValue("f0", f0Param); | ||
beastGompertzGrowth.setInputValue("b", bParam); | ||
beastGompertzGrowth.setInputValue("NInfinity", NInfinityParam); | ||
|
||
|
||
beastGompertzGrowth.initAndValidate(); | ||
|
||
return beastGompertzGrowth; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public Class<GompertzGrowth> getGeneratorClass() { | ||
return GompertzGrowth.class; | ||
} | ||
|
||
@Override | ||
public Class<phylonco.beast.evolution.populationmodel.GompertzGrowth> getBEASTClass() { | ||
return phylonco.beast.evolution.populationmodel.GompertzGrowth.class; | ||
} | ||
|
||
} | ||
//package phylonco.lphybeast.tobeast.generators; | ||
// | ||
//import beast.base.core.BEASTInterface; | ||
//import beast.base.core.Function; | ||
//import beast.base.evolution.tree.coalescent.PopulationFunction; | ||
//import beast.base.inference.parameter.RealParameter; | ||
//import lphy.base.evolution.coalescent.populationmodel.GompertzPopulation; | ||
//import lphy.base.evolution.coalescent.populationmodel.GompertzPopulationFunction; | ||
//import lphy.core.model.Generator; | ||
//import lphy.core.model.ValueUtils; | ||
//import lphybeast.BEASTContext; | ||
//import lphybeast.GeneratorToBEAST; | ||
//import phylonco.beast.evolution.populationmodel.GompertzGrowth; | ||
//import phylonco.lphy.evolution.substitutionmodel.GT16; | ||
// | ||
//import java.util.List; | ||
// | ||
//public class GompertzToBEAST implements GeneratorToBEAST<GompertzPopulationFunction, GompertzGrowth> { | ||
//// <populationModel id="gompertzPopulationModel" spec="phylonco.beast.evolution.populationmodel.GompertzGrowth"> | ||
//// <parameter name="f0" idref="f0"/> | ||
//// <parameter name="NInfinity" idref="NInfinity"/> | ||
//// <parameter name="b" idref="b"/> | ||
//// </populationModel> | ||
// | ||
// @Override | ||
// public GompertzGrowth generatorToBEAST(GompertzPopulationFunction gompertzPopulationFunction, BEASTInterface beastInterface, BEASTContext beastContext) { | ||
// | ||
// GompertzGrowth beastGompertzGrowth = new GompertzGrowth(); | ||
// | ||
// RealParameter f0Param = beastContext.getAsRealParameter(gompertzPopulationFunction.getF0()); | ||
// RealParameter bParam = beastContext.getAsRealParameter(gompertzPopulationFunction.getB()); | ||
// RealParameter NInfinityParam = beastContext.getAsRealParameter(gompertzPopulationFunction.getNInfinity()); | ||
// | ||
// beastGompertzGrowth.setInputValue("f0", f0Param); | ||
// beastGompertzGrowth.setInputValue("b", bParam); | ||
// beastGompertzGrowth.setInputValue("NInfinity", NInfinityParam); | ||
// beastGompertzGrowth.initAndValidate(); | ||
// | ||
// return beastGompertzGrowth; | ||
// } | ||
// | ||
// @Override | ||
// public Class<GompertzPopulationFunction> getGeneratorClass() { return GompertzPopulationFunction.class; } | ||
// | ||
// @Override | ||
// public Class<GompertzGrowth> getBEASTClass() { | ||
// return GompertzGrowth.class; | ||
// } | ||
//} |
58 changes: 58 additions & 0 deletions
58
...hybeast/src/main/java/phylonco/lphybeast/tobeast/generators/PopFuncCoalescentToBEAST.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,58 @@ | ||
package phylonco.lphybeast.tobeast.generators; | ||
|
||
import beast.base.core.BEASTInterface; | ||
import beast.base.evolution.tree.TreeIntervals; | ||
import beast.base.evolution.tree.coalescent.ConstantPopulation; | ||
import lphy.base.evolution.coalescent.PopulationFunction; | ||
import lphy.base.evolution.coalescent.PopulationFunctionCoalescent; | ||
import lphy.base.evolution.coalescent.populationmodel.GompertzPopulation; | ||
import lphy.core.model.Value; | ||
import lphybeast.BEASTContext; | ||
import lphybeast.GeneratorToBEAST; | ||
import phylonco.beast.evolution.populationmodel.GompertzGrowth; | ||
|
||
public class PopFuncCoalescentToBEAST implements | ||
GeneratorToBEAST<PopulationFunctionCoalescent, beast.base.evolution.tree.coalescent.Coalescent> { | ||
@Override | ||
public beast.base.evolution.tree.coalescent.Coalescent generatorToBEAST(PopulationFunctionCoalescent coalescent, BEASTInterface value, BEASTContext context) { | ||
|
||
beast.base.evolution.tree.coalescent.Coalescent beastCoalescent = new beast.base.evolution.tree.coalescent.Coalescent(); | ||
|
||
TreeIntervals treeIntervals = new TreeIntervals(); | ||
treeIntervals.setInputValue("tree", value); | ||
treeIntervals.initAndValidate(); | ||
|
||
beastCoalescent.setInputValue("treeIntervals", treeIntervals); | ||
|
||
beast.base.evolution.tree.coalescent.PopulationFunction.Abstract populationFunction; | ||
//TODO why private ? | ||
Value<PopulationFunction> lphyPF = coalescent.getParams().get("popFunc"); | ||
|
||
if (lphyPF.getType().isAssignableFrom(GompertzPopulation.class)) { | ||
|
||
populationFunction = (GompertzGrowth) context.getBEASTObject(lphyPF); | ||
|
||
} else { | ||
// TODO other pop function types | ||
populationFunction = new ConstantPopulation(); | ||
populationFunction.setInputValue("popSize", context.getBEASTObject("TODO")); | ||
populationFunction.initAndValidate(); | ||
} | ||
|
||
beastCoalescent.setInputValue("populationModel", populationFunction); | ||
|
||
beastCoalescent.initAndValidate(); | ||
|
||
return beastCoalescent; | ||
} | ||
|
||
@Override | ||
public Class<PopulationFunctionCoalescent> getGeneratorClass() { | ||
return PopulationFunctionCoalescent.class; | ||
} | ||
|
||
@Override | ||
public Class<beast.base.evolution.tree.coalescent.Coalescent> getBEASTClass() { | ||
return beast.base.evolution.tree.coalescent.Coalescent.class; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...-lphybeast/src/main/java/phylonco/lphybeast/tobeast/values/PopulationFunctionToBEAST.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,49 @@ | ||
package phylonco.lphybeast.tobeast.values; | ||
|
||
import beast.base.inference.parameter.RealParameter; | ||
import lphy.base.evolution.coalescent.PopulationFunction; | ||
import lphy.base.evolution.coalescent.populationmodel.GompertzPopulation; | ||
import lphy.base.evolution.coalescent.populationmodel.GompertzPopulationFunction; | ||
import lphy.core.model.Value; | ||
import lphybeast.BEASTContext; | ||
import lphybeast.ValueToBEAST; | ||
import lphybeast.tobeast.values.ValueToParameter; | ||
import phylonco.beast.evolution.populationmodel.GompertzGrowth; | ||
//TODO exclude | ||
public class PopulationFunctionToBEAST implements ValueToBEAST<PopulationFunction, beast.base.evolution.tree.coalescent.PopulationFunction.Abstract> { | ||
|
||
public beast.base.evolution.tree.coalescent.PopulationFunction.Abstract valueToBEAST(Value<PopulationFunction> lphyPopFuncVal, BEASTContext context) { | ||
beast.base.evolution.tree.coalescent.PopulationFunction.Abstract beastPopFunc; | ||
|
||
if (lphyPopFuncVal.getType().isAssignableFrom(GompertzPopulation.class)) { | ||
|
||
GompertzPopulationFunction gen = (GompertzPopulationFunction) lphyPopFuncVal.getGenerator(); | ||
|
||
RealParameter f0Param = context.getAsRealParameter(gen.getF0()); | ||
RealParameter bParam = context.getAsRealParameter(gen.getB()); | ||
RealParameter NInfinityParam = context.getAsRealParameter(gen.getNInfinity()); | ||
|
||
beastPopFunc = new GompertzGrowth(); | ||
|
||
beastPopFunc.setInputValue("f0", f0Param); | ||
beastPopFunc.setInputValue("b", bParam); | ||
beastPopFunc.setInputValue("NInfinity", NInfinityParam); | ||
beastPopFunc.initAndValidate(); | ||
|
||
ValueToParameter.setID(beastPopFunc, lphyPopFuncVal); | ||
|
||
return beastPopFunc; | ||
} | ||
|
||
throw new UnsupportedOperationException("TODO"); | ||
} | ||
|
||
public Class getValueClass() { | ||
return PopulationFunction.class; | ||
} | ||
|
||
public Class<beast.base.evolution.tree.coalescent.PopulationFunction.Abstract> getBEASTClass() { | ||
return beast.base.evolution.tree.coalescent.PopulationFunction.Abstract.class; | ||
} | ||
|
||
} |
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