Debian Codegraph @

src/dr/evolution/datatype/TwoStateCovarion.java

raw symbols SCIP
1 /*
2 * TwoStateCovarion.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.evolution.datatype;
27
28 /**
29 * @author Helen Shearman
30 * @author Alexei Drummond
31 */
32 public class TwoStateCovarion extends DataType {
33
34 public static final String DESCRIPTION = "twoStateCovarion";
35 public static final int TYPE = COVARION;
36 public static final TwoStateCovarion INSTANCE = new TwoStateCovarion();
37
38 private TwoStateCovarion() {
39 stateCount = 4;
40 ambiguousStateCount = 8;
41 }
42
43 @Override
44 public char[] getValidChars() {
45 return null;
46 }
47
48 public int getState(char c) {
49 switch (c) {
50 case 'a':
51 return 0;
52 case 'b':
53 return 1;
54 case 'c':
55 return 2;
56 case 'd':
57 return 3;
58 case '0':
59 return 4;
60 case '1':
61 return 5;
62 case '?':
63 return getUnknownState();
64 case '-':
65 return getGapState();
66 }
67 throw new IllegalArgumentException("Character " + c + " not recognised in two-state covarion datatype!");
68 }
69
70 public char getChar(int state) {
71
72 switch (state) {
73 case 0:
74 return 'a';
75 case 1:
76 return 'b';
77 case 2:
78 return 'c';
79 case 3:
80 return 'd';
81 case 4:
82 return '0';
83 case 5:
84 return '1';
85 case 6:
86 return '?';
87 case 7:
88 return '-';
89 }
90 throw new IllegalArgumentException("State " + state + " not recognised in two-state covarion datatype!");
91 }
92
93 /**
94 * returns an array containing the non-ambiguous states
95 * that this state represents.
96 */
97 public int[] getStates(int state) {
98
99 if (state == 4 || state == 5) {
100 int[] states = new int[2];
101 states[0] = state % 2;
102 states[1] = state % 2 + 2;
103 return states;
104 } else throw new IllegalArgumentException();
105 }
106
107 /**
108 * returns an array containing the non-ambiguous states that this state represents.
109 */
110 public boolean[] getStateSet(int state) {
111
112 boolean[] stateSet = new boolean[stateCount];
113 for (int i = 0; i < stateCount; i++) {
114 stateSet[i] = false;
115 }
116 if (!isAmbiguousState(state)) {
117 stateSet[state] = true;
118 } else if (state == 4 || state == 5) {
119 for (int i = 0; i < stateCount; i++) {
120 if ((i % 2) == (state % 2)) {
121 stateSet[i] = true;
122 }
123 }
124 } else {
125 for (int i = 0; i < stateCount; i++) {
126 stateSet[i] = true;
127 }
128 }
129 return stateSet;
130 }
131
132 public int getUnknownState() {
133 return stateCount + 2;
134 }
135
136 public int getGapState() {
137 return stateCount + 3;
138 }
139
140 public boolean isAmbiguousChar(char c) {
141 return isAmbiguousState(getState(c));
142 }
143
144 public boolean isUnknownChar(char c) {
145 return isUnknownState(getState(c));
146 }
147
148 public boolean isGapChar(char c) {
149 return isGapState(getState(c));
150 }
151
152 public boolean isAmbiguousState(int state) {
153 return (state >= 4);
154 }
155
156 public boolean isUnknownState(int state) {
157 return (state == getUnknownState());
158 }
159
160 public boolean isGapState(int state) {
161 return (state == getGapState());
162 }
163
164
165 public String getDescription() {
166 return DESCRIPTION;
167 }
168
169 public int getType() {
170 return TYPE;
171 }
172
173 }