Debian Codegraph @

src/dr/app/beauti/options/PartitionSubstitutionModel.java

raw symbols SCIP
1 /*
2 * PartitionSubstitutionModel.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.app.beauti.options;
27
28 import dr.evomodel.substmodel.aminoacid.AminoAcidModelType;
29 import dr.evomodel.substmodel.nucleotide.NucModelType;
30 import dr.app.beauti.components.continuous.ContinuousSubstModelType;
31 import dr.app.beauti.components.discrete.DiscreteSubstModelType;
32 import dr.app.beauti.types.*;
33 import dr.evolution.datatype.AminoAcids;
34 import dr.evolution.datatype.DataType;
35 import dr.evolution.datatype.Microsatellite;
36 import dr.evolution.datatype.Nucleotides;
37
38 import java.util.ArrayList;
39 import java.util.HashSet;
40 import java.util.List;
41 import java.util.Set;
42
43 /**
44 * @author Alexei Drummond
45 * @author Andrew Rambaut
46 * @author Walter Xie
47 */
48 public class PartitionSubstitutionModel extends PartitionOptions {
49 private static final long serialVersionUID = -2570346396317131108L;
50
51 // Instance variables
52
53 public static final String GTR_RATES = "gtr.rates";
54 public static final String[] GTR_RATE_NAMES = {"gtr.AC", "gtr.AG", "gtr.AT", "gtr.CG", "gtr.GT"};
55 private static final String[] GTR_TRANSITIONS = {"A-C", "A-G", "A-T", "C-G", "G-T"};
56
57 private NucModelType nucSubstitutionModel = NucModelType.HKY;
58 private AminoAcidModelType aaSubstitutionModel = AminoAcidModelType.BLOSUM_62;
59 private BinaryModelType binarySubstitutionModel = BinaryModelType.BIN_SIMPLE;
60 private DiscreteSubstModelType discreteSubstType = DiscreteSubstModelType.SYM_SUBST;
61 private ContinuousSubstModelType continuousSubstModelType = ContinuousSubstModelType.HOMOGENOUS;
62
63 private final int continuousTraitCount;
64
65 private final TraitData traitData;
66
67 private boolean activateBSSVS = false;
68 public boolean useAmbiguitiesTreeLikelihood = false;
69
70 private FrequencyPolicyType frequencyPolicy = FrequencyPolicyType.ESTIMATED;
71 private boolean gammaHetero = false;
72 private int gammaCategories = 4;
73 private boolean invarHetero = false;
74 private String codonHeteroPattern = null;
75 private boolean unlinkedSubstitutionModel = true;
76 private boolean unlinkedHeterogeneityModel = true;
77 private boolean unlinkedFrequencyModel = true;
78
79 private boolean dolloModel = false;
80
81 private MicroSatModelType.RateProportionality ratePorportion = MicroSatModelType.RateProportionality.EQUAL_RATE;
82 private MicroSatModelType.MutationalBias mutationBias = MicroSatModelType.MutationalBias.UNBIASED;
83 private MicroSatModelType.Phase phase = MicroSatModelType.Phase.ONE_PHASE;
84 private Microsatellite microsatellite = null;
85 private boolean isLatitudeLongitude = false;
86 private double jitterWindow = 0.0;
87
88 public TraitData getTraitData() {
89 return traitData;
90 }
91
92 public PartitionSubstitutionModel(BeautiOptions options, String name, AbstractPartitionData partition) {
93 super(options, name);
94
95 if (partition.getTraits() != null && partition.getDataType().getType() == DataType.CONTINUOUS) {
96 continuousTraitCount = partition.getTraits().size();
97 } else {
98 continuousTraitCount = 0;
99 }
100
101 if (partition.getTraits() != null && partition.getDataType().getType() == DataType.GENERAL) {
102 traitData = partition.getTraits().get(0);
103 } else {
104 traitData = null;
105 }
106
107 initModelParametersAndOpererators();
108 }
109
110 /**
111 * A copy constructor
112 *
113 * @param options the beauti options
114 * @param name the name of the new model
115 * @param source the source model
116 */
117 public PartitionSubstitutionModel(BeautiOptions options, String name, PartitionSubstitutionModel source) {
118 super(options, name);
119
120 nucSubstitutionModel = source.nucSubstitutionModel;
121 aaSubstitutionModel = source.aaSubstitutionModel;
122 binarySubstitutionModel = source.binarySubstitutionModel;
123 discreteSubstType = source.discreteSubstType;
124 continuousSubstModelType = source.continuousSubstModelType;
125
126 continuousTraitCount = source.continuousTraitCount;
127
128 traitData = source.traitData;
129
130 activateBSSVS = source.activateBSSVS;
131 useAmbiguitiesTreeLikelihood = source.useAmbiguitiesTreeLikelihood;
132
133 frequencyPolicy = source.frequencyPolicy;
134 gammaHetero = source.gammaHetero;
135 gammaCategories = source.gammaCategories;
136 invarHetero = source.invarHetero;
137 codonHeteroPattern = source.codonHeteroPattern;
138 unlinkedSubstitutionModel = source.unlinkedSubstitutionModel;
139 unlinkedHeterogeneityModel = source.unlinkedHeterogeneityModel;
140 unlinkedFrequencyModel = source.unlinkedFrequencyModel;
141
142 dolloModel = source.dolloModel;
143
144 ratePorportion = source.ratePorportion;
145 mutationBias = source.mutationBias;
146 phase = source.phase;
147
148 microsatellite = source.microsatellite;
149
150 initModelParametersAndOpererators();
151 }
152
153 public PartitionSubstitutionModel(BeautiOptions options, String name) {
154 super(options, name);
155 continuousTraitCount = 0;
156 traitData = null;
157
158 initModelParametersAndOpererators();
159 }
160
161 // only init in PartitionSubstitutionModel
162 @Override
163 public void initModelParametersAndOpererators() {
164 double substWeights = 1.0;
165
166 //Substitution model parameters
167 if (options.useNewFrequenciesPrior()) {
168 createNonNegativeParameterDirichletPrior("frequencies", "base frequencies", this, 4, 1.0, true);
169 createNonNegativeParameterDirichletPrior("CP1.frequencies", "base frequencies for codon position 1", this, 4, 1.0, true);
170 createNonNegativeParameterDirichletPrior("CP2.frequencies", "base frequencies for codon position 2", this, 4, 1.0, true);
171 createNonNegativeParameterDirichletPrior("CP1+2.frequencies", "base frequencies for codon positions 1 & 2", this, 4, 1.0, true);
172 createNonNegativeParameterDirichletPrior("CP3.frequencies", "base frequencies for codon position 3", this, 4, 1.0, true);
173 } else {
174 createZeroOneParameterUniformPrior("frequencies", "base frequencies", 0.25, true);
175 createZeroOneParameterUniformPrior("CP1.frequencies", "base frequencies for codon position 1", 0.25, true);
176 createZeroOneParameterUniformPrior("CP2.frequencies", "base frequencies for codon position 2", 0.25, true);
177 createZeroOneParameterUniformPrior("CP1+2.frequencies", "base frequencies for codon positions 1 & 2", 0.25, true);
178 createZeroOneParameterUniformPrior("CP3.frequencies", "base frequencies for codon position 3", 0.25, true);
179 }
180
181 //This prior is moderately diffuse with a median of 2.718
182 createParameterLognormalPrior("kappa", "HKY transition-transversion parameter",
183 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
184 createParameterLognormalPrior("CP1.kappa", "HKY transition-transversion parameter for codon position 1",
185 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
186 createParameterLognormalPrior("CP2.kappa", "HKY transition-transversion parameter for codon position 2",
187 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
188 createParameterLognormalPrior("CP1+2.kappa", "HKY transition-transversion parameter for codon positions 1 & 2",
189 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
190 createParameterLognormalPrior("CP3.kappa", "HKY transition-transversion parameter for codon position 3",
191 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
192
193 createParameterLognormalPrior("kappa1", "TN93 1st transition-transversion parameter",
194 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
195 createParameterLognormalPrior("CP1.kappa1", "TN93 1st transition-transversion parameter for codon position 1",
196 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
197 createParameterLognormalPrior("CP2.kappa1", "TN93 1st transition-transversion parameter for codon position 2",
198 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
199 createParameterLognormalPrior("CP1+2.kappa1", "TN93 1st transition-transversion parameter for codon positions 1 & 2",
200 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
201 createParameterLognormalPrior("CP3.kappa1", "TN93 1st transition-transversion parameter for codon position 3",
202 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
203
204 createParameterLognormalPrior("kappa2", "TN93 2nd transition-transversion parameter",
205 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
206 createParameterLognormalPrior("CP1.kappa2", "TN93 2nd transition-transversion parameter for codon position 1",
207 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
208 createParameterLognormalPrior("CP2.kappa2", "TN93 2nd transition-transversion parameter for codon position 2",
209 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
210 createParameterLognormalPrior("CP1+2.kappa2", "TN93 2nd transition-transversion parameter for codon positions 1 & 2",
211 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
212 createParameterLognormalPrior("CP3.kappa2", "TN93 2nd transition-transversion parameter for codon position 3",
213 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 2.0, 1.0, 1.25, 0.0, true);
214
215 // createParameter("frequencies", "GTR base frequencies", UNITY_SCALE, 0.25, 0.0, 1.0);
216 // createParameter("CP1.frequencies", "GTR base frequencies for codon position 1", UNITY_SCALE, 0.25, 0.0, 1.0);
217 // createParameter("CP2.frequencies", "GTR base frequencies for codon position 2", UNITY_SCALE, 0.25, 0.0, 1.0);
218 // createParameter("CP1+2.frequencies", "GTR base frequencies for codon positions 1 & 2", UNITY_SCALE, 0.25, 0.0, 1.0);
219 // createParameter("CP3.frequencies", "GTR base frequencies for codon position 3", UNITY_SCALE, 0.25, 0.0, 1.0);
220
221 // create the relative rate parameters for the GTR rate matrix
222
223 // if (!options.classicOperatorsAndPriors && options.NEW_GTR_PARAMETERIZATION) {
224 createNonNegativeParameterDirichletPrior(GTR_RATES, "GTR transition rates parameter",
225 this, 6, 6.0, true);
226 for (int i = 1; i <= 3; i++) {
227 createNonNegativeParameterDirichletPrior("CP" + i + "." + GTR_RATES, "GTR transition rates parameter",
228 this, 6, 6.0, true);
229 }
230 createNonNegativeParameterDirichletPrior("CP1+2." + GTR_RATES, "GTR transition rates parameter",
231 this, 6, 6.0, true);
232
233 //} else {
234 for (int j = 0; j < 5; j++) {
235 if (j == 1) { // ag
236 createParameterGammaPrior(GTR_RATE_NAMES[j], "GTR " + GTR_TRANSITIONS[j] + " substitution parameter",
237 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, 0.05, 20, false, true);
238 } else {
239 createParameterGammaPrior(GTR_RATE_NAMES[j], "GTR " + GTR_TRANSITIONS[j] + " substitution parameter",
240 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, 0.05, 10, false, true);
241 }
242
243 for (int i = 1; i <= 3; i++) {
244 if (j == 1) { // ag
245 createParameterGammaPrior("CP" + i + "." + GTR_RATE_NAMES[j], "GTR " + GTR_TRANSITIONS[j] + " substitution parameter for codon position " + i,
246 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, 0.05, 20, false, true);
247 } else {
248 createParameterGammaPrior("CP" + i + "." + GTR_RATE_NAMES[j], "GTR " + GTR_TRANSITIONS[j] + " substitution parameter for codon position " + i,
249 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, 0.05, 10, false, true);
250 }
251 }
252
253 if (j == 1) { // ag
254 createParameterGammaPrior("CP1+2." + GTR_RATE_NAMES[j], "GTR " + GTR_TRANSITIONS[j] + " substitution parameter for codon positions 1 & 2",
255 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, 0.05, 20, false, true);
256 } else {
257 createParameterGammaPrior("CP1+2." + GTR_RATE_NAMES[j], "GTR " + GTR_TRANSITIONS[j] + " substitution parameter for codon positions 1 & 2",
258 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, 0.05, 10, false, true);
259 }
260 }
261 //}
262
263 // createParameter("frequencies", "Binary Simple frequencies", UNITY_SCALE, 0.5, 0.0, 1.0);
264 //
265 // createParameter("frequencies", "Binary Covarion frequencies of the visible states", UNITY_SCALE, 0.5, 0.0, 1.0);
266 createZeroOneParameterUniformPrior("hfrequencies", "Binary Covarion frequencies of the hidden rates", 0.5, true);
267 createZeroOneParameterUniformPrior("bcov.alpha", "Binary Covarion rate of evolution in slow mode", 0.5, true);
268 createParameterGammaPrior("bcov.s", "Binary Covarion rate of flipping between slow and fast modes",
269 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 0.5, 0.05, 10, false, true);
270
271 createParameterExponentialPrior("alpha", "gamma shape parameter",
272 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 0.5, 0.5, 0.0, true);
273 createParameterExponentialPrior("CP1.alpha", "gamma shape parameter for codon position 1",
274 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 0.5, 0.5, 0.0, true);
275 createParameterExponentialPrior("CP2.alpha", "gamma shape parameter for codon position 2",
276 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 0.5, 0.5, 0.0, true);
277 createParameterExponentialPrior("CP1+2.alpha", "gamma shape parameter for codon positions 1 & 2",
278 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 0.5, 0.5, 0.0, true);
279 createParameterExponentialPrior("CP3.alpha", "gamma shape parameter for codon position 3",
280 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 0.5, 0.5, 0.0, true);
281
282 createZeroOneParameterUniformPrior("pInv", "proportion of invariant sites parameter", 0.5, true);
283 createZeroOneParameterUniformPrior("CP1.pInv", "proportion of invariant sites parameter for codon position 1", 0.5, true);
284 createZeroOneParameterUniformPrior("CP2.pInv", "proportion of invariant sites parameter for codon position 2", 0.5, true);
285 createZeroOneParameterUniformPrior("CP1+2.pInv", "proportion of invariant sites parameter for codon positions 1 & 2", 0.5, true);
286 createZeroOneParameterUniformPrior("CP3.pInv", "proportion of invariant sites parameter for codon position 3", 0.5, true);
287
288 // nu parameters are an alternative parameterization of relative rates suitable for using with a Dirichlet prior.
289 // They sum to 1 and their product with the evolutionary rate is weighted by the partitions size.
290 createZeroOneParameterUniformPrior("nu", "relative rate parameter", 1.0, true);
291 createZeroOneParameterUniformPrior("CP1.nu", "relative rate parameter for codon position 1", 1.0, true);
292 createZeroOneParameterUniformPrior("CP2.nu", "relative rate parameter for codon position 2", 1.0, true);
293 createZeroOneParameterUniformPrior("CP1+2.nu", "relative rate parameter for codon positions 1 & 2", 1.0, true);
294 createZeroOneParameterUniformPrior("CP3.nu", "relative rate parameter for codon position 3", 1.0, true);
295
296 createNonNegativeParameterInfinitePrior("mu", "relative rate parameter", PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, true);
297 createNonNegativeParameterInfinitePrior("CP1.mu", "relative rate parameter for codon position 1",
298 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, true);
299 createNonNegativeParameterInfinitePrior("CP2.mu", "relative rate parameter for codon position 2",
300 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, true);
301 createNonNegativeParameterInfinitePrior("CP1+2.mu", "relative rate parameter for codon positions 1 & 2",
302 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, true);
303 createNonNegativeParameterInfinitePrior("CP3.mu", "relative rate parameter for codon position 3",
304 PriorScaleType.SUBSTITUTION_PARAMETER_SCALE, 1.0, true);
305
306 createScaleOperator("kappa", demoTuning, substWeights);
307 createScaleOperator("CP1.kappa", demoTuning, substWeights);
308 createScaleOperator("CP2.kappa", demoTuning, substWeights);
309 createScaleOperator("CP1+2.kappa", demoTuning, substWeights);
310 createScaleOperator("CP3.kappa", demoTuning, substWeights);
311
312 createScaleOperator("kappa1", demoTuning, substWeights);
313 createScaleOperator("CP1.kappa1", demoTuning, substWeights);
314 createScaleOperator("CP2.kappa1", demoTuning, substWeights);
315 createScaleOperator("CP1+2.kappa1", demoTuning, substWeights);
316 createScaleOperator("CP3.kappa1", demoTuning, substWeights);
317
318 createScaleOperator("kappa2", demoTuning, substWeights);
319 createScaleOperator("CP1.kappa2", demoTuning, substWeights);
320 createScaleOperator("CP2.kappa2", demoTuning, substWeights);
321 createScaleOperator("CP1+2.kappa2", demoTuning, substWeights);
322 createScaleOperator("CP3.kappa2", demoTuning, substWeights);
323
324 createOperator("frequencies", OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
325 createOperator("CP1.frequencies", OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
326 createOperator("CP2.frequencies", OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
327 createOperator("CP1+2.frequencies", OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
328 createOperator("CP3.frequencies", OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
329
330 // if (!options.classicOperatorsAndPriors && options.NEW_GTR_PARAMETERIZATION) {
331 createOperator("deltaGTR", "gtr.rates",
332 "Change GTR transition rates relative to each other maintaining mean",
333 GTR_RATES,
334 OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
335 for (int j = 1; j <= 3; j++) {
336 createOperator("CP" + j + ".deltaGTR", "CP" + j + ".gtr.rates",
337 "Change GTR transition rates relative to each other maintaining mean",
338 "CP" + j + "." + GTR_RATES,
339 OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
340 }
341 createOperator("CP1+2.deltaGTR", "CP1+2.gtr.rates",
342 "Change GTR transition rates relative to each other maintaining mean",
343 "CP1+2." + GTR_RATES,
344 OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
345 // } else {
346 for (String rateName : GTR_RATE_NAMES) {
347 createScaleOperator(rateName, demoTuning, substWeights);
348 for (int j = 1; j <= 3; j++) {
349 createScaleOperator("CP" + j + "." + rateName, demoTuning, substWeights);
350 }
351 createScaleOperator("CP1+2." + rateName, demoTuning, substWeights);
352 }
353 // }
354
355 createScaleOperator("alpha", demoTuning, substWeights);
356 for (int i = 1; i <= 3; i++) {
357 createScaleOperator("CP" + i + ".alpha", demoTuning, substWeights);
358 }
359 createScaleOperator("CP1+2.alpha", demoTuning, substWeights);
360
361 // if (!options.classicOperatorsAndPriors && LOGIT_PINV_KERNEL) { // a switch at the top of BeautiOptions
362 createOperator("rwPInv", "rwPInv", "Random walk on pInv in logit space", "pInv", OperatorType.RANDOM_WALK_LOGIT, demoTuning, substWeights);
363 for (int i = 1; i <= 3; i++) {
364 createOperator("CP" + i + ".rwPInv", "CP" + i + ".rwPInv", "Random walk on pInv in logit space", "CP" + i + ".pInv", OperatorType.RANDOM_WALK_LOGIT, demoTuning, substWeights);
365 }
366 createOperator("CP1+2.rwPInv", "CP1+2.rwPInv", "Random walk on pInv in logit space", "CP1+2.pInv", OperatorType.RANDOM_WALK_LOGIT, demoTuning, substWeights);
367 // } else {
368 // old (and not very appropriate scale operator)
369 createOperator("CP1+2.uniformPInv", "CP1+2.uniformPInv", "Random walk on pInv in logit space", "pInv", OperatorType.UNIFORM, demoTuning, substWeights);
370 for (int i = 1; i <= 3; i++) {
371 createOperator("CP" + i + ".uniformPInv", "CP" + i + ".uniformPInv", "Random walk on pInv in logit space", "CP" + i + ".pInv", OperatorType.UNIFORM, demoTuning, substWeights);
372 }
373 createOperator("CP1+2.uniformPInv", "CP1+2.uniformPInv", "Random walk on pInv in logit space", "CP1+2.pInv", OperatorType.UNIFORM, demoTuning, substWeights);
374 // }
375
376 createScaleOperator("bcov.alpha", demoTuning, substWeights);
377 createScaleOperator("bcov.s", demoTuning, substWeights);
378 createOperator("hfrequencies", OperatorType.DELTA_EXCHANGE, 0.01, substWeights);
379
380 //=============== microsat ======================
381 createParameterGammaPrior("propLinear", "Proportionality linear function",
382 PriorScaleType.NONE, 0.5, 1.0, 1.0, false, true);
383 createParameterNormalPrior("biasConst", "Constant bias", PriorScaleType.NONE,
384 0.0, 0.0, 10.0, 0.0, true);
385 createParameterNormalPrior("biasLinear", "Linear bias", PriorScaleType.NONE,
386 0.0, 0.0, 10.0, 0.0, true);
387 createZeroOneParameterUniformPrior("geomDist", "The success probability of geometric distribution", 0.1, true);
388 createZeroOneParameterUniformPrior("onePhaseProb", "A probability of geomDist being the last step of series", 1.0, true);
389
390 createScaleOperator("propLinear", demoTuning, substWeights);
391 // createOperator("deltaBiasConst", "deltaBiasConst", "Delta exchange on constant bias", "biasConst",
392 // OperatorType.DELTA_EXCHANGE, 0.001, 1.6);
393 createOperator("randomWalkBiasConst", "randomWalkBiasConst", "Random walk on constant bias", "biasConst",
394 OperatorType.RANDOM_WALK, 0.01, 2.0);
395 createOperator("randomWalkBiasLinear", "randomWalkBiasLinear", "Random walk on linear bias", "biasLinear",
396 OperatorType.RANDOM_WALK, 0.001, 2.0);
397 createOperator("randomWalkGeom", "randomWalkGeom", "Random walk on geomDist", "geomDist",
398 OperatorType.RANDOM_WALK, 0.01, 2.0);
399
400 }
401
402 ////////////////////////////////////////////////////////////////
403
404 @Override
405 public List<Parameter> selectParameters(List<Parameter> params) {
406 // setAvgRootAndRate();
407 boolean includeRelativeRates = getCodonPartitionCount() > 1;//TODO check
408 switch (getDataType().getType()) {
409 case DataType.NUCLEOTIDES:
410 if (includeRelativeRates && unlinkedSubstitutionModel) {
411 if (codonHeteroPattern.equals("123")) {
412 for (int i = 1; i <= getCodonPartitionCount(); i++) {
413 switch (nucSubstitutionModel) {
414 case JC:
415 break;
416 case HKY:
417 params.add(getParameter("CP" + i + ".kappa"));
418 break;
419 case TN93:
420 params.add(getParameter("CP" + i + ".kappa1"));
421 params.add(getParameter("CP" + i + ".kappa2"));
422 break;
423 case GTR:
424 if (options.useNewGTR()) {
425 params.add(getParameter("CP" + i + "." + GTR_RATES));
426 } else {
427 for (String rateName : GTR_RATE_NAMES) {
428 params.add(getParameter("CP" + i + "." + rateName));
429 }
430 }
431 break;
432
433 default:
434 throw new IllegalArgumentException("Unknown nucleotides substitution model");
435 }
436 }
437
438 } else if (codonHeteroPattern.equals("112")) {
439 switch (nucSubstitutionModel) {
440 case JC:
441 break;
442 case HKY:
443 params.add(getParameter("CP1+2.kappa"));
444 params.add(getParameter("CP3.kappa"));
445 break;
446 case TN93:
447 params.add(getParameter("CP1+2.kappa1"));
448 params.add(getParameter("CP3.kappa1"));
449 params.add(getParameter("CP1+2.kappa2"));
450 params.add(getParameter("CP3.kappa2"));
451 break;
452 case GTR:
453 if (options.useNewGTR()) {
454 params.add(getParameter("CP1+2." + GTR_RATES));
455 params.add(getParameter("CP3." + GTR_RATES));
456 } else {
457 for (String rateName : GTR_RATE_NAMES) {
458 params.add(getParameter("CP1+2." + rateName));
459 }
460 for (String rateName : GTR_RATE_NAMES) {
461 params.add(getParameter("CP3." + rateName));
462 }
463 }
464 break;
465
466 default:
467 throw new IllegalArgumentException("Unknown nucleotides substitution model");
468 }
469
470 } else {
471 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
472 }
473 } else { // no codon partitioning, or unlinkedSubstitutionModel
474 switch (nucSubstitutionModel) {
475 case JC:
476 break;
477 case HKY:
478 params.add(getParameter("kappa"));
479 break;
480 case TN93:
481 params.add(getParameter("kappa1"));
482 params.add(getParameter("kappa2"));
483 break;
484 case GTR:
485 if (options.useNewGTR()) {
486 params.add(getParameter(GTR_RATES));
487 } else {
488
489 for (String rateName : GTR_RATE_NAMES) {
490 params.add(getParameter(rateName));
491 }
492 }
493 break;
494
495 default:
496 throw new IllegalArgumentException("Unknown nucleotides substitution model");
497 }
498 }
499
500 // only AMINO_ACIDS not addFrequency
501 addFrequencyParams(params, includeRelativeRates);
502 break;
503
504 case DataType.AMINO_ACIDS:
505 // if (includeRelativeRates) {
506 // params.add(getParameter("mu"));
507 // }
508 break;
509
510 case DataType.TWO_STATES:
511 case DataType.COVARION:
512 switch (binarySubstitutionModel) {
513 case BIN_SIMPLE:
514 case BIN_DOLLO:
515 break;
516
517 case BIN_COVARION:
518 // useAmbiguitiesTreeLikelihood = true;
519 params.add(getParameter("bcov.alpha"));
520 params.add(getParameter("bcov.s"));
521 params.add(getParameter("hfrequencies")); // no codon for binary
522 break;
523
524 default:
525 throw new IllegalArgumentException("Unknown binary substitution model");
526 }
527 // if (includeRelativeRates) {
528 // params.add(getParameter("mu"));
529 // }
530
531 // only AMINO_ACIDS not addFrequency
532 addFrequencyParams(params, includeRelativeRates);
533 break;
534
535 case DataType.GENERAL:
536 // This model is controlled by DiscreteTraitComponentOptions
537 break;
538
539 case DataType.CONTINUOUS:
540 // This model is controlled by ContinuousTraitComponentOptions
541 break;
542
543 case DataType.MICRO_SAT:
544 if (ratePorportion == MicroSatModelType.RateProportionality.EQUAL_RATE) {
545
546 } else if (ratePorportion == MicroSatModelType.RateProportionality.PROPORTIONAL_RATE) {
547 params.add(getParameter("propLinear"));
548 } else if (ratePorportion == MicroSatModelType.RateProportionality.ASYM_QUAD) {
549
550 }
551 if (mutationBias == MicroSatModelType.MutationalBias.UNBIASED) {
552
553 } else if (mutationBias == MicroSatModelType.MutationalBias.CONSTANT_BIAS) {
554 params.add(getParameter("biasConst"));
555 } else if (mutationBias == MicroSatModelType.MutationalBias.LINEAR_BIAS) {
556 params.add(getParameter("biasConst"));
557 params.add(getParameter("biasLinear"));
558 }
559 if (phase == MicroSatModelType.Phase.ONE_PHASE) {
560
561 } else if (phase == MicroSatModelType.Phase.TWO_PHASE) {
562 params.add(getParameter("geomDist"));
563 } else if (phase == MicroSatModelType.Phase.TWO_PHASE_STAR) {
564 params.add(getParameter("geomDist"));
565 params.add(getParameter("onePhaseProb"));
566 }
567 break;
568
569 default:
570 throw new IllegalArgumentException("Unknown data type");
571 }
572
573 // if gamma do shape move
574 if (gammaHetero) {
575 if (includeRelativeRates && unlinkedHeterogeneityModel) {
576 if (codonHeteroPattern.equals("123")) {
577 params.add(getParameter("CP1.alpha"));
578 params.add(getParameter("CP2.alpha"));
579 params.add(getParameter("CP3.alpha"));
580 } else if (codonHeteroPattern.equals("112")) {
581 params.add(getParameter("CP1+2.alpha"));
582 params.add(getParameter("CP3.alpha"));
583 } else {
584 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
585 }
586 } else {
587 params.add(getParameter("alpha"));
588 }
589 }
590 // if pinv do pinv move
591 if (invarHetero) {
592 if (includeRelativeRates && unlinkedHeterogeneityModel) {
593 if (codonHeteroPattern.equals("123")) {
594 params.add(getParameter("CP1.pInv"));
595 params.add(getParameter("CP2.pInv"));
596 params.add(getParameter("CP3.pInv"));
597 } else if (codonHeteroPattern.equals("112")) {
598 params.add(getParameter("CP1+2.pInv"));
599 params.add(getParameter("CP3.pInv"));
600 } else {
601 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
602 }
603 } else {
604 params.add(getParameter("pInv"));
605 }
606 }
607 return params;
608 }
609
610 public List<Parameter> getRelativeRateParameters() {
611 List<Parameter> allMus = new ArrayList<Parameter>();
612 int[] weights = getPartitionCodonWeights();
613 if (getCodonPartitionCount() > 1) {
614 if (codonHeteroPattern.equals("123")) {
615 Parameter parameter = getParameter("CP1." + (options.useNuRelativeRates() ? "nu" : "mu"));
616 parameter.setDimensionWeight(weights[0]);
617 allMus.add(parameter);
618
619 parameter = getParameter("CP2." + (options.useNuRelativeRates() ? "nu" : "mu"));
620 parameter.setDimensionWeight(weights[1]);
621 allMus.add(parameter);
622
623 parameter = getParameter("CP3." + (options.useNuRelativeRates() ? "nu" : "mu"));
624 parameter.setDimensionWeight(weights[2]);
625 allMus.add(parameter);
626 } else if (codonHeteroPattern.equals("112")) {
627 Parameter parameter = getParameter("CP1+2." + (options.useNuRelativeRates() ? "nu" : "mu"));
628 parameter.setDimensionWeight(weights[0]);
629 allMus.add(parameter);
630
631 parameter = getParameter("CP3." + (options.useNuRelativeRates() ? "nu" : "mu"));
632 parameter.setDimensionWeight(weights[1]);
633 allMus.add(parameter);
634 } else {
635 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
636 }
637 } else {
638 Parameter mu = getParameter(options.useNuRelativeRates() ? "nu" : "mu");
639 mu.setDimensionWeight(weights[0]);
640 allMus.add(mu);
641 }
642 return allMus;
643 }
644
645 private void addFrequencyParams(List<Parameter> params, boolean includeRelativeRates) {
646 if (frequencyPolicy == FrequencyPolicyType.ESTIMATED) {
647 if (includeRelativeRates && unlinkedSubstitutionModel && unlinkedFrequencyModel) {
648 if (codonHeteroPattern.equals("123")) {
649 params.add(getParameter("CP1.frequencies"));
650 params.add(getParameter("CP2.frequencies"));
651 params.add(getParameter("CP3.frequencies"));
652 } else if (codonHeteroPattern.equals("112")) {
653 params.add(getParameter("CP1+2.frequencies"));
654 params.add(getParameter("CP3.frequencies"));
655 } else {
656 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
657 }
658 } else {
659 params.add(getParameter("frequencies"));
660 }
661
662 }
663 }
664
665 @Override
666 public List<Operator> selectOperators(List<Operator> operators) {
667
668 List<Operator> ops = new ArrayList<Operator>();
669
670 switch (getDataType().getType()) {
671 case DataType.NUCLEOTIDES:
672
673 if (hasCodonPartitions() && unlinkedSubstitutionModel) {
674 if (codonHeteroPattern.equals("123")) {
675 switch (nucSubstitutionModel) {
676 case JC:
677 break;
678 case HKY:
679 ops.add(getOperator("CP1.kappa"));
680 ops.add(getOperator("CP2.kappa"));
681 ops.add(getOperator("CP3.kappa"));
682 break;
683
684 case TN93:
685 ops.add(getOperator("CP1.kappa1"));
686 ops.add(getOperator("CP2.kappa1"));
687 ops.add(getOperator("CP3.kappa1"));
688 ops.add(getOperator("CP1.kappa2"));
689 ops.add(getOperator("CP2.kappa2"));
690 ops.add(getOperator("CP3.kappa2"));
691 break;
692
693 case GTR:
694
695 for (int i = 1; i <= 3; i++) {
696 if (options.useNewGTR()) {
697 ops.add(getOperator("CP" + i + ".deltaGTR"));
698 } else {
699 for (String rateName : GTR_RATE_NAMES) {
700 ops.add(getOperator("CP" + i + "." + rateName));
701 }
702 }
703 }
704 break;
705
706 default:
707 throw new IllegalArgumentException("Unknown nucleotides substitution model");
708 }
709
710 } else if (codonHeteroPattern.equals("112")) {
711 switch (nucSubstitutionModel) {
712 case JC:
713 break;
714 case HKY:
715 ops.add(getOperator("CP1+2.kappa"));
716 ops.add(getOperator("CP3.kappa"));
717 break;
718
719 case TN93:
720 ops.add(getOperator("CP1+2.kappa1"));
721 ops.add(getOperator("CP3.kappa1"));
722 ops.add(getOperator("CP1+2.kappa2"));
723 ops.add(getOperator("CP3.kappa2"));
724 break;
725
726 case GTR:
727 if (options.useNewGTR()) {
728 ops.add(getOperator("CP1+2.deltaGTR"));
729 ops.add(getOperator("CP3.deltaGTR"));
730 } else {
731 for (String rateName : GTR_RATE_NAMES) {
732 ops.add(getOperator("CP1+2." + rateName));
733 }
734 for (String rateName : GTR_RATE_NAMES) {
735 ops.add(getOperator("CP3." + rateName));
736 }
737 }
738 break;
739
740 default:
741 throw new IllegalArgumentException("Unknown nucleotides substitution model");
742 }
743
744 } else {
745 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
746 }
747
748 } else { // no codon partitioning, or unlinkedSubstitutionModel
749 switch (nucSubstitutionModel) {
750 case JC:
751 break;
752 case HKY:
753 ops.add(getOperator("kappa"));
754 break;
755
756 case TN93:
757 ops.add(getOperator("kappa1"));
758 ops.add(getOperator("kappa2"));
759 break;
760
761 case GTR:
762 if (options.useNewGTR()) {
763 ops.add(getOperator("deltaGTR"));
764 } else {
765 for (String rateName : GTR_RATE_NAMES) {
766 ops.add(getOperator(rateName));
767 }
768 }
769 break;
770
771 default:
772 throw new IllegalArgumentException("Unknown nucleotides substitution model");
773 }
774 }
775
776 // only AMINO_ACIDS not addFrequency
777 addFrequencyOps(ops);
778 break;
779
780 case DataType.AMINO_ACIDS:
781 break;
782
783 case DataType.TWO_STATES:
784 case DataType.COVARION:
785 switch (binarySubstitutionModel) {
786 case BIN_SIMPLE:
787 case BIN_DOLLO:
788 break;
789
790 case BIN_COVARION:
791 ops.add(getOperator("bcov.alpha"));
792 ops.add(getOperator("bcov.s"));
793 ops.add(getOperator("hfrequencies"));
794 break;
795
796 default:
797 throw new IllegalArgumentException("Unknown binary substitution model");
798 }
799
800 // only AMINO_ACIDS not addFrequency
801 addFrequencyOps(ops);
802 break;
803
804 case DataType.GENERAL:
805 break;
806
807 case DataType.CONTINUOUS:
808 break;
809
810 case DataType.MICRO_SAT:
811 if (ratePorportion == MicroSatModelType.RateProportionality.EQUAL_RATE) {
812
813 } else if (ratePorportion == MicroSatModelType.RateProportionality.PROPORTIONAL_RATE) {
814 ops.add(getOperator("propLinear"));
815 } else if (ratePorportion == MicroSatModelType.RateProportionality.ASYM_QUAD) {
816
817 }
818 if (mutationBias == MicroSatModelType.MutationalBias.UNBIASED) {
819
820 } else if (mutationBias == MicroSatModelType.MutationalBias.CONSTANT_BIAS) {
821 ops.add(getOperator("randomWalkBiasConst"));
822 } else if (mutationBias == MicroSatModelType.MutationalBias.LINEAR_BIAS) {
823 ops.add(getOperator("randomWalkBiasConst"));
824 ops.add(getOperator("randomWalkBiasLinear"));
825 }
826 if (phase == MicroSatModelType.Phase.ONE_PHASE) {
827
828 } else if (phase == MicroSatModelType.Phase.TWO_PHASE) {
829 ops.add(getOperator("randomWalkGeom"));
830 } else if (phase == MicroSatModelType.Phase.TWO_PHASE_STAR) {
831 // ops.add(getOperator("randomWalkGeom"));
832 // ops.add(getOperator("onePhaseProb"));
833 }
834 break;
835
836 default:
837 throw new IllegalArgumentException("Unknown data type");
838 }
839
840 // if gamma do shape move
841 if (gammaHetero) {
842 if (hasCodonPartitions() && unlinkedHeterogeneityModel) {
843 if (codonHeteroPattern.equals("123")) {
844 ops.add(getOperator("CP1.alpha"));
845 ops.add(getOperator("CP2.alpha"));
846 ops.add(getOperator("CP3.alpha"));
847 } else if (codonHeteroPattern.equals("112")) {
848 ops.add(getOperator("CP1+2.alpha"));
849 ops.add(getOperator("CP3.alpha"));
850 } else {
851 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
852 }
853 } else {
854 ops.add(getOperator("alpha"));
855 }
856 }
857 // if pinv do pinv move
858 if (invarHetero) {
859 String name = (options.usePInvRandomWalk() ? "rwPInv" : "uniformPInv");
860 if (hasCodonPartitions() && unlinkedHeterogeneityModel) {
861 if (codonHeteroPattern.equals("123")) {
862 ops.add(getOperator("CP1." + name));
863 ops.add(getOperator("CP2." + name));
864 ops.add(getOperator("CP3." + name));
865 } else if (codonHeteroPattern.equals("112")) {
866 ops.add(getOperator("CP1+2." + name));
867 ops.add(getOperator("CP3." + name));
868 } else {
869 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
870 }
871 } else {
872 ops.add(getOperator(name));
873 }
874 }
875
876 if (options.operatorSetType != OperatorSetType.CUSTOM) {
877 // unless a custom mix has been chosen these operators should be off if AMTK is on
878 for (Operator op : ops) {
879 if (op.getParameter1().isAdaptiveMultivariateCompatible) {
880 op.setUsed(options.operatorSetType != OperatorSetType.ADAPTIVE_MULTIVARIATE);
881 }
882 }
883 }
884
885 operators.addAll(ops);
886
887 return operators;
888 }
889
890 private void addFrequencyOps(List<Operator> ops) {
891 if (frequencyPolicy == FrequencyPolicyType.ESTIMATED) {
892 if (hasCodonPartitions() && unlinkedSubstitutionModel && unlinkedFrequencyModel) {
893 if (codonHeteroPattern.equals("123")) {
894 ops.add(getOperator("CP1.frequencies"));
895 ops.add(getOperator("CP2.frequencies"));
896 ops.add(getOperator("CP3.frequencies"));
897 } else if (codonHeteroPattern.equals("112")) {
898 ops.add(getOperator("CP1+2.frequencies"));
899 ops.add(getOperator("CP3.frequencies"));
900 } else {
901 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
902 }
903 } else {
904 ops.add(getOperator("frequencies"));
905 }
906 }
907 }
908
909 /**
910 * @return true either if the options have more than one partition or any partition is
911 * broken into codon positions.
912 */
913 public boolean hasCodonPartitions() {
914 return getCodonPartitionCount() > 1;
915 }
916
917 public int getCodonPartitionCount() {
918 if (codonHeteroPattern == null || codonHeteroPattern.equals("111")) {
919 return 1;
920 }
921 if (codonHeteroPattern.equals("123")) {
922 return 3;
923 }
924 if (codonHeteroPattern.equals("112")) {
925 return 2;
926 }
927 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
928 }
929
930 public void addWeightsForPartition(AbstractPartitionData partition, int[] weights, int offset) {
931 int n = partition.getSiteCount();
932 int codonCount = n / 3;
933 int remainder = n % 3;
934 if (codonHeteroPattern == null || codonHeteroPattern.equals("111")) {
935 weights[offset] += n;
936 return;
937 }
938 if (codonHeteroPattern.equals("123")) {
939 weights[offset] += codonCount + (remainder > 0 ? 1 : 0);
940 weights[offset + 1] += codonCount + (remainder > 1 ? 1 : 0);
941 weights[offset + 2] += codonCount;
942 return;
943 }
944 if (codonHeteroPattern.equals("112")) {
945 weights[offset] += codonCount * 2 + remainder; // positions 1 + 2
946 weights[offset + 1] += codonCount; // position 3
947 return;
948 }
949 throw new IllegalArgumentException("codonHeteroPattern must be one of '111', '112' or '123'");
950 }
951
952 /**
953 * This returns an integer vector of the number of sites in each partition (including any codon partitions). These
954 * are strictly in the same order as the 'mu' relative rates are listed.
955 *
956 * @return weights for each partition model
957 */
958 public int[] getPartitionCodonWeights() {
959 int[] weights = new int[getCodonPartitionCount()];
960
961 int k = 0;
962 for (AbstractPartitionData partition : options.getDataPartitions(this)) {
963 if (partition.getPartitionSubstitutionModel() == this) {
964 addWeightsForPartition(partition, weights, k);
965 }
966 }
967 k += getCodonPartitionCount();
968
969 assert (k == weights.length);
970
971 return weights;
972 }
973
974 ///////////////////////////////////////////////////////
975
976 public NucModelType getNucSubstitutionModel() {
977 return nucSubstitutionModel;
978 }
979
980 public void setNucSubstitutionModel(NucModelType nucSubstitutionModel) {
981 this.nucSubstitutionModel = nucSubstitutionModel;
982 }
983
984 public AminoAcidModelType getAaSubstitutionModel() {
985 return aaSubstitutionModel;
986 }
987
988 public void setAaSubstitutionModel(AminoAcidModelType aaSubstitutionModel) {
989 this.aaSubstitutionModel = aaSubstitutionModel;
990 }
991
992 public BinaryModelType getBinarySubstitutionModel() {
993 return binarySubstitutionModel;
994 }
995
996 public void setBinarySubstitutionModel(BinaryModelType binarySubstitutionModel) {
997 this.binarySubstitutionModel = binarySubstitutionModel;
998 }
999
1000 public DiscreteSubstModelType getDiscreteSubstType() {
1001 return discreteSubstType;
1002 }
1003
1004 public void setDiscreteSubstType(DiscreteSubstModelType discreteSubstType) {
1005 this.discreteSubstType = discreteSubstType;
1006 }
1007
1008 public ContinuousSubstModelType getContinuousSubstModelType() {
1009 return continuousSubstModelType;
1010 }
1011
1012 public void setContinuousSubstModelType(final ContinuousSubstModelType continuousSubstModelType) {
1013 this.continuousSubstModelType = continuousSubstModelType;
1014 }
1015
1016 public void setIsLatitudeLongitude(boolean latitudeLongitude) {
1017 isLatitudeLongitude = latitudeLongitude;
1018 }
1019
1020 public boolean isLatitudeLongitude() {
1021 return isLatitudeLongitude;
1022 }
1023
1024 public void setJitterWindow(double jitterWindow) {
1025 this.jitterWindow = jitterWindow;
1026 }
1027
1028 public double getJitterWindow() {
1029 return jitterWindow;
1030 }
1031
1032 public int getContinuousTraitCount() {
1033 return continuousTraitCount;
1034 }
1035
1036 public MicroSatModelType.RateProportionality getRatePorportion() {
1037 return ratePorportion;
1038 }
1039
1040 public void setRatePorportion(MicroSatModelType.RateProportionality ratePorportion) {
1041 this.ratePorportion = ratePorportion;
1042 }
1043
1044 public MicroSatModelType.MutationalBias getMutationBias() {
1045 return mutationBias;
1046 }
1047
1048 public void setMutationBias(MicroSatModelType.MutationalBias mutationBias) {
1049 this.mutationBias = mutationBias;
1050 }
1051
1052 public MicroSatModelType.Phase getPhase() {
1053 return phase;
1054 }
1055
1056 public void setPhase(MicroSatModelType.Phase phase) {
1057 this.phase = phase;
1058 }
1059
1060 public Microsatellite getMicrosatellite() {
1061 return microsatellite;
1062 }
1063
1064 public void setMicrosatellite(Microsatellite microsatellite) {
1065 this.microsatellite = microsatellite;
1066 }
1067
1068 public boolean isActivateBSSVS() {
1069 return discreteSubstType != DiscreteSubstModelType.GLM_SUBST && activateBSSVS;
1070 }
1071
1072 public void setActivateBSSVS(boolean activateBSSVS) {
1073 this.activateBSSVS = activateBSSVS;
1074 }
1075
1076 public FrequencyPolicyType getFrequencyPolicy() {
1077 return frequencyPolicy;
1078 }
1079
1080 public void setFrequencyPolicy(FrequencyPolicyType frequencyPolicy) {
1081 this.frequencyPolicy = frequencyPolicy;
1082 }
1083
1084 public boolean isGammaHetero() {
1085 return gammaHetero;
1086 }
1087
1088 public void setGammaHetero(boolean gammaHetero) {
1089 this.gammaHetero = gammaHetero;
1090 }
1091
1092 public int getGammaCategories() {
1093 return gammaCategories;
1094 }
1095
1096 public void setGammaCategories(int gammaCategories) {
1097 this.gammaCategories = gammaCategories;
1098 }
1099
1100 public boolean isInvarHetero() {
1101 return invarHetero;
1102 }
1103
1104 public void setInvarHetero(boolean invarHetero) {
1105 this.invarHetero = invarHetero;
1106 }
1107
1108 public String getCodonHeteroPattern() {
1109 return codonHeteroPattern;
1110 }
1111
1112 public void setCodonHeteroPattern(String codonHeteroPattern) {
1113 this.codonHeteroPattern = codonHeteroPattern;
1114 }
1115
1116 /**
1117 * @return true if the rate matrix parameters are unlinked across codon positions
1118 */
1119 public boolean isUnlinkedSubstitutionModel() {
1120 return unlinkedSubstitutionModel;
1121 }
1122
1123 public void setUnlinkedSubstitutionModel(boolean unlinkedSubstitutionModel) {
1124 this.unlinkedSubstitutionModel = unlinkedSubstitutionModel;
1125 }
1126
1127 public boolean isUnlinkedHeterogeneityModel() {
1128 return unlinkedHeterogeneityModel;
1129 }
1130
1131 public void setUnlinkedHeterogeneityModel(boolean unlinkedHeterogeneityModel) {
1132 this.unlinkedHeterogeneityModel = unlinkedHeterogeneityModel;
1133 }
1134
1135 public boolean isUnlinkedFrequencyModel() {
1136 return unlinkedFrequencyModel;
1137 }
1138
1139 public void setUnlinkedFrequencyModel(boolean unlinkedFrequencyModel) {
1140 this.unlinkedFrequencyModel = unlinkedFrequencyModel;
1141 }
1142
1143 public boolean isDolloModel() {
1144 return dolloModel;
1145 }
1146
1147 public void setDolloModel(boolean dolloModel) {
1148 this.dolloModel = dolloModel;
1149 }
1150
1151 public boolean isUseAmbiguitiesTreeLikelihood() {
1152 return useAmbiguitiesTreeLikelihood;
1153 }
1154
1155 public void setUseAmbiguitiesTreeLikelihood(boolean useAmbiguitiesTreeLikelihood) {
1156 this.useAmbiguitiesTreeLikelihood = useAmbiguitiesTreeLikelihood;
1157 }
1158
1159 public String getPrefix() {
1160 String prefix = "";
1161 if (options.getPartitionSubstitutionModels(Nucleotides.INSTANCE).size() +
1162 options.getPartitionSubstitutionModels(AminoAcids.INSTANCE).size() > 1) {
1163 // There is more than one active partition model, or doing species analysis
1164 prefix += getName() + ".";
1165 }
1166 return prefix;
1167 }
1168
1169 public String getPrefix(DataType dataType) {
1170 String prefix = "";
1171 if (options.getPartitionSubstitutionModels(dataType).size() > 1) {
1172 // There is more than one active partition model, or doing species analysis
1173 prefix += getName() + ".";
1174 }
1175 return prefix;
1176 }
1177
1178 public String getPrefix(int codonPartitionNumber) {
1179 String prefix = "";
1180 prefix += getPrefix();
1181 prefix += getPrefixCodon(codonPartitionNumber);
1182 return prefix;
1183 }
1184
1185 public String getPrefixCodon(int codonPartitionNumber) {
1186 String prefix = "";
1187 if (getCodonPartitionCount() > 1 && codonPartitionNumber > 0) {
1188 if (getCodonHeteroPattern().equals("123")) {
1189 prefix += "CP" + codonPartitionNumber + ".";
1190 } else if (getCodonHeteroPattern().equals("112")) {
1191 if (codonPartitionNumber == 1) {
1192 prefix += "CP1+2.";
1193 } else {
1194 prefix += "CP3.";
1195 }
1196 } else {
1197 throw new IllegalArgumentException("unsupported codon hetero pattern");
1198 }
1199
1200 }
1201 return prefix;
1202 }
1203
1204 /**
1205 * returns the union of the set of states for all traits using this discrete CTMC model
1206 *
1207 * @return
1208 */
1209 public Set<String> getDiscreteStateSet() {
1210 Set<String> states = new HashSet<String>();
1211 for (AbstractPartitionData partition : options.getDataPartitions(this)) {
1212 if (partition.getTraits() != null) {
1213 states.addAll(partition.getTraits().get(0).getStatesOfTrait(options.taxonList));
1214 }
1215 }
1216 return states;
1217 }
1218
1219 public void copyFrom(PartitionSubstitutionModel source) {
1220 nucSubstitutionModel = source.nucSubstitutionModel;
1221 aaSubstitutionModel = source.aaSubstitutionModel;
1222 binarySubstitutionModel = source.binarySubstitutionModel;
1223 discreteSubstType = source.discreteSubstType;
1224 continuousSubstModelType = source.continuousSubstModelType;
1225
1226 activateBSSVS = source.activateBSSVS;
1227 useAmbiguitiesTreeLikelihood = source.useAmbiguitiesTreeLikelihood;
1228
1229 frequencyPolicy = source.frequencyPolicy;
1230 gammaHetero = source.gammaHetero;
1231 gammaCategories = source.gammaCategories;
1232 invarHetero = source.invarHetero;
1233 codonHeteroPattern = source.codonHeteroPattern;
1234 unlinkedSubstitutionModel = source.unlinkedSubstitutionModel;
1235 unlinkedHeterogeneityModel = source.unlinkedHeterogeneityModel;
1236 unlinkedFrequencyModel = source.unlinkedFrequencyModel;
1237
1238 dolloModel = source.dolloModel;
1239
1240 ratePorportion = source.ratePorportion;
1241 mutationBias = source.mutationBias;
1242 phase = source.phase;
1243
1244 microsatellite = source.microsatellite;
1245 }
1246
1247 @Override
1248 public String toString() {
1249 return getName();
1250 }
1251
1252 }