Debian Codegraph @

src/dr/app/bss/PartitionData.java

raw symbols SCIP
1 /*
2 * PartitionData.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.bss;
27
28 import java.io.Serializable;
29
30 import dr.evomodel.branchmodel.BranchModel;
31 import dr.evomodel.branchmodel.HomogeneousBranchModel;
32 import dr.evomodel.siteratemodel.GammaSiteRateModel;
33 import dr.evomodel.substmodel.EmpiricalRateMatrix;
34 import dr.evomodel.substmodel.FrequencyModel;
35 import dr.evomodel.substmodel.nucleotide.GTR;
36 import dr.evomodel.substmodel.codon.GY94CodonModel;
37 import dr.evomodel.substmodel.nucleotide.HKY;
38 import dr.evomodel.substmodel.codon.MG94HKYCodonModel;
39 import dr.evomodel.substmodel.nucleotide.TN93;
40 import dr.evolution.coalescent.CoalescentSimulator;
41 import dr.evolution.coalescent.ConstantPopulation;
42 import dr.evolution.coalescent.DemographicFunction;
43 import dr.evolution.coalescent.ExponentialGrowth;
44 import dr.evolution.datatype.AminoAcids;
45 import dr.evolution.datatype.Codons;
46 import dr.evolution.datatype.DataType;
47 import dr.evolution.datatype.Nucleotides;
48 import dr.evolution.sequence.Sequence;
49 import dr.evolution.util.Taxa;
50 import dr.evolution.util.Units;
51 import dr.evomodel.branchratemodel.BranchRateModel;
52 import dr.evomodel.branchratemodel.DiscretizedBranchRates;
53 import dr.evomodel.branchratemodel.StrictClockBranchRates;
54 import dr.evomodel.substmodel.aminoacid.*;
55 import dr.oldevomodel.sitemodel.SiteModel;
56 import dr.evomodel.tree.TreeModel;
57 import dr.evoxml.TaxaParser;
58 import dr.inference.distribution.ExponentialDistributionModel;
59 import dr.inference.distribution.InverseGaussianDistributionModel;
60 import dr.inference.distribution.LogNormalDistributionModel;
61 import dr.inference.distribution.ParametricDistributionModel;
62 import dr.inference.model.Parameter;
63 import dr.inferencexml.distribution.DistributionModelParser;
64 import dr.inferencexml.distribution.InverseGaussianDistributionModelParser;
65 import dr.inferencexml.distribution.LogNormalDistributionModelParser;
66
67 /**
68 * @author Filip Bielejec
69 * @version $Id$
70 */
71 @SuppressWarnings("serial")
72 public class PartitionData implements Serializable {
73
74 public PartitionData() {
75 }// END: Constructor
76
77 public int from = 1;
78 public int to = 10;
79 public int every = 1;
80
81 public int createPartitionSiteCount() {
82 return ((to - from) / every) + 1;
83 }
84
85 public void resetIdrefs() {
86 resetClockModelIdref();
87 resetFrequencyModelIdref();
88 resetSiteRateModelIdref();
89 resetSubstitutionModelIdref();
90 resetTreeModelIdref();
91 resetDemographicModelIdref();
92 resetTaxaIdref();
93 }
94
95 // ///////////////////////
96 // ---TREE ANNOTATING---//
97 // ///////////////////////
98
99 // private LinkedHashMap<NodeRef, int[]> sequenceMap;
100 //
101 // public void setSequenceMap(LinkedHashMap<NodeRef, int[]> sequenceMap) {
102 // this.sequenceMap = sequenceMap;
103 // }
104 //
105 // public LinkedHashMap<NodeRef, int[]> getSequenceMap() {
106 // return sequenceMap;
107 // }
108
109 // /////////////////////////
110 // ---DEMOGRAPHIC MODEL---//
111 // /////////////////////////
112
113 //TODO: LogisticGrowth.getInverseIntensity
114 public static final int lastImplementedIndex = 3;
115
116 public int demographicModelIndex = 0;
117
118 public String demographicModelIdref = Utils.DEMOGRAPHIC_MODEL;
119
120 public void resetDemographicModelIdref() {
121 this.demographicModelIdref = Utils.DEMOGRAPHIC_MODEL;
122 }
123
124 public static String[] demographicModels = {
125 "No Model (user-specified tree)",
126 "Constant Population",
127 "Exponential Growth (Growth Rate)",
128 "Exponential Growth (Doubling Time)",
129 // "Logistic Growth (Growth Rate)",
130 // "Logistic Growth (Doubling Time)",
131 // "Expansion (Growth Rate)",
132 // "Expansion (Doubling Time)",
133 };
134
135 public static String[] demographicParameterNames = new String[] {
136 "Population Size", // Constant Population
137
138 "Population Size", // Exponential Growth (Growth Rate)
139 "Growth Rate", // Exponential Growth (Growth Rate)
140
141 "Population Size", // Exponential Growth (Doubling Time)
142 "Doubling Time", // Exponential Growth (Doubling Time)
143
144 // "Population Size", // Logistic Growth (Growth Rate)
145 // "Growth Rate", // Logistic Growth (Growth Rate)
146 // "Logistic Shape (Half-life)", // Logistic Growth (Growth Rate)
147
148 // "Population Size", // Logistic Growth (Doubling Time)
149 // "Doubling Time", // Logistic Growth (Doubling Time)
150 // "Logistic Shape (Half-life)", // Logistic Growth (Doubling Time)
151
152 // "Population Size", // Expansion (Growth Rate)
153 // "Ancestral Proportion", // Expansion (Growth Rate)
154 // "Growth Rate", // Expansion (Growth Rate)
155
156 // "Population Size", // Expansion (Doubling Time)
157 // "Ancestral Proportion", // Expansion (Doubling Time)
158 // "Doubling Time", // Expansion (Doubling Time)
159 };
160
161 public static int[][] demographicParameterIndices = {
162 { }, // No model
163 { 0 }, // Constant Population
164 { 1, 2 }, // Exponential Growth (Growth Rate)
165 { 3, 4 }, // Exponential Growth (Doubling Time)
166 // { 5, 6, 7 }, // Logistic Growth (Growth Rate)
167 // { 8, 9, 10 }, // Logistic Growth (Doubling Time)
168 // { 11, 12, 13 }, // Expansion (Growth Rate)
169 // { 14, 15, 16 } // Expansion (Doubling Time)
170 };
171
172
173 public double[] demographicParameterValues = new double[] {
174
175 /*Constant Population*/
176 1000.0, // Population Size
177
178 /*Exponential Growth (Growth Rate)*/
179 1000.0, // Population Size
180 0.5, // Growth Rate
181
182 /*Exponential Growth (Doubling Time)*/
183 1000.0, // Population Size
184 10.0, // Doubling Time
185
186 // /*Logistic Growth (Growth Rate)*/
187 // 1000.0, // Population Size
188 // 0.5, // Growth Rate
189 // 50.0, // Logistic Shape (Half-life)
190
191 // 1000.0, // Population Size
192 // 10.0, // Doubling Time
193 // 50.0, // Logistic Shape (Half-life)
194 // 1000.0, // Population Size
195 // 0.1, // Ancestral Proportion
196 // 0.5, // Growth Rate
197 // 1000.0, // Population Size
198 // 0.1, // Ancestral Proportion
199 // 10.0 // Doubling Time
200 };
201
202 public DemographicFunction createDemographicFunction() {
203
204 DemographicFunction demographicFunction = null;
205
206 if (this.demographicModelIndex == 0) { // No model
207
208 // do nothing
209
210 } else if (this.demographicModelIndex == 1) {// Constant Population
211
212 demographicFunction = new ConstantPopulation(Units.Type.YEARS);
213 ((ConstantPopulation)demographicFunction).setN0(demographicParameterValues[0]);
214
215 } else if (this.demographicModelIndex == 2) {// Exponential Growth (Growth Rate)
216
217 demographicFunction = new ExponentialGrowth(Units.Type.YEARS);
218 ((ExponentialGrowth) demographicFunction).setN0(demographicParameterValues[1]);
219 ((ExponentialGrowth) demographicFunction).setGrowthRate(demographicParameterValues[2]);
220
221 } else if (this.demographicModelIndex == 3) {// Exponential Growth (Doubling Time)
222
223 demographicFunction = new ExponentialGrowth(Units.Type.YEARS);
224 ((ExponentialGrowth) demographicFunction).setN0(demographicParameterValues[3]);
225 ((ExponentialGrowth) demographicFunction).setDoublingTime(demographicParameterValues[4]);
226
227 // } else if (this.demographicModelIndex == 4) {// Logistic Growth (Growth Rate)
228 //
229 // demographicFunction = new LogisticGrowth(Units.Type.YEARS);
230 // ((LogisticGrowth) demographicFunction).setN0(demographicParameterValues[5]);
231 // ((LogisticGrowth) demographicFunction).setGrowthRate(demographicParameterValues[6]);
232 // ((LogisticGrowth) demographicFunction).setTime50(demographicParameterValues[7]);
233 //
234 // } else if (this.demographicModelIndex == 5) {// Logistic Growth (Doubling Time)
235 //
236 // demographicFunction = new LogisticGrowth(Units.Type.YEARS);
237 // ((LogisticGrowth) demographicFunction).setN0(demographicParameterValues[8]);
238 // ((LogisticGrowth) demographicFunction).setDoublingTime(demographicParameterValues[9]);
239 // ((LogisticGrowth) demographicFunction).setTime50(demographicParameterValues[10]);
240 //
241 // } else if (this.demographicModelIndex == 6) {// Expansion (Growth Rate)
242 //
243 // demographicFunction = new Expansion(Units.Type.YEARS);
244 // ((Expansion) demographicFunction).setN0(demographicParameterValues[11]);
245 // ((Expansion) demographicFunction).setProportion(demographicParameterValues[12]);
246 // ((Expansion) demographicFunction).setGrowthRate(demographicParameterValues[13]);
247 //
248 // } else if (this.demographicModelIndex == 7) {// Expansion (Doubling Time)
249 //
250 // demographicFunction = new Expansion(Units.Type.YEARS);
251 // ((Expansion) demographicFunction).setN0(demographicParameterValues[14]);
252 // ((Expansion) demographicFunction).setProportion(demographicParameterValues[15]);
253 // ((Expansion) demographicFunction).setDoublingTime(demographicParameterValues[16]);
254
255 } else {
256
257 System.out.println("Not yet implemented");
258
259 }
260
261 return demographicFunction;
262 }// END: createDemographicFunction
263
264 // ////////////
265 // ---TAXA---//
266 // ////////////
267
268 public TreesTableRecord record = null;
269
270 public String taxaIdref = TaxaParser.TAXA;
271
272 public void resetTaxaIdref() {
273 this.taxaIdref = TaxaParser.TAXA;
274 }
275
276 // //////////////////
277 // ---TREE MODEL---//
278 // //////////////////
279
280 // public Tree tree = null;
281 public String treeModelIdref = TreeModel.TREE_MODEL;
282
283 public void resetTreeModelIdref() {
284 this.treeModelIdref = TreeModel.TREE_MODEL;
285 }
286
287 public TreeModel createTreeModel() {
288
289 TreeModel treeModel = null;
290 if (this.demographicModelIndex == 0 && this.record.isTreeSet()) {
291
292 treeModel = new TreeModel(this.record.getTree());
293
294 } else if( (this.demographicModelIndex > 0 && this.demographicModelIndex <= lastImplementedIndex) && this.record.isTreeSet()) {
295
296 Taxa taxa = new Taxa(this.record.getTree().asList());
297 CoalescentSimulator topologySimulator = new CoalescentSimulator();
298 treeModel = new TreeModel(topologySimulator.simulateTree(taxa, createDemographicFunction()));
299
300 } else if((this.demographicModelIndex > 0 && this.demographicModelIndex <= lastImplementedIndex) && this.record.isTaxaSet()) {
301
302 Taxa taxa = this.record.getTaxa();
303 CoalescentSimulator topologySimulator = new CoalescentSimulator();
304 treeModel = new TreeModel(topologySimulator.simulateTree(taxa, createDemographicFunction()));
305
306 // } else if (this.demographicModelIndex == 0 && this.record.taxaSet) {
307 // throw new RuntimeException("Data and demographic model incompatible for partition ");
308
309 } else {
310
311 throw new RuntimeException("Data and demographic model incompatible.");
312
313 }// END: demo model check
314
315 return treeModel;
316 }//END: createTreeModel
317
318 // /////////////////
319 // ---DATA TYPE---//
320 // /////////////////
321
322 public int dataTypeIndex = 0;
323
324 public static String[] dataTypes = { "Nucleotide", //
325 "Codon", //
326 "Amino acid" //
327 };
328
329 public DataType createDataType() {
330
331 DataType dataType = null;
332
333 if (this.dataTypeIndex == 0) { // Nucleotide
334
335 dataType = Nucleotides.INSTANCE;
336
337 } else if (this.dataTypeIndex == 1) { // Codon
338
339 dataType = Codons.UNIVERSAL;
340
341 } else if (this.dataTypeIndex == 2) { // AminoAcid
342
343 dataType = AminoAcids.INSTANCE;
344
345 } else {
346
347 System.out.println("Not yet implemented");
348
349 }
350
351 return dataType;
352 }// END: createDataType
353
354 // ///////////////////////////
355 // ---SUBSTITUTION MODELS---//
356 // ///////////////////////////
357
358 public int substitutionModelIndex = 0;
359
360 public String substitutionModelIdref = Utils.SUBSTITUTION_MODEL;
361
362 public void resetSubstitutionModelIdref() {
363 this.substitutionModelIdref = Utils.SUBSTITUTION_MODEL;
364 }
365
366 public static String[] substitutionModels = { "HKY", //
367 "GTR", //
368 "TN93", //
369 "GY94CodonModel", //
370 "MG94CodonModel",
371 "Blosum62", //
372 "CPREV", //
373 "Dayhoff", //
374 "FLU", //
375 "JTT", //
376 "LG", //
377 "MTREV", //
378 "WAG" //
379 };
380
381 public static int[] substitutionCompatibleDataTypes = { 0, // HKY
382 0, // GTR
383 0, // TN93
384 1, // GY94CodonModel
385 1, // MG94CodonModel
386 2, // Blosum62
387 2, // CPREV
388 2, // Dayhoff
389 2, // FLU
390 2, // JTT
391 2, // LG
392 2, // MTREV
393 2 // WAG
394 };
395
396 public static String[] substitutionParameterNames = new String[] {
397 "Kappa value", // HKY
398 "AC", // GTR
399 "AG", // GTR
400 "AT", // GTR
401 "CG", // GTR
402 "CT", // GTR
403 "GT", // GTR
404 "Kappa 1 (A-G)", // TN93
405 "Kappa 2 (C-T)", // TN93
406 "Omega value", // GY94CodonModel
407 "Kappa value", // GY94CodonModel
408 "Alpha value", // MG94CodonModel
409 "Beta value", // MG94CodonModel
410 "Kappa value" // MG94CodonModel
411
412 };
413
414 public static int[][] substitutionParameterIndices = { { 0 }, // HKY
415 { 1, 2, 3, 4, 5, 6 }, // GTR
416 { 7, 8 }, // TN93
417 { 9, 10 }, // GY94CodonModel
418 {11, 12, 13}, // MG94CodonModel
419 {}, // Blosum62
420 {}, // CPREV
421 {}, // Dayhoff
422 {}, // FLU
423 {}, // JTT
424 {}, // LG
425 {}, // MTREV
426 {} // WAG
427 };
428
429 public double[] substitutionParameterValues = new double[] { 1.0, // Kappa-value
430 1.0, // AC
431 1.0, // AG
432 1.0, // AT
433 1.0, // CG
434 1.0, // CT
435 1.0, // GT
436 1.0, // Kappa 1
437 1.0, // Kappa 2
438 0.1, // Omega value
439 1.0, // Kappa value
440 10.0, // Alpha value
441 1.0, // Beta value
442 1.0 // kappa value
443 };
444
445 public BranchModel createBranchModel() {
446
447 BranchModel branchModel = null;
448
449 if (this.substitutionModelIndex == 0) { // HKY
450
451 Parameter kappa = new Parameter.Default(1, substitutionParameterValues[0]);
452
453 FrequencyModel frequencyModel = this.createFrequencyModel();
454
455 HKY hky = new HKY(kappa, frequencyModel);
456
457 branchModel = new HomogeneousBranchModel(hky);
458
459 } else if (this.substitutionModelIndex == 1) { // GTR
460
461 Parameter ac = new Parameter.Default(1,
462 substitutionParameterValues[1]);
463 Parameter ag = new Parameter.Default(1,
464 substitutionParameterValues[2]);
465 Parameter at = new Parameter.Default(1,
466 substitutionParameterValues[3]);
467 Parameter cg = new Parameter.Default(1,
468 substitutionParameterValues[4]);
469 Parameter ct = new Parameter.Default(1,
470 substitutionParameterValues[5]);
471 Parameter gt = new Parameter.Default(1,
472 substitutionParameterValues[6]);
473
474 FrequencyModel frequencyModel = this.createFrequencyModel();
475
476 GTR gtr = new GTR(ac, ag, at, cg, ct, gt, frequencyModel);
477
478 branchModel = new HomogeneousBranchModel(gtr);
479
480 } else if (this.substitutionModelIndex == 2) { // TN93
481
482 Parameter kappa1 = new Parameter.Default(1,
483 substitutionParameterValues[7]);
484 Parameter kappa2 = new Parameter.Default(1,
485 substitutionParameterValues[8]);
486
487 FrequencyModel frequencyModel = this.createFrequencyModel();
488
489 TN93 tn93 = new TN93(kappa1, kappa2, frequencyModel);
490
491 branchModel = new HomogeneousBranchModel(tn93);
492
493 } else if (this.substitutionModelIndex == 3) { // Yang Codon Model
494
495 FrequencyModel frequencyModel = this.createFrequencyModel();
496
497 Parameter kappa = new Parameter.Default(1,
498 substitutionParameterValues[9]);
499 Parameter omega = new Parameter.Default(1,
500 substitutionParameterValues[10]);
501
502 GY94CodonModel yangCodonModel = new GY94CodonModel(
503 Codons.UNIVERSAL, omega, kappa, frequencyModel);
504
505 branchModel = new HomogeneousBranchModel(yangCodonModel);
506
507
508 } else if(this.substitutionModelIndex == 4) { // MG94CodonModel
509
510
511 FrequencyModel frequencyModel = this.createFrequencyModel();
512
513 Parameter alpha = new Parameter.Default(1, substitutionParameterValues[11]);
514 Parameter beta = new Parameter.Default(1, substitutionParameterValues[12]);
515 Parameter kappa = new Parameter.Default(1, substitutionParameterValues[13]);
516
517 MG94HKYCodonModel mg94 = new MG94HKYCodonModel(Codons.UNIVERSAL, alpha, beta, kappa, frequencyModel);
518
519 branchModel = new HomogeneousBranchModel(mg94);
520
521 } else if (this.substitutionModelIndex == 5) { // Blosum62
522
523 FrequencyModel frequencyModel = this.createFrequencyModel();
524
525 EmpiricalRateMatrix rateMatrix = Blosum62.INSTANCE;
526
527 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
528 rateMatrix, frequencyModel);
529
530 branchModel = new HomogeneousBranchModel(
531 empiricalAminoAcidModel);
532
533 } else if (this.substitutionModelIndex == 6) { // CPREV
534
535 FrequencyModel frequencyModel = this.createFrequencyModel();
536
537 EmpiricalRateMatrix rateMatrix = CPREV.INSTANCE;
538
539 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
540 rateMatrix, frequencyModel);
541
542 branchModel = new HomogeneousBranchModel(
543 empiricalAminoAcidModel);
544
545 } else if (this.substitutionModelIndex == 7) { // Dayhoff
546
547 FrequencyModel frequencyModel = this.createFrequencyModel();
548
549 EmpiricalRateMatrix rateMatrix = Dayhoff.INSTANCE;
550
551 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
552 rateMatrix, frequencyModel);
553
554 branchModel = new HomogeneousBranchModel(
555 empiricalAminoAcidModel);
556
557 } else if (this.substitutionModelIndex == 8) { // JTT
558
559 FrequencyModel frequencyModel = this.createFrequencyModel();
560
561 EmpiricalRateMatrix rateMatrix = JTT.INSTANCE;
562
563 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
564 rateMatrix, frequencyModel);
565
566 branchModel = new HomogeneousBranchModel(
567 empiricalAminoAcidModel);
568
569 } else if (this.substitutionModelIndex == 9) { // LG
570
571 FrequencyModel frequencyModel = this.createFrequencyModel();
572
573 EmpiricalRateMatrix rateMatrix = LG.INSTANCE;
574
575 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
576 rateMatrix, frequencyModel);
577
578 branchModel = new HomogeneousBranchModel(
579 empiricalAminoAcidModel);
580
581 } else if (this.substitutionModelIndex == 10) { // MTREV
582
583 FrequencyModel frequencyModel = this.createFrequencyModel();
584
585 EmpiricalRateMatrix rateMatrix = MTREV.INSTANCE;
586
587 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
588 rateMatrix, frequencyModel);
589
590 branchModel = new HomogeneousBranchModel(
591 empiricalAminoAcidModel);
592
593 } else if (this.substitutionModelIndex == 11) { // WAG
594
595 FrequencyModel frequencyModel = this.createFrequencyModel();
596
597 EmpiricalRateMatrix rateMatrix = WAG.INSTANCE;
598
599 EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel(
600 rateMatrix, frequencyModel);
601
602 branchModel = new HomogeneousBranchModel(
603 empiricalAminoAcidModel);
604
605 } else {
606
607 System.out.println("Not yet implemented");
608
609 }
610
611 return branchModel;
612 }// END: createBranchSubstitutionModel
613
614 // ////////////////////////
615 // ---FREQUENCY MODELS---//
616 // ////////////////////////
617
618 public String frequencyModelIdref = Utils.FREQUENCY_MODEL;
619
620 public void resetFrequencyModelIdref() {
621 this.frequencyModelIdref = Utils.FREQUENCY_MODEL;
622 }
623
624 public int frequencyModelIndex = 0;
625
626 public static String[] frequencyModels = { "Nucleotide frequencies", //
627 "Codon frequencies", //
628 "Amino acid frequencies"
629 };
630
631 public static int[] frequencyCompatibleDataTypes = { 0, // Nucleotide
632 1, // Codon
633 2 // Amino acid
634 };
635
636 public static String[] frequencyParameterNames = new String[] {
637 "A frequency", // Nucleotide frequencies
638 "C frequency", // Nucleotide frequencies
639 "G frequency", // Nucleotide frequencies
640 "T frequency", // Nucleotide frequencies
641 "AAA frequency", // Codon frequencies
642 "AAC frequency", //
643 "AAG frequency", //
644 "AAT frequency", //
645 "ACA frequency", //
646 "ACC frequency", //
647 "ACG frequency", //
648 "ACT frequency", //
649 "AGA frequency", //
650 "AGC frequency", //
651 "AGG frequency", //
652 "AGT frequency", //
653 "ATA frequency", //
654 "ATC frequency", //
655 "ATG frequency", //
656 "ATT frequency", //
657 "CAA frequency", //
658 "CAC frequency", //
659 "CAG frequency", //
660 "CAT frequency", //
661 "CCA frequency", //
662 "CCC frequency", //
663 "CCG frequency", //
664 "CCT frequency", //
665 "CGA frequency", //
666 "CGC frequency", //
667 "CGG frequency", //
668 "CGT frequency", //
669 "CTA frequency", //
670 "CTC frequency", //
671 "CTG frequency", //
672 "CTT frequency", //
673 "GAA frequency", //
674 "GAC frequency", //
675 "GAG frequency", //
676 "GAT frequency", //
677 "GCA frequency", //
678 "GCC frequency", //
679 "GCG frequency", //
680 "GCT frequency", //
681 "GGA frequency", //
682 "GGC frequency", //
683 "GGG frequency", //
684 "GGT frequency", //
685 "GTA frequency", //
686 "GTC frequency", //
687 "GTG frequency", //
688 "GTT frequency", //
689 "TAC frequency", //
690 "TAT frequency", //
691 "TCA frequency", //
692 "TCC frequency", //
693 "TCG frequency", //
694 "TCT frequency", //
695 "TGC frequency", //
696 "TGG frequency", //
697 "TGT frequency", //
698 "TTA frequency", //
699 "TTC frequency", //
700 "TTG frequency", //
701 "TTT frequency", // Codon frequencies
702 "amino acid frequency 1", //
703 "amino acid frequency 2", //
704 "amino acid frequency 3", //
705 "amino acid frequency 4", //
706 "amino acid frequency 5", //
707 "amino acid frequency 6", //
708 "amino acid frequency 7", //
709 "amino acid frequency 8", //
710 "amino acid frequency 9", //
711 "amino acid frequency 10", //
712 "amino acid frequency 11", //
713 "amino acid frequency 12", //
714 "amino acid frequency 13", //
715 "amino acid frequency 14", //
716 "amino acid frequency 15", //
717 "amino acid frequency 16", //
718 "amino acid frequency 17", //
719 "amino acid frequency 18", //
720 "amino acid frequency 19", //
721 "amino acid frequency 20" //
722
723 };
724
725 public int[][] frequencyParameterIndices = { { 0, 1, 2, 3 }, // NucleotideFrequencies
726 { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, //
727 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, //
728 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, //
729 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, //
730 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, //
731 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, //
732 64 }, // CodonFrequencies
733 { 65, 66, 67, 68, 69, //
734 70, 71, 72, 73, 74, //
735 75, 76, 77, 78, 79, //
736 80, 81, 82, 83, 84 //
737 } // AminoAcidFrequencies
738 };
739
740 public double[] frequencyParameterValues = new double[] { 0.25, // A frequency
741 0.25, // C frequency
742 0.25, // G frequency
743 0.25, // T frequency
744 0.0163936, // AAA frequency
745 0.01639344, //
746 0.01639344, //
747 0.01639344, //
748 0.01639344, //
749 0.01639344, //
750 0.01639344, //
751 0.01639344, //
752 0.01639344, //
753 0.01639344, //
754 0.01639344, //
755 0.01639344, //
756 0.01639344, //
757 0.01639344, //
758 0.01639344, //
759 0.01639344, //
760 0.01639344, //
761 0.01639344, //
762 0.01639344, //
763 0.01639344, //
764 0.01639344, //
765 0.01639344, //
766 0.01639344, //
767 0.01639344, //
768 0.01639344, //
769 0.01639344, //
770 0.01639344, //
771 0.01639344, //
772 0.01639344, //
773 0.01639344, //
774 0.01639344, //
775 0.01639344, //
776 0.01639344, //
777 0.01639344, //
778 0.01639344, //
779 0.01639344, //
780 0.01639344, //
781 0.01639344, //
782 0.01639344, //
783 0.01639344, //
784 0.01639344, //
785 0.01639344, //
786 0.01639344, //
787 0.01639344, //
788 0.01639344, //
789 0.01639344, //
790 0.01639344, //
791 0.01639344, //
792 0.01639344, //
793 0.01639344, //
794 0.01639344, //
795 0.01639344, //
796 0.01639344, //
797 0.01639344, //
798 0.01639344, //
799 0.01639344, //
800 0.01639344, //
801 0.01639344, //
802 0.01639344, //
803 0.01639344, //
804 0.01639344, // TTT frequency
805 0.05, // aminoacidfrequency1
806 0.05, // aminoacidfrequency2
807 0.05, // aminoacidfrequency3
808 0.05, // aminoacidfrequency4
809 0.05, // aminoacidfrequency5
810 0.05, // aminoacidfrequency6
811 0.05, // aminoacidfrequency7
812 0.05, // aminoacidfrequency8
813 0.05, // aminoacidfrequency9
814 0.05, // aminoacidfrequency10
815 0.05, // aminoacidfrequency11
816 0.05, // aminoacidfrequency12
817 0.05, // aminoacidfrequency13
818 0.05, // aminoacidfrequency14
819 0.05, // aminoacidfrequency15
820 0.05, // aminoacidfrequency16
821 0.05, // aminoacidfrequency17
822 0.05, // aminoacidfrequency18
823 0.05, // aminoacidfrequency19
824 0.05 // aminoacidfrequency20
825 };
826
827 public FrequencyModel createFrequencyModel() {
828
829 FrequencyModel frequencyModel = null;
830
831 if (this.frequencyModelIndex == 0) { // Nucleotidefrequencies
832
833 Parameter freqs = new Parameter.Default(new double[] {
834 frequencyParameterValues[0], frequencyParameterValues[1],
835 frequencyParameterValues[2], frequencyParameterValues[3] });
836
837 DataType dataType = this.createDataType();
838
839 frequencyModel = new FrequencyModel(dataType, freqs);
840
841 } else if (this.frequencyModelIndex == 1) {
842
843 Parameter freqs = new Parameter.Default(new double[] {
844 frequencyParameterValues[4], frequencyParameterValues[5],
845 frequencyParameterValues[6], frequencyParameterValues[7],
846 frequencyParameterValues[8], frequencyParameterValues[9],
847 frequencyParameterValues[10], frequencyParameterValues[11],
848 frequencyParameterValues[12], frequencyParameterValues[13],
849 frequencyParameterValues[14], frequencyParameterValues[15],
850 frequencyParameterValues[16], frequencyParameterValues[17],
851 frequencyParameterValues[18], frequencyParameterValues[19],
852 frequencyParameterValues[20], frequencyParameterValues[21],
853 frequencyParameterValues[22], frequencyParameterValues[23],
854 frequencyParameterValues[24], frequencyParameterValues[25],
855 frequencyParameterValues[26], frequencyParameterValues[27],
856 frequencyParameterValues[28], frequencyParameterValues[29],
857 frequencyParameterValues[30], frequencyParameterValues[31],
858 frequencyParameterValues[32], frequencyParameterValues[33],
859 frequencyParameterValues[34], frequencyParameterValues[35],
860 frequencyParameterValues[36], frequencyParameterValues[37],
861 frequencyParameterValues[38], frequencyParameterValues[39],
862 frequencyParameterValues[40], frequencyParameterValues[41],
863 frequencyParameterValues[42], frequencyParameterValues[43],
864 frequencyParameterValues[44], frequencyParameterValues[45],
865 frequencyParameterValues[46], frequencyParameterValues[47],
866 frequencyParameterValues[48], frequencyParameterValues[49],
867 frequencyParameterValues[50], frequencyParameterValues[51],
868 frequencyParameterValues[52], frequencyParameterValues[53],
869 frequencyParameterValues[54], frequencyParameterValues[55],
870 frequencyParameterValues[56], frequencyParameterValues[57],
871 frequencyParameterValues[58], frequencyParameterValues[59],
872 frequencyParameterValues[60], frequencyParameterValues[61],
873 frequencyParameterValues[62], frequencyParameterValues[63],
874 frequencyParameterValues[64] });
875
876 DataType dataType = this.createDataType();
877
878 frequencyModel = new FrequencyModel(dataType, freqs);
879
880 } else if (this.frequencyModelIndex == 2) {
881
882 Parameter freqs = new Parameter.Default(new double[] {
883 frequencyParameterValues[65], frequencyParameterValues[66], frequencyParameterValues[67], frequencyParameterValues[68],
884 frequencyParameterValues[69], frequencyParameterValues[70], frequencyParameterValues[71], frequencyParameterValues[72],
885 frequencyParameterValues[73], frequencyParameterValues[74], frequencyParameterValues[75], frequencyParameterValues[76],
886 frequencyParameterValues[77], frequencyParameterValues[78], frequencyParameterValues[79], frequencyParameterValues[80],
887 frequencyParameterValues[81], frequencyParameterValues[82], frequencyParameterValues[83], frequencyParameterValues[84]
888 });
889
890 DataType dataType = this.createDataType();
891
892 frequencyModel = new FrequencyModel(dataType, freqs);
893
894 } else {
895
896 System.out.println("Not yet implemented");
897
898 }
899
900 return frequencyModel;
901 }// END: createFrequencyModel
902
903 // ////////////////////
904 // ---CLOCK MODELS---//
905 // ////////////////////
906
907 public int clockModelIndex = 0;
908 public int LRC_INDEX = 1;
909
910 public String clockModelIdref = BranchRateModel.BRANCH_RATES;
911
912 public void resetClockModelIdref() {
913 this.clockModelIdref = BranchRateModel.BRANCH_RATES;
914 }
915
916 public static String[] clockModels = { "Strict Clock", // 0
917 "Lognormal relaxed clock (Uncorrelated)", // 1
918 "Exponential relaxed clock (Uncorrelated)", // 2
919 "Inverse Gaussian relaxed clock" // 3
920 };
921
922 public static String[] clockParameterNames = new String[] { "clock.rate", // StrictClock
923 "ucld.mean", // Lognormal relaxed clock
924 "ucld.stdev", // Lognormal relaxed clock
925 "ucld.offset", // Lognormal relaxed clock
926 "uced.mean", // Exponential relaxed clock
927 "uced.offset", // Exponential relaxed clock
928 "ig.mean", // Inverse Gaussian
929 "ig.stdev", // Inverse Gaussian
930 "ig.offset" // Inverse Gaussian
931 };
932
933 public static int[][] clockParameterIndices = { { 0 }, // StrictClock
934 { 1, 2, 3 }, // Lognormal relaxed clock
935 { 4, 5 }, // Exponential relaxed clock
936 { 6, 7, 8 } // Inverse Gaussian
937 };
938
939 public double[] clockParameterValues = new double[] { 1.0, // clockrate
940 0.001, // ucld.mean
941 1.0, // ucld.stdev
942 0.0, // ucld.offset
943 1.0, // uced.mean
944 0.0, // uced.offset
945 0.0, // ig.mean
946 1.0, // ig.stdev
947 0.0 // ig.offset
948 };
949
950 public boolean lrcParametersInRealSpace = true;
951
952 public BranchRateModel createClockRateModel() {
953
954 BranchRateModel branchRateModel = null;
955
956 if (this.clockModelIndex == 0) { // Strict Clock
957
958 Parameter rateParameter = new Parameter.Default(1, clockParameterValues[0]);
959
960 branchRateModel = new StrictClockBranchRates(rateParameter);
961
962 } else if (this.clockModelIndex == LRC_INDEX) {// Lognormal relaxed clock
963
964 double numberOfBranches = 2 * (createTreeModel().getTaxonCount() - 1);
965 Parameter rateCategoryParameter = new Parameter.Default(numberOfBranches);
966
967 Parameter mean = new Parameter.Default(LogNormalDistributionModelParser.MEAN, 1, clockParameterValues[1]);
968 Parameter stdev = new Parameter.Default(LogNormalDistributionModelParser.STDEV, 1, clockParameterValues[2]);
969 //TODO: choose between log scale / real scale
970 ParametricDistributionModel distributionModel = new LogNormalDistributionModel(mean, stdev, clockParameterValues[3], lrcParametersInRealSpace);
971
972 branchRateModel = new DiscretizedBranchRates(createTreeModel(), //
973 rateCategoryParameter, //
974 distributionModel, //
975 1, //
976 false, //
977 Double.NaN, //
978 true, //randomizeRates
979 false, // keepRates
980 false // cacheRates
981 );
982
983 } else if(this.clockModelIndex == 2) { // Exponential relaxed clock
984
985 double numberOfBranches = 2 * (createTreeModel().getTaxonCount() - 1);
986 Parameter rateCategoryParameter = new Parameter.Default(numberOfBranches);
987
988 Parameter mean = new Parameter.Default(DistributionModelParser.MEAN, 1, clockParameterValues[4]);
989 ParametricDistributionModel distributionModel = new ExponentialDistributionModel(mean, clockParameterValues[5]);
990
991 // branchRateModel = new DiscretizedBranchRates(createTreeModel(), rateCategoryParameter,
992 // distributionModel, 1, false, Double.NaN);
993
994 branchRateModel = new DiscretizedBranchRates(createTreeModel(), //
995 rateCategoryParameter, //
996 distributionModel, //
997 1, //
998 false, //
999 Double.NaN, //
1000 true, //randomizeRates
1001 false, // keepRates
1002 false // cacheRates
1003 );
1004
1005 } else if(this.clockModelIndex == 3) { // Inverse Gaussian
1006
1007 double numberOfBranches = 2 * (createTreeModel().getTaxonCount() - 1);
1008 Parameter rateCategoryParameter = new Parameter.Default(numberOfBranches);
1009
1010 Parameter mean = new Parameter.Default(InverseGaussianDistributionModelParser.MEAN, 1, clockParameterValues[6]);
1011 Parameter stdev = new Parameter.Default(InverseGaussianDistributionModelParser.STDEV, 1, clockParameterValues[7]);
1012 ParametricDistributionModel distributionModel = new InverseGaussianDistributionModel(
1013 mean, stdev, clockParameterValues[8], false);
1014
1015 branchRateModel = new DiscretizedBranchRates(createTreeModel(), //
1016 rateCategoryParameter, //
1017 distributionModel, //
1018 1, //
1019 false, //
1020 Double.NaN, //
1021 true, //randomizeRates
1022 false, // keepRates
1023 false // cacheRates
1024 );
1025
1026 } else {
1027
1028 System.out.println("Not yet implemented");
1029
1030 }
1031
1032 return branchRateModel;
1033 }// END: createBranchRateModel
1034
1035 // ///////////////////////
1036 // ---SITE RATE MODEL---//
1037 // ///////////////////////
1038
1039 public int siteRateModelIndex = 0;
1040
1041 public String siteRateModelIdref = SiteModel.SITE_MODEL;
1042
1043 public void resetSiteRateModelIdref() {
1044 this.siteRateModelIdref = SiteModel.SITE_MODEL;
1045 }
1046
1047 public static String[] siteRateModels = { "No Model", //
1048 "Gamma Site Rate Model" //
1049 };
1050
1051 public static String[] siteRateModelParameterNames = new String[] {
1052 "Gamma categories", // Gamma Site Rate Model
1053 "Alpha", // Gamma Site Rate Model
1054 "Invariant sites proportion" // Gamma Site Rate Model
1055 };
1056
1057 public static int[][] siteRateModelParameterIndices = { {}, // NoModel
1058 { 0, 1, 2 }, // GammaSiteRateModel
1059 };
1060
1061 public double[] siteRateModelParameterValues = new double[] { 4.0, // GammaCategories
1062 0.5, // Alpha
1063 0.0 // Invariant sites proportion
1064 };
1065
1066 public GammaSiteRateModel createSiteRateModel() {
1067
1068 GammaSiteRateModel siteModel = null;
1069 String name = "siteModel";
1070
1071 if (this.siteRateModelIndex == 0) { // no model
1072
1073 siteModel = new GammaSiteRateModel(name);
1074
1075 } else if (this.siteRateModelIndex == 1) { // GammaSiteRateModel
1076
1077 siteModel = new GammaSiteRateModel(name,
1078 siteRateModelParameterValues[1],
1079 (int) siteRateModelParameterValues[0], siteRateModelParameterValues[2]);
1080
1081 } else {
1082
1083 System.out.println("Not yet implemented");
1084
1085 }
1086
1087 return siteModel;
1088 }// END: createGammaSiteRateModel
1089
1090 // //////////////////////////
1091 // ---ANCESTRAL SEQUENCE---//
1092 // //////////////////////////
1093
1094 public String ancestralSequenceString = null;
1095
1096 public Sequence createAncestralSequence() {
1097
1098 Sequence sequence = new Sequence(ancestralSequenceString);
1099 // sequence.appendSequenceString(ancestralSequenceString);
1100
1101 return sequence;
1102 }
1103
1104 }// END: class
1105