Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Stochastic Variable Selection lphybeast #65

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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