Search in sources :

Example 1 with BranchSpecificSubstitutionModelProvider

use of dr.evomodel.substmodel.BranchSpecificSubstitutionModelProvider 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;
}
Also used : BranchParameter(dr.inference.model.BranchParameter) ParameterReplaceableSubstitutionModel(dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel) ArrayList(java.util.ArrayList) BranchSpecificSubstitutionModelProvider(dr.evomodel.substmodel.BranchSpecificSubstitutionModelProvider) ParameterReplaceableSubstitutionModel(dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) TreeModel(dr.evomodel.tree.TreeModel) NodeRef(dr.evolution.tree.NodeRef) ArbitrarySubstitutionParameterBranchModel(dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel) Parameter(dr.inference.model.Parameter) BranchParameter(dr.inference.model.BranchParameter)

Aggregations

NodeRef (dr.evolution.tree.NodeRef)1 ArbitrarySubstitutionParameterBranchModel (dr.evomodel.branchmodel.ArbitrarySubstitutionParameterBranchModel)1 BranchSpecificSubstitutionModelProvider (dr.evomodel.substmodel.BranchSpecificSubstitutionModelProvider)1 ParameterReplaceableSubstitutionModel (dr.evomodel.substmodel.ParameterReplaceableSubstitutionModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 TreeModel (dr.evomodel.tree.TreeModel)1 BranchParameter (dr.inference.model.BranchParameter)1 Parameter (dr.inference.model.Parameter)1 ArrayList (java.util.ArrayList)1