diff --git a/phylonco-lphybeast/src/main/java/phylonco/lphybeast/spi/LBPhylonco.java b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/spi/LBPhylonco.java index f160ecc..7c4765d 100644 --- a/phylonco-lphybeast/src/main/java/phylonco/lphybeast/spi/LBPhylonco.java +++ b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/spi/LBPhylonco.java @@ -2,6 +2,8 @@ import beast.base.evolution.datatype.DataType; import jebl.evolution.sequences.SequenceType; +import lphy.base.evolution.coalescent.PopulationFunctionCoalescent; +import lphy.base.evolution.coalescent.populationmodel.GompertzPopulationFunction; import lphy.core.model.Generator; import lphy.core.model.Value; import lphybeast.GeneratorToBEAST; @@ -15,6 +17,8 @@ import phylonco.lphybeast.tobeast.generators.GT16ErrorModelToBEAST; import phylonco.lphybeast.tobeast.generators.GT16ToBEAST; import phylonco.lphybeast.tobeast.generators.GTUnphaseToBEAST; +import phylonco.lphybeast.tobeast.generators.PopFuncCoalescentToBEAST; +import phylonco.lphybeast.tobeast.values.PopulationFunctionToBEAST; import java.util.ArrayList; import java.util.Arrays; @@ -33,14 +37,17 @@ public class LBPhylonco implements LPhyBEASTExt { @Override public List> getValuesToBEASTs() { - return new ArrayList<>(); + return Arrays.asList( + PopulationFunctionToBEAST.class // TODO + ); } @Override public List> getGeneratorToBEASTs() { return Arrays.asList( GT16ErrorModelToBEAST.class, - GT16ToBEAST.class, GTUnphaseToBEAST.class -// GompertzToBEAST.class, LogisticToBEAST.class, PopulationFunctionCoalescentToBEAST.class + GT16ToBEAST.class, GTUnphaseToBEAST.class, + PopFuncCoalescentToBEAST.class//, GompertzToBEAST.class +// , LogisticToBEAST.class, PopulationFunctionCoalescentToBEAST.class ); } @@ -54,7 +61,9 @@ public Map getDataTypeMap() { @Override public List> getExcludedGenerator() { return Arrays.asList(PhasedGenotypeFunction.class, HomozygousAlignmentDistribution.class, - HaploidAlignment.class); + HaploidAlignment.class, + PopulationFunctionCoalescent.class, + GompertzPopulationFunction.class); } @Override diff --git a/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/GompertzToBEAST.java b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/GompertzToBEAST.java index 05a612b..a313edc 100644 --- a/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/GompertzToBEAST.java +++ b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/GompertzToBEAST.java @@ -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 { -// -// -// -// -// - - @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 getGeneratorClass() { - return GompertzGrowth.class; - } - - @Override - public Class 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 { +//// +//// +//// +//// +//// +// +// @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 getGeneratorClass() { return GompertzPopulationFunction.class; } +// +// @Override +// public Class getBEASTClass() { +// return GompertzGrowth.class; +// } +//} diff --git a/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/PopFuncCoalescentToBEAST.java b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/PopFuncCoalescentToBEAST.java new file mode 100644 index 0000000..5802834 --- /dev/null +++ b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/generators/PopFuncCoalescentToBEAST.java @@ -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 { + @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 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 getGeneratorClass() { + return PopulationFunctionCoalescent.class; + } + + @Override + public Class getBEASTClass() { + return beast.base.evolution.tree.coalescent.Coalescent.class; + } +} diff --git a/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/values/PopulationFunctionToBEAST.java b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/values/PopulationFunctionToBEAST.java new file mode 100644 index 0000000..eb3cb7b --- /dev/null +++ b/phylonco-lphybeast/src/main/java/phylonco/lphybeast/tobeast/values/PopulationFunctionToBEAST.java @@ -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 { + + public beast.base.evolution.tree.coalescent.PopulationFunction.Abstract valueToBEAST(Value 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 getBEASTClass() { + return beast.base.evolution.tree.coalescent.PopulationFunction.Abstract.class; + } + +} diff --git a/phylonco-lphybeast/version.xml b/phylonco-lphybeast/version.xml index 8c20e12..f492787 100644 --- a/phylonco-lphybeast/version.xml +++ b/phylonco-lphybeast/version.xml @@ -30,7 +30,7 @@ - +