Search in sources :

Example 1 with MultiLociTreeSet

use of dr.evomodel.coalescent.MultiLociTreeSet in project beast-mcmc by beast-dev.

the class CoalescentLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(MODEL);
    DemographicModel demoModel = (DemographicModel) cxo.getChild(DemographicModel.class);
    List<TreeModel> trees = new ArrayList<TreeModel>();
    List<Double> popFactors = new ArrayList<Double>();
    MultiLociTreeSet treesSet = demoModel instanceof MultiLociTreeSet ? (MultiLociTreeSet) demoModel : null;
    for (int k = 0; k < xo.getChildCount(); ++k) {
        final Object child = xo.getChild(k);
        if (child instanceof XMLObject) {
            cxo = (XMLObject) child;
            if (cxo.getName().equals(POPULATION_TREE)) {
                final TreeModel t = (TreeModel) cxo.getChild(TreeModel.class);
                assert t != null;
                trees.add(t);
                popFactors.add(cxo.getAttribute(POPULATION_FACTOR, 1.0));
            }
        }
    //                in the future we may have arbitrary multi-loci element
    //                else if( child instanceof MultiLociTreeSet )  {
    //                    treesSet = (MultiLociTreeSet)child;
    //                }
    }
    TreeModel treeModel = null;
    if (trees.size() == 1 && popFactors.get(0) == 1.0) {
        treeModel = trees.get(0);
    } else if (trees.size() > 1) {
        treesSet = new MultiLociTreeSet.Default(trees, popFactors);
    } else if (!(trees.size() == 0 && treesSet != null)) {
        throw new XMLParseException("Incorrectly constructed likelihood element");
    }
    TaxonList includeSubtree = null;
    if (xo.hasChildNamed(INCLUDE)) {
        includeSubtree = (TaxonList) xo.getElementFirstChild(INCLUDE);
    }
    List<TaxonList> excludeSubtrees = new ArrayList<TaxonList>();
    if (xo.hasChildNamed(EXCLUDE)) {
        cxo = xo.getChild(EXCLUDE);
        for (int i = 0; i < cxo.getChildCount(); i++) {
            excludeSubtrees.add((TaxonList) cxo.getChild(i));
        }
    }
    if (treeModel != null) {
        try {
            return new CoalescentLikelihood(treeModel, includeSubtree, excludeSubtrees, demoModel);
        } catch (TreeUtils.MissingTaxonException mte) {
            throw new XMLParseException("treeModel missing a taxon from taxon list in " + getParserName() + " element");
        }
    } else {
        if (includeSubtree != null || excludeSubtrees.size() > 0) {
            throw new XMLParseException("Include/Exclude taxa not supported for multi locus sets");
        }
        // a base - and modifing it will probsbly result in a bigger mess.
        return new OldAbstractCoalescentLikelihood(treesSet, demoModel);
    }
}
Also used : TaxonList(dr.evolution.util.TaxonList) ArrayList(java.util.ArrayList) DemographicModel(dr.evomodel.coalescent.DemographicModel) TreeModel(dr.evomodel.tree.TreeModel) CoalescentLikelihood(dr.evomodel.coalescent.CoalescentLikelihood) OldAbstractCoalescentLikelihood(dr.evomodel.coalescent.OldAbstractCoalescentLikelihood) OldAbstractCoalescentLikelihood(dr.evomodel.coalescent.OldAbstractCoalescentLikelihood) MultiLociTreeSet(dr.evomodel.coalescent.MultiLociTreeSet) TreeUtils(dr.evolution.tree.TreeUtils)

Aggregations

TreeUtils (dr.evolution.tree.TreeUtils)1 TaxonList (dr.evolution.util.TaxonList)1 CoalescentLikelihood (dr.evomodel.coalescent.CoalescentLikelihood)1 DemographicModel (dr.evomodel.coalescent.DemographicModel)1 MultiLociTreeSet (dr.evomodel.coalescent.MultiLociTreeSet)1 OldAbstractCoalescentLikelihood (dr.evomodel.coalescent.OldAbstractCoalescentLikelihood)1 TreeModel (dr.evomodel.tree.TreeModel)1 ArrayList (java.util.ArrayList)1