Debian Codegraph @

src/dr/evolution/alignment/Alignment.java

raw symbols SCIP
1 /*
2 * Alignment.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.alignment;
27
28 import dr.evolution.datatype.DataType;
29 import dr.evolution.sequence.SequenceList;
30
31 /**
32 * interface for any alignment data.
33 *
34 * @version $Id: Alignment.java,v 1.12 2005/05/24 20:25:55 rambaut Exp $
35 *
36 * @author Andrew Rambaut
37 * @author Alexei Drummond
38 */
39 public interface Alignment extends SequenceList, SiteList
40 {
41
42 /**
43 * Sets the dataType of this alignment. This can be different from
44 * the actual dataTypes of the sequences - they will be translated
45 * as required.
46 */
47 void setDataType(DataType dataType);
48
49 /**
50 /**
51 * Returns string representation of single sequence in
52 * alignment with gap characters included.
53 */
54 String getAlignedSequenceString(int sequenceIndex);
55
56 /**
57 * Returns string representation of single sequence in
58 * alignment with gap characters excluded.
59 */
60 String getUnalignedSequenceString(int sequenceIndex);
61
62 public abstract class Abstract implements Alignment {
63 // **************************************************************
64 // PatternList IMPLEMENTATION
65 // **************************************************************
66
67 /**
68 * @return number of patterns
69 */
70 public int getPatternCount() {
71 return getSiteCount();
72 }
73
74 /**
75 * @return number of invariant sites
76 */
77 public int getInvariantCount() {
78 throw new RuntimeException("Not implemented yet");
79 }
80
81 /**
82 * @return number of states for this siteList
83 */
84 public int getStateCount() {
85 return getDataType().getStateCount();
86 }
87
88 /**
89 * Gets the length of the pattern strings which will usually be the
90 * same as the number of taxa
91 * @return the length of patterns
92 */
93 public int getPatternLength() {
94 return getSequenceCount();
95 }
96
97 /**
98 * Gets the pattern as an array of state numbers (one per sequence)
99 * @return the pattern at patternIndex
100 */
101 public int[] getPattern(int patternIndex) {
102 return getSitePattern(patternIndex);
103 }
104
105 @Override
106 public double[][] getUncertainPattern(int patternIndex) {
107 return getUncertainSitePattern(patternIndex);
108 }
109
110 /**
111 * @return state at (taxonIndex, patternIndex)
112 */
113 public int getPatternState(int taxonIndex, int patternIndex) {
114 return getState(taxonIndex, patternIndex);
115 }
116
117 @Override
118 public double[] getUncertainPatternState(int taxonIndex, int patternIndex) {
119 return getUncertainPatternState(taxonIndex, patternIndex);
120 }
121
122 /**
123 * Gets the weight of a site pattern (always 1.0)
124 */
125 public double getPatternWeight(int patternIndex) {
126 return 1.0;
127 }
128
129 /**
130 * @return the array of pattern weights
131 */
132 public double[] getPatternWeights() {
133 int count = getSiteCount();
134 double[] weights = new double[count];
135 for (int i = 0; i < count; i++)
136 weights[i] = 1.0;
137 return weights;
138 }
139
140 /**
141 * @return the frequency of each state
142 */
143 public double[] getStateFrequencies() {
144 return PatternList.Utils.empiricalStateFrequencies(this);
145 }
146
147 @Override
148 public boolean areUnique() {
149 return false;
150 }
151
152 // **************************************************************
153 // Identifiable IMPLEMENTATION
154 // **************************************************************
155
156 protected String id = null;
157
158 /**
159 * @return the id.
160 */
161 public String getId() {
162 return id;
163 }
164
165 /**
166 * Sets the id.
167 */
168 public void setId(String id) {
169 this.id = id;
170 }
171
172 }
173
174 }