Search in sources :

Example 1 with PreOrderSettings

use of dr.evomodel.treedatalikelihood.PreOrderSettings in project beast-mcmc by beast-dev.

the class TreeDataLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    boolean useAmbiguities = xo.getAttribute(USE_AMBIGUITIES, false);
    boolean usePreOrder = xo.getAttribute(USE_PREORDER, false);
    boolean branchRateDerivative = xo.getAttribute(BRANCHRATE_DERIVATIVE, usePreOrder);
    boolean branchInfinitesimalDerivative = xo.getAttribute(BRANCHINFINITESIMAL_DERIVATIVE, false);
    if (usePreOrder != (branchRateDerivative || branchInfinitesimalDerivative)) {
        throw new RuntimeException("Need to specify derivative types.");
    }
    PreOrderSettings settings = new PreOrderSettings(usePreOrder, branchRateDerivative, branchInfinitesimalDerivative);
    // TreeDataLikelihood doesn't currently support Instances defined from the command line
    // int instanceCount = xo.getAttribute(INSTANCE_COUNT, 1);
    // if (instanceCount < 1) {
    // instanceCount = 1;
    // }
    // 
    // String ic = System.getProperty(BEAGLE_INSTANCE_COUNT);
    // if (ic != null && ic.length() > 0) {
    // instanceCount = Integer.parseInt(ic);
    // }
    List<PatternList> patternLists = new ArrayList<PatternList>();
    List<SiteRateModel> siteRateModels = new ArrayList<SiteRateModel>();
    List<BranchModel> branchModels = new ArrayList<BranchModel>();
    boolean hasSinglePartition = false;
    PatternList patternList = (PatternList) xo.getChild(PatternList.class);
    if (patternList != null) {
        hasSinglePartition = true;
        patternLists.add(patternList);
        GammaSiteRateModel siteRateModel = (GammaSiteRateModel) xo.getChild(GammaSiteRateModel.class);
        siteRateModels.add(siteRateModel);
        FrequencyModel rootFreqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
        BranchModel branchModel = (BranchModel) xo.getChild(BranchModel.class);
        if (branchModel == null) {
            SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
            if (substitutionModel == null) {
                substitutionModel = siteRateModel.getSubstitutionModel();
            }
            if (substitutionModel == null) {
                throw new XMLParseException("No substitution model available for partition in DataTreeLikelihood: " + xo.getId());
            }
            branchModel = new HomogeneousBranchModel(substitutionModel, rootFreqModel);
        }
        branchModels.add(branchModel);
    }
    int k = 0;
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChildName(i).equals(PARTITION)) {
            if (hasSinglePartition) {
                throw new XMLParseException("Either a single set of patterns should be given or multiple 'partitions' elements within DataTreeLikelihood: " + xo.getId());
            }
            k += 1;
            XMLObject cxo = (XMLObject) xo.getChild(i);
            patternList = (PatternList) cxo.getChild(PatternList.class);
            patternLists.add(patternList);
            GammaSiteRateModel siteRateModel = (GammaSiteRateModel) cxo.getChild(GammaSiteRateModel.class);
            siteRateModels.add(siteRateModel);
            FrequencyModel rootFreqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
            BranchModel branchModel = (BranchModel) cxo.getChild(BranchModel.class);
            if (branchModel == null) {
                SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
                if (substitutionModel == null) {
                    substitutionModel = siteRateModel.getSubstitutionModel();
                }
                if (substitutionModel == null) {
                    throw new XMLParseException("No substitution model available for partition " + k + " in DataTreeLikelihood: " + xo.getId());
                }
                branchModel = new HomogeneousBranchModel(substitutionModel, rootFreqModel);
            }
            branchModels.add(branchModel);
            BranchRateModel branchRateModel = (BranchRateModel) cxo.getChild(BranchRateModel.class);
            if (branchRateModel != null) {
                throw new XMLParseException("Partitions are not currently allowed their own BranchRateModel in TreeDataLikelihood object '" + xo.getId());
            }
        }
    }
    if (patternLists.size() == 0) {
        throw new XMLParseException("Either a single set of patterns should be given or multiple 'partitions' elements within DataTreeLikelihood: " + xo.getId());
    }
    Tree treeModel = (Tree) xo.getChild(Tree.class);
    BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    if (branchRateModel == null) {
        throw new XMLParseException("BranchRateModel missing from TreeDataLikelihood object '" + xo.getId());
    // branchRateModel = new DefaultBranchRateModel();
    }
    TipStatesModel tipStatesModel = (TipStatesModel) xo.getChild(TipStatesModel.class);
    final boolean preferGPU = xo.getAttribute(PREFER_GPU, false);
    PartialsRescalingScheme scalingScheme = PartialsRescalingScheme.DEFAULT;
    if (xo.hasAttribute(SCALING_SCHEME)) {
        scalingScheme = PartialsRescalingScheme.parseFromString(xo.getStringAttribute(SCALING_SCHEME));
        if (scalingScheme == null)
            throw new XMLParseException("Unknown scaling scheme '" + xo.getStringAttribute(SCALING_SCHEME) + "' in " + "TreeDataLikelihood object '" + xo.getId());
    }
    final boolean delayScaling = xo.getAttribute(DELAY_SCALING, true);
    if (tipStatesModel != null) {
        throw new XMLParseException("BEAGLE_INSTANCES option cannot be used with a TipStateModel (i.e., a sequence error model).");
    }
    return createTreeDataLikelihood(patternLists, branchModels, siteRateModels, treeModel, branchRateModel, null, useAmbiguities, preferGPU, scalingScheme, delayScaling, settings);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) PatternList(dr.evolution.alignment.PatternList) ArrayList(java.util.ArrayList) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) PartialsRescalingScheme(dr.evomodel.treelikelihood.PartialsRescalingScheme) BranchModel(dr.evomodel.branchmodel.BranchModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) SiteRateModel(dr.evomodel.siteratemodel.SiteRateModel) TipStatesModel(dr.evomodel.tipstatesmodel.TipStatesModel) PreOrderSettings(dr.evomodel.treedatalikelihood.PreOrderSettings) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) Tree(dr.evolution.tree.Tree)

Aggregations

PatternList (dr.evolution.alignment.PatternList)1 Tree (dr.evolution.tree.Tree)1 BranchModel (dr.evomodel.branchmodel.BranchModel)1 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)1 SiteRateModel (dr.evomodel.siteratemodel.SiteRateModel)1 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 TipStatesModel (dr.evomodel.tipstatesmodel.TipStatesModel)1 PreOrderSettings (dr.evomodel.treedatalikelihood.PreOrderSettings)1 PartialsRescalingScheme (dr.evomodel.treelikelihood.PartialsRescalingScheme)1 ArrayList (java.util.ArrayList)1