-
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.
Merge pull request #65 from bioDS/svs_lphybeast
Merge Stochastic Variable Selection lphybeast
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...hybeast/src/main/java/phylonco/lphybeast/tobeast/values/SVSPopulationFunctionToBEAST.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,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; | ||
} | ||
} |
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
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