use of dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel in project beast-mcmc by beast-dev.
the class ArbitrarySubstitutionParameterBranchModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Logger.getLogger("dr.evomodel").info("\nUsing branch-specific substitution parameter branch model.");
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
if (!(substitutionModel instanceof ParameterReplaceableSubstitutionModel)) {
throw new RuntimeException("The substitution model is not parameter replaceable!");
}
XMLObject cxo = xo.getChild(BRANCH_SPECIFIC_PARAMETER);
// XMLObject dxo = xo.getChild(SINGLE_RATE);
BranchSpecificSubstitutionModelProvider substitutionModelProvider;
ArbitrarySubstitutionParameterBranchModel branchParameterModel;
// assert (dxo.getChildCount() == cxo.getChildCount());
List<Parameter> oldParameters = new ArrayList<Parameter>();
List<BranchParameter> parameterList = new ArrayList<BranchParameter>();
for (int i = 0; i < cxo.getChildCount(); i++) {
// Parameter rootParameter = (Parameter) dxo.getChild(i);
// ArbitraryBranchRates branchRateModel = (ArbitraryBranchRates) cxo.getChild(i);
// BranchParameter branchParameter = new BranchParameter("branchSpecific.substitution.parameter",
// tree,
// branchRateModel,
// rootParameter);
// branchParameter.setId("branchSpecific." + rootParameter.getId());
// parameterList.add(branchParameter);
// xo.setNativeObject(branchParameter);
BranchParameter branchParameter = (BranchParameter) cxo.getChild(i);
parameterList.add(branchParameter);
oldParameters.add(branchParameter.getRootParameter());
}
List<SubstitutionModel> substitutionModelList = new ArrayList<SubstitutionModel>();
ParameterReplaceableSubstitutionModel rootSubstitutionModel = (ParameterReplaceableSubstitutionModel) substitutionModel;
// List<Parameter> oldParameters = parseParameters(dxo);
// List<Parameter> branchParameters = parseParameters(cxo);
final int parameterCount = parameterList.size();
int v = 0;
for (int nodeNum = 0; nodeNum < tree.getNodeCount(); ++nodeNum) {
NodeRef node = tree.getNode(nodeNum);
ParameterReplaceableSubstitutionModel branchSubstitutionModel = (ParameterReplaceableSubstitutionModel) substitutionModel;
List<Parameter> newParameters = new ArrayList<Parameter>();
if (tree.isRoot(node)) {
for (int i = 0; i < parameterCount; i++) {
BranchParameter branchParameter = parameterList.get(i);
newParameters.add(branchParameter.getRootParameter());
}
} else {
for (int i = 0; i < parameterCount; i++) {
BranchParameter branchParameter = parameterList.get(i);
newParameters.add(branchParameter.getParameter(v));
}
v++;
}
branchSubstitutionModel = branchSubstitutionModel.factory(oldParameters, newParameters);
substitutionModelList.add(branchSubstitutionModel);
}
substitutionModelProvider = new BranchSpecificSubstitutionModelProvider.Default(substitutionModelList, tree);
branchParameterModel = new ArbitrarySubstitutionParameterBranchModel(ARBITRARY_SUBSTITUTION_PARAMETER_BRANCH_MODEL, substitutionModelProvider, parameterList, tree);
return branchParameterModel;
}
use of dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel in project beast-mcmc by beast-dev.
the class BranchSpecificSubstitutionParameterBranchModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
List<Parameter> parameters = new ArrayList<>();
for (XMLObject xoc : xo.getAllChildren(OLD_PARAMETER)) {
Parameter parameter = (Parameter) xoc.getChild(Parameter.class);
parameters.add(parameter);
}
List<BranchRateModel> branchRateModels = new ArrayList<>();
for (XMLObject xoc : xo.getAllChildren(NEW_PARAMETER)) {
BranchRateModel branchRateModel = (BranchRateModel) xoc.getChild(BranchRateModel.class);
branchRateModels.add(branchRateModel);
}
ParameterReplaceableSubstitutionModel substitutionModel = (ParameterReplaceableSubstitutionModel) xo.getChild(ParameterReplaceableSubstitutionModel.class);
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
return new BranchSpecificSubstitutionParameterBranchModel(BRANCH_SPECIFIC_SUBSTITUTION_PARAMETER_BRANCH_MODEL, parameters, branchRateModels, substitutionModel, tree);
}
Aggregations