/* * TransmissionTreeOperator.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.evomodel.epidemiology.casetocase.operators; import dr.evolution.tree.NodeRef; import dr.evomodel.epidemiology.casetocase.AbstractCase; import dr.evomodel.epidemiology.casetocase.BranchMapModel; import dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood; import dr.evomodel.operators.AbstractTreeOperator; import dr.evomodel.operators.ExchangeOperator; import dr.evomodel.operators.SubtreeSlideOperator; import dr.evomodel.operators.WilsonBalding; import dr.evomodel.tree.TreeModel; import dr.inference.operators.AbstractAdaptableOperator; import dr.inference.operators.AdaptableMCMCOperator; import dr.inference.operators.AdaptationMode; import dr.xml.*; import java.util.ArrayList; /** * An operator that wraps a (phylogenetic) tree operator and adjusts the transmission tree accordingly. Only works * for the simpler (TT=TMRCA) version of the transmission tree (suitable for birth-death models and their derivatives). * TT moves are deterministic, so the Hastings ratios reported by the inner operators are not affected. * * @author Matthew Hall */ public class TransmissionTreeOperator extends AbstractAdaptableOperator { private final CaseToCaseTreeLikelihood c2cLikelihood; private final AbstractTreeOperator innerOperator; public static final String TRANSMISSION_TREE_OPERATOR = "transmissionTreeOperator"; public TransmissionTreeOperator(CaseToCaseTreeLikelihood c2cLikelihood, AbstractTreeOperator operator, AdaptationMode mode) { super(mode); this.c2cLikelihood = c2cLikelihood; this.innerOperator = operator; this.setWeight(innerOperator.getWeight()); // this doesn't work at all right now - it awaits the restoration of the TT=TMRCA version throw new RuntimeException("TransmissionTreeOperator only works on non-extended tree paintings"); } public TransmissionTreeOperator(CaseToCaseTreeLikelihood c2cLikelihood, AbstractTreeOperator operator) { this(c2cLikelihood,operator, AdaptationMode.ADAPTATION_OFF); } public double doOperation() { TreeModel tree = c2cLikelihood.getTreeModel(); BranchMapModel branchMap = c2cLikelihood.getBranchMap(); AbstractCase[] newBranchMap = branchMap.getArrayCopy(); int[] oldParents = getParentsArray(tree); double[] oldHeights = getHeightsArray(tree); double hr = innerOperator.doOperation(); int[] newParents = getParentsArray(tree); ArrayList changedNodes = new ArrayList(); for(int i=0; i