| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evolution.alignment; |
| 27 |
|
| 28 |
import dr.evolution.datatype.*; |
| 29 |
import dr.evolution.util.Taxon; |
| 30 |
import dr.evolution.util.TaxonList; |
| 31 |
|
| 32 |
import java.util.List; |
| 33 |
import java.util.Iterator; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class SimpleSiteList implements SiteList { |
| 45 |
|
| 46 |
private final TaxonList taxonList; |
| 47 |
private final DataType dataType; |
| 48 |
|
| 49 |
private int siteCount = 0; |
| 50 |
private int[][] sitePatterns = new int[0][]; |
| 51 |
|
| 52 |
public SimpleSiteList(DataType dataType) { |
| 53 |
this.taxonList = null; |
| 54 |
this.dataType = dataType; |
| 55 |
} |
| 56 |
|
| 57 |
public SimpleSiteList(DataType dataType, TaxonList taxonList) { |
| 58 |
this.taxonList = taxonList; |
| 59 |
this.dataType = dataType; |
| 60 |
} |
| 61 |
|
| 62 |
public int addPattern(int[] pattern) { |
| 63 |
int capacity = sitePatterns.length; |
| 64 |
if (siteCount >= capacity) { |
| 65 |
capacity += 10000; |
| 66 |
int[][] newSitePatterns = new int[capacity][]; |
| 67 |
for (int i = 0; i < siteCount; i++) { |
| 68 |
newSitePatterns[i] = sitePatterns[i]; |
| 69 |
} |
| 70 |
sitePatterns = newSitePatterns; |
| 71 |
} |
| 72 |
|
| 73 |
sitePatterns[siteCount] = pattern; |
| 74 |
siteCount++; |
| 75 |
|
| 76 |
return siteCount - 1; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public int getSiteCount() { |
| 87 |
return siteCount; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public int[] getSitePattern(int siteIndex) { |
| 95 |
return sitePatterns[siteIndex]; |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public double[][] getUncertainSitePattern(int siteIndex) { |
| 100 |
throw new UnsupportedOperationException("getUncertainSitePattern not implemented yet"); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public int getPatternIndex(int siteIndex) { |
| 108 |
return siteIndex; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public int getState(int taxonIndex, int siteIndex) { |
| 115 |
return getSitePattern(siteIndex)[taxonIndex]; |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public double[] getUncertainState(int taxonIndex, int siteIndex) { |
| 120 |
throw new UnsupportedOperationException("getUncertainState not implemented yet"); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public int getPatternCount() { |
| 131 |
return getSiteCount(); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public int getStateCount() { |
| 138 |
return dataType.getStateCount(); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public int getPatternLength() { |
| 147 |
return getTaxonCount(); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public int[] getPattern(int patternIndex) { |
| 155 |
return getSitePattern(patternIndex); |
| 156 |
} |
| 157 |
|
| 158 |
@Override |
| 159 |
public double[][] getUncertainPattern(int patternIndex) { |
| 160 |
throw new UnsupportedOperationException("getUncertainPattern not implemented yet"); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public int getPatternState(int taxonIndex, int patternIndex) { |
| 167 |
return getSitePattern(patternIndex)[taxonIndex]; |
| 168 |
} |
| 169 |
|
| 170 |
@Override |
| 171 |
public double[] getUncertainPatternState(int taxonIndex, int patternIndex) { |
| 172 |
throw new UnsupportedOperationException("getUncertainPatternState not implemented yet"); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public double getPatternWeight(int patternIndex) { |
| 179 |
return 1.0; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public double[] getPatternWeights() { |
| 186 |
double[] weights = new double[getSiteCount()]; |
| 187 |
for (int i = 0; i < getSiteCount(); i++) { |
| 188 |
weights[i] = 1.0; |
| 189 |
} |
| 190 |
return weights; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public DataType getDataType() { |
| 197 |
return dataType; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public double[] getStateFrequencies() { |
| 204 |
return Utils.empiricalStateFrequencies(this); |
| 205 |
} |
| 206 |
|
| 207 |
@Override |
| 208 |
public boolean areUnique() { |
| 209 |
return false; |
| 210 |
} |
| 211 |
|
| 212 |
@Override |
| 213 |
public boolean areUncertain() { |
| 214 |
return false; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public int getTaxonCount() { |
| 225 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 226 |
return taxonList.getTaxonCount(); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public Taxon getTaxon(int taxonIndex) { |
| 233 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 234 |
return taxonList.getTaxon(taxonIndex); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public String getTaxonId(int taxonIndex) { |
| 241 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 242 |
return taxonList.getTaxonId(taxonIndex); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public int getTaxonIndex(String id) { |
| 249 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 250 |
return taxonList.getTaxonIndex(id); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
public int getTaxonIndex(Taxon taxon) { |
| 257 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 258 |
return taxonList.getTaxonIndex(taxon); |
| 259 |
} |
| 260 |
|
| 261 |
public List<Taxon> asList() { |
| 262 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 263 |
return taxonList.asList(); |
| 264 |
} |
| 265 |
|
| 266 |
public Iterator<Taxon> iterator() { |
| 267 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 268 |
return taxonList.iterator(); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public Object getTaxonAttribute(int taxonIndex, String name) { |
| 278 |
if (taxonList == null) throw new RuntimeException("SimpleSiteList has no taxonList"); |
| 279 |
return taxonList.getTaxonAttribute(taxonIndex, name); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
protected String id = null; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public String getId() { |
| 292 |
return id; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public void setId(String id) { |
| 299 |
this.id = id; |
| 300 |
} |
| 301 |
} |