Debian Codegraph @

src/dr/evomodelxml/treelikelihood/ALSTreeLikelihoodParser.java

raw symbols SCIP
1 /*
2 * ALSTreeLikelihoodParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evomodelxml.treelikelihood;
27
28 import dr.evolution.alignment.PatternList;
29 import dr.evolution.util.Taxon;
30 import dr.oldevomodel.MSSD.ALSTreeLikelihood;
31 import dr.oldevomodel.MSSD.AbstractObservationProcess;
32 import dr.oldevomodel.MSSD.AnyTipObservationProcess;
33 import dr.oldevomodel.MSSD.SingleTipObservationProcess;
34 import dr.evomodel.branchratemodel.BranchRateModel;
35 import dr.oldevomodel.sitemodel.SiteModel;
36 import dr.oldevomodel.substmodel.MutationDeathModel;
37 import dr.evomodel.tree.TreeModel;
38 import dr.oldevomodelxml.treelikelihood.TreeLikelihoodParser;
39 import dr.inference.model.Parameter;
40 import dr.xml.*;
41
42 import java.util.logging.Logger;
43
44 /**
45 *
46 */
47 public class ALSTreeLikelihoodParser extends AbstractXMLObjectParser {
48 public static final String LIKE_NAME = "alsTreeLikelihood";
49 public static final String INTEGRATE_GAIN_RATE = "integrateGainRate";
50 public static final String OBSERVATION_PROCESS = "observationProcess";
51 public static final String OBSERVATION_TYPE = "type";
52 public static final String OBSERVATION_TAXON = "taxon";
53 public static final String ANY_TIP = "anyTip";
54 public final static String IMMIGRATION_RATE = "immigrationRate";
55 public static final String FORCE_RESCALING = TreeLikelihoodParser.FORCE_RESCALING;
56
57 public String getParserName() {
58 return LIKE_NAME;
59 }
60
61 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
62
63 boolean useAmbiguities = false;
64 boolean storePartials = true;
65 if (xo.hasAttribute(TreeLikelihoodParser.USE_AMBIGUITIES)) {
66 useAmbiguities = xo.getBooleanAttribute(TreeLikelihoodParser.USE_AMBIGUITIES);
67 }
68 if (xo.hasAttribute(TreeLikelihoodParser.STORE_PARTIALS)) {
69 storePartials = xo.getBooleanAttribute(TreeLikelihoodParser.STORE_PARTIALS);
70 }
71
72 boolean integrateGainRate = xo.getBooleanAttribute(INTEGRATE_GAIN_RATE);
73
74 //AbstractObservationProcess observationProcess = (AbstractObservationProcess) xo.getChild(AbstractObservationProcess.class);
75
76
77 PatternList patternList = (PatternList) xo.getChild(PatternList.class);
78 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
79 SiteModel siteModel = (SiteModel) xo.getChild(SiteModel.class);
80 BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
81 Parameter mu = ((MutationDeathModel) siteModel.getSubstitutionModel()).getDeathParameter();
82 Parameter lam;
83 if (!integrateGainRate) {
84 lam = (Parameter) xo.getElementFirstChild(IMMIGRATION_RATE);
85 } else {
86 lam = new Parameter.Default("gainRate", 1.0, 0.001, 1.999);
87 }
88 AbstractObservationProcess observationProcess = null;
89
90 Logger.getLogger("dr.evolution").info("\n ---------------------------------\nCreating ALSTreeLikelihood model.");
91 for (int i = 0; i < xo.getChildCount(); ++i) {
92 Object cxo = xo.getChild(i);
93 if (cxo instanceof XMLObject && ((XMLObject) cxo).getName().equals(OBSERVATION_PROCESS)) {
94 if (((XMLObject) cxo).getStringAttribute(OBSERVATION_TYPE).equals("singleTip")) {
95 String taxonName = ((XMLObject) cxo).getStringAttribute(OBSERVATION_TAXON);
96 Taxon taxon = treeModel.getTaxon(treeModel.getTaxonIndex(taxonName));
97 observationProcess = new SingleTipObservationProcess(treeModel, patternList, siteModel,
98 branchRateModel, mu, lam, taxon);
99 Logger.getLogger("dr.evolution").info("All traits are assumed extant in " + taxonName);
100 } else { // "anyTip" observation process
101 observationProcess = new AnyTipObservationProcess(ANY_TIP, treeModel, patternList,
102 siteModel, branchRateModel, mu, lam);
103 Logger.getLogger("dr.evolution").info("Observed traits are assumed to be extant in at least one tip node.");
104 }
105
106 observationProcess.setIntegrateGainRate(integrateGainRate);
107 }
108 }
109 Logger.getLogger("dr.evolution").info("\tIf you publish results using Acquisition-Loss-Mutation (ALS) Model likelihood, please reference Alekseyenko, Lee and Suchard (2008) Syst. Biol 57: 772-784.\n---------------------------------\n");
110
111 boolean forceRescaling = xo.getAttribute(FORCE_RESCALING, false);
112
113 // forceRescaling = true;
114
115 return new ALSTreeLikelihood(observationProcess, patternList, treeModel, siteModel, branchRateModel,
116 useAmbiguities, storePartials, forceRescaling);
117 }
118
119 //************************************************************************
120 // AbstractXMLObjectParser implementation
121 //************************************************************************
122
123 public String getParserDescription() {
124 return "This element represents the likelihood of a patternlist on a tree given the site model.";
125 }
126
127 public Class getReturnType() {
128 return ALSTreeLikelihood.class;
129 }
130
131 public XMLSyntaxRule[] getSyntaxRules() {
132 return rules;
133 }
134
135 private final XMLSyntaxRule[] rules = {
136 AttributeRule.newBooleanRule(TreeLikelihoodParser.USE_AMBIGUITIES, true),
137 AttributeRule.newBooleanRule(TreeLikelihoodParser.STORE_PARTIALS, true),
138 AttributeRule.newBooleanRule(INTEGRATE_GAIN_RATE),
139 AttributeRule.newBooleanRule(FORCE_RESCALING, true),
140 new ElementRule(IMMIGRATION_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true),
141 new ElementRule(PatternList.class),
142 new ElementRule(TreeModel.class),
143 new ElementRule(SiteModel.class),
144 new ElementRule(BranchRateModel.class, true),
145 new ElementRule(OBSERVATION_PROCESS,
146 new XMLSyntaxRule[]{AttributeRule.newStringRule(OBSERVATION_TYPE, false),
147 AttributeRule.newStringRule(OBSERVATION_TAXON, true)})
148 //new ElementRule(AbstractObservationProcess.class)
149 };
150
151 }