Skip to content

Commit

Permalink
init dev version #55
Browse files Browse the repository at this point in the history
  • Loading branch information
walterxie committed Apr 15, 2024
1 parent 2b3ff72 commit 455d55d
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -33,14 +37,17 @@ public class LBPhylonco implements LPhyBEASTExt {

@Override
public List<Class<? extends ValueToBEAST>> getValuesToBEASTs() {
return new ArrayList<>();
return Arrays.asList(
PopulationFunctionToBEAST.class // TODO
);
}

@Override
public List<Class<? extends GeneratorToBEAST>> 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
);
}

Expand All @@ -54,7 +61,9 @@ public Map<SequenceType, DataType> getDataTypeMap() {
@Override
public List<Class<? extends Generator>> getExcludedGenerator() {
return Arrays.asList(PhasedGenotypeFunction.class, HomozygousAlignmentDistribution.class,
HaploidAlignment.class);
HaploidAlignment.class,
PopulationFunctionCoalescent.class,
GompertzPopulationFunction.class);
}

@Override
Expand Down
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;
// }
//}
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;
}
}
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;
}

}
2 changes: 1 addition & 1 deletion phylonco-lphybeast/version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<provider classname="phylonco.beast.evolution.substitutionmodel.MethylationHKY"/>
<provider classname="phylonco.beast.evolution.substitutionmodel.SiFit2"/>
<provider classname="phylonco.beast.evolution.substitutionmodel.SiFit3"/>
<!-- <provider classname="phylonco.beast.evolution.populationmodel.GompertzGrowth"/>-->
<provider classname="phylonco.beast.evolution.populationmodel.GompertzGrowth"/>
<!-- <provider classname="phylonco.beast.evolution.populationmodel.ExponentialGrowth"/>-->
</service>

Expand Down

0 comments on commit 455d55d

Please sign in to comment.