Debian Codegraph @

src/dr/app/beauti/components/ancestralstates/AncestralStatesComponentOptions.java

raw symbols SCIP
1 /*
2 * AncestralStatesComponentOptions.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.components.ancestralstates;
27
28 import dr.app.beauti.options.*;
29
30 import java.io.Serializable;
31 import java.util.*;
32
33 /**
34 * @author Andrew Rambaut
35 * @version $Id$
36 */
37 public class AncestralStatesComponentOptions implements ComponentOptions {
38
39 public AncestralStatesComponentOptions() {
40 }
41
42 public void createParameters(final ModelOptions modelOptions) {
43 }
44
45 public void selectParameters(final ModelOptions modelOptions, final List<Parameter> params) {
46 }
47
48 public void selectStatistics(final ModelOptions modelOptions, final List<Parameter> stats) {
49 // no statistics required
50 }
51
52 public void selectOperators(final ModelOptions modelOptions, final List<Operator> ops) {
53 }
54
55 private AncestralStateOptions getOptions(final AbstractPartitionData partition) {
56 AncestralStateOptions options = ancestralStateOptionsMap.get(partition);
57 if (options == null) {
58 options = new AncestralStateOptions();
59 ancestralStateOptionsMap.put(partition, options);
60 }
61 return options;
62 }
63
64 public boolean usingAncestralStates(final AbstractPartitionData partition) {
65 return reconstructAtNodes(partition) || reconstructAtMRCA(partition) || isCountingStates(partition) || dNdSRobustCounting(partition);
66 }
67
68 public boolean reconstructAtNodes(final AbstractPartitionData partition) {
69 return getOptions(partition).reconstructAtNodes;
70 }
71
72 public void setReconstructAtNodes(final AbstractPartitionData partition, boolean reconstructAtNodes) {
73 getOptions(partition).reconstructAtNodes = reconstructAtNodes;
74 }
75
76 public boolean reconstructAtMRCA(final AbstractPartitionData partition) {
77 return getOptions(partition).reconstructAtMRCA;
78 }
79
80 public void setReconstructAtMRCA(final AbstractPartitionData partition, boolean reconstructAtMRCA) {
81 getOptions(partition).reconstructAtMRCA = reconstructAtMRCA;
82 }
83
84 public String getMRCATaxonSet(final AbstractPartitionData partition) {
85 AncestralStateOptions options = ancestralStateOptionsMap.get(partition);
86 return options.mrcaTaxonSetName;
87 }
88
89 public void setMRCATaxonSet(final AbstractPartitionData partition, String taxonSetName) {
90 getOptions(partition).mrcaTaxonSetName = taxonSetName;
91 }
92
93 public boolean isCountingStates(final AbstractPartitionData partition) {
94 return getOptions(partition).countingStates;
95 }
96
97 public void setCountingStates(final AbstractPartitionData partition, boolean isCountingStates) {
98 getOptions(partition).countingStates = isCountingStates;
99 }
100
101 public boolean isCompleteHistoryLogging(final AbstractPartitionData partition) {
102 return getOptions(partition).isCompleteHistoryLogging;
103 }
104
105 public void setCompleteHistoryLogging(final AbstractPartitionData partition, boolean isCompleteHistoryLogging) {
106 getOptions(partition).isCompleteHistoryLogging = isCompleteHistoryLogging;
107 }
108
109
110 public boolean dNdSRobustCounting(final AbstractPartitionData partition) {
111 return getOptions(partition).dNdSRobustCounting;
112 }
113
114 public void setDNdSRobustCounting(final AbstractPartitionData partition, boolean dNdSRobustCounting) {
115 if (dNdSRobustCounting && partition.getPartitionSubstitutionModel().getCodonPartitionCount() != 3) {
116 throw new IllegalArgumentException("dNdS Robust Counting can only be used with 3 codon partition models.");
117 }
118 if (dNdSRobustCounting && (partition.getPartitionSubstitutionModel().isGammaHetero() ||
119 partition.getPartitionSubstitutionModel().isInvarHetero())) {
120 throw new IllegalArgumentException("dNdS Robust Counting can only be when site-specific rate heterogeneity is off.");
121 }
122 getOptions(partition).dNdSRobustCounting = dNdSRobustCounting;
123 }
124
125 public boolean dNdSRobustCountingAvailable(final AbstractPartitionData partition) {
126 // todo - are there other constraints of the use of this model?
127 return partition.getPartitionSubstitutionModel().getCodonPartitionCount() == 3 &&
128 !partition.getPartitionSubstitutionModel().isGammaHetero() &&
129 !partition.getPartitionSubstitutionModel().isInvarHetero();
130 }
131
132 class AncestralStateOptions implements Serializable {
133 boolean reconstructAtNodes = false;
134 boolean reconstructAtMRCA = false;
135 String mrcaTaxonSetName = null;
136 boolean countingStates = false;
137 boolean isCompleteHistoryLogging = false;
138 boolean dNdSRobustCounting = false;
139 };
140
141 private final Map<AbstractPartitionData, AncestralStateOptions> ancestralStateOptionsMap = new HashMap<AbstractPartitionData, AncestralStateOptions>();
142
143 }