Skip to content

Commit

Permalink
Merge pull request #65 from bioDS/svs_lphybeast
Browse files Browse the repository at this point in the history
Merge Stochastic Variable Selection lphybeast
  • Loading branch information
yxu927 authored Jul 16, 2024
2 parents a9a2bac + dc747ba commit 08d2702
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package phylonco.lphybeast.tobeast.values;

import beast.base.inference.parameter.RealParameter;
import lphy.base.evolution.coalescent.PopulationFunction;
import lphy.base.evolution.coalescent.populationmodel.SVSFunction;
import lphy.base.evolution.coalescent.populationmodel.SVSPopulationFunction;
import lphy.core.model.GraphicalModelNode;
import lphy.core.model.Value;
import lphybeast.BEASTContext;
import lphybeast.ValueToBEAST;
import lphybeast.tobeast.values.ValueToParameter;
import phylonco.beast.evolution.populationmodel.StochasticVariableSelection;

public class SVSPopulationFunctionToBEAST implements ValueToBEAST<SVSPopulationFunction, StochasticVariableSelection> {

@Override
public StochasticVariableSelection valueToBEAST(Value<SVSPopulationFunction> lphyPopFuncVal, BEASTContext context) {

StochasticVariableSelection beastPopFunc = new StochasticVariableSelection();

SVSFunction gen = (SVSFunction) lphyPopFuncVal.getGenerator();


RealParameter indicatorParam = context.getAsRealParameter(gen.getIndicator());
Value<PopulationFunction[]> modelsValue = gen.getModels();
Object[] modelsObjArray = modelsValue.value();

PopulationFunction[] modelsArray = new PopulationFunction[modelsObjArray.length];
for (int i = 0; i < modelsArray.length; i++) {
modelsArray[i] = (PopulationFunction) modelsObjArray[i];
}

beast.base.evolution.tree.coalescent.PopulationFunction[] modelFuncs = new beast.base.evolution.tree.coalescent.PopulationFunction[modelsArray.length];

for (int i = 0; i < modelsArray.length; i++) {
String modelName = gen.MODELS_PARAM_NAME;
GraphicalModelNode node = (GraphicalModelNode) (gen.getParams().get(modelName).getInputs().get(0));
Object contextObj = context.getBEASTObject((Value) node.getInputs().get(i));
beast.base.evolution.tree.coalescent.PopulationFunction beastPopFunction;
beastPopFunction = (beast.base.evolution.tree.coalescent.PopulationFunction) contextObj;
modelFuncs[i] = beastPopFunction;
}


beastPopFunc.setInputValue("indicator", indicatorParam);
beastPopFunc.setInputValue("models", modelFuncs);
beastPopFunc.initAndValidate();

ValueToParameter.setID(beastPopFunc, lphyPopFuncVal);

return beastPopFunc;
}

@Override
public Class getValueClass() {
return SVSPopulationFunction.class;
}

@Override
public Class<StochasticVariableSelection> getBEASTClass() {
return StochasticVariableSelection.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public StochasticVariableSelection valueToBEAST(Value<SVSFunction> lphyPopFuncVa
beast.base.evolution.tree.coalescent.PopulationFunction[] modelFuncs = new beast.base.evolution.tree.coalescent.PopulationFunction[modelsArray.length];

for (int i = 0; i < modelsArray.length; i++) {
modelFuncs[i] = (beast.base.evolution.tree.coalescent.PopulationFunction) context.getBEASTObject(new Value<>(modelsArray[i], gen));
modelFuncs[i] = (beast.base.evolution.tree.coalescent.PopulationFunction) context.getBEASTObject(new Value<>(null, modelsArray[i]));
}

// Create and return the StochasticVariableSelection instance with the converted models
Expand Down
2 changes: 2 additions & 0 deletions phylonco-lphybeast/version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<provider classname="phylonco.beast.evolution.populationmodel.LogisticGrowth"/>
<provider classname="phylonco.beast.evolution.populationmodel.GompertzGrowth_t50"/>
<provider classname="phylonco.beast.evolution.populationmodel.ConstantGrowth"/>
<provider classname="phylonco.beast.evolution.populationmodel.StochasticVariableSelection"/>


</service>

Expand Down

0 comments on commit 08d2702

Please sign in to comment.