/* * MixtureModelBranchRatesParser.java * * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard * * This file is part of BEAST. * See the NOTICE file distributed with this work for additional * information regarding copyright ownership and licensing. * * BEAST is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * BEAST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BEAST; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ package dr.evomodelxml.branchratemodel; import dr.evomodel.branchratemodel.MixtureModelBranchRates; import dr.evomodel.tree.TreeModel; import dr.inference.distribution.ParametricDistributionModel; import dr.inference.model.Parameter; import dr.xml.*; import java.util.logging.Logger; import java.util.ArrayList; /** * @author Wai Lok Sibon Li */ public class MixtureModelBranchRatesParser extends AbstractXMLObjectParser { public static final String MIXTURE_MODEL_BRANCH_RATES = "mixtureModelBranchRates"; public static final String DISTRIBUTION = "distribution"; public static final String RATE_CATEGORY_QUANTILES = "rateCategoryQuantiles"; public static final String SINGLE_ROOT_RATE = "singleRootRate"; public static final String NORMALIZE = "normalize"; public static final String NORMALIZE_BRANCH_RATE_TO = "normalizeBranchRateTo"; public static final String DISTRIBUTION_INDEX = "distributionIndex"; public static final String USE_QUANTILE = "useQuantilesForRates"; //public static final String NORMALIZED_MEAN = "normalizedMean"; public String getParserName() { return MIXTURE_MODEL_BRANCH_RATES; } public Object parseXMLObject(XMLObject xo) throws XMLParseException { ArrayList modelsList = new ArrayList(); final boolean normalize = xo.getAttribute(NORMALIZE, false); final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_BRANCH_RATE_TO, Double.NaN); final boolean useQuantilesForRates = xo.getAttribute(USE_QUANTILE, true); TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); //while (xo.hasChildNamed(DISTRIBUTION)) { for (int i = 0; i < xo.getChildCount(); i++) { Object child = xo.getChild(i); if( child instanceof XMLObject ) { if( ((XMLObject) child).getName().equals(DISTRIBUTION) ) { XMLObject childXML = (XMLObject) child; modelsList.add((ParametricDistributionModel) childXML.getChild(0)); } } } //Parameter rateCategoryParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORIES); ParametricDistributionModel[] models = modelsList.toArray(new ParametricDistributionModel[modelsList.size()]); Parameter rateCategoryQuantilesParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORY_QUANTILES); Parameter distributionIndexParameter = (Parameter) xo.getElementFirstChild(DISTRIBUTION_INDEX); Logger.getLogger("dr.evomodel").info("Using random discretized relaxed clock model with a mixture distribution."); for(int i=0; i