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