| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 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 { |
| 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 |
|
| 114 |
|
| 115 |
return new ALSTreeLikelihood(observationProcess, patternList, treeModel, siteModel, branchRateModel, |
| 116 |
useAmbiguities, storePartials, forceRescaling); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 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 |
|
| 149 |
}; |
| 150 |
|
| 151 |
} |