Debian Codegraph @

src/dr/evomodel/trace/CnCsToDnDsPerSiteAnalysis.java

raw symbols SCIP
1 /*
2 * CnCsToDnDsPerSiteAnalysis.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.evomodel.trace;
27
28 import dr.inference.trace.LogFileTraces;
29 import dr.inference.trace.TraceException;
30 import dr.inference.trace.TraceList;
31 import dr.math.EmpiricalBayesPoissonSmoother;
32 import dr.stats.DiscreteStatistics;
33 import dr.util.*;
34 import dr.xml.*;
35
36 import java.io.File;
37 import java.io.FileNotFoundException;
38 import java.util.*;
39
40 /**
41 * @author Philippe Lemey
42 * @author Marc A. Suchard
43 */
44 public class CnCsToDnDsPerSiteAnalysis implements Citable {
45
46 public static final String CNCS_TO_DNDS_PER_SITE_ANALYSIS = "cNcSTodNdSPerSiteAnalysis";
47 public static final String BURN_IN = "burnin";
48 public static final String CUTOFF = "cutoff";
49 public static final String PROPORTION = "proportion";
50 public static final String INCLUDE_SIGNIFICANT_SYMBOL = "includeSymbol";
51 public static final String INCLUDE_SIGNIFICANCE_LEVEL = "includeLevel";
52 public static final String INCLUDE_SITE_CLASSIFICATION = "includeClassification";
53 public static final String SIGNIFICANCE_TEST = "test";
54 public static final String SEPARATOR_STRING = "separator";
55 public static final String INCLUDE_SIMULATION_OUTCOME = "simulationOutcome";
56 public static final String INCLUDE_HPD = "includeHPD";
57 public static final String SITE_SIMULATION = "siteSimulation";
58 public static final String CN = "CN";
59 public static final String CS = "CS";
60 public static final String USE_SAMPLE = "sample";
61
62 public CnCsToDnDsPerSiteAnalysis(TraceList traceListN, TraceList traceListS) {
63 this.traceListN = traceListN;
64 this.traceListS = traceListS;
65 this.numSites = (traceListN.getTraceCount()) / 2;
66 this.format = new OutputFormat();
67
68
69 setUseSample(false);
70
71
72 double[][] allCn = new double[numSites][this.traceListN.getStateCount()];
73 double[][] allUn = new double[numSites][this.traceListN.getStateCount()];
74 double[][] allCs = new double[numSites][this.traceListS.getStateCount()];
75 double[][] allUs = new double[numSites][this.traceListS.getStateCount()];
76
77 for (int o = 0; o < numSites; o++) {
78 allCn[o] = listToDoubleArray(traceListN.getValues(o));
79 allUn[o] = listToDoubleArray(traceListN.getValues(numSites + o));
80 allCs[o] = listToDoubleArray(traceListS.getValues(o));
81 allUs[o] = listToDoubleArray(traceListS.getValues(numSites + o));
82 }
83
84 allCn = transpose(allCn);
85 allUn = transpose(allUn);
86 allCs = transpose(allCs);
87 allUs = transpose(allUs);
88
89 double[][] tempAllSmoothedCn = new double[this.traceListN.getStateCount()][numSites];
90 double[][] tempAllSmoothedUn = new double[this.traceListN.getStateCount()][numSites];
91 double[][] tempAllSmoothedCs = new double[this.traceListS.getStateCount()][numSites];
92 double[][] tempAllSmoothedUs = new double[this.traceListS.getStateCount()][numSites];
93
94 boolean first = true;
95
96 for (int p = 0; p < this.traceListN.getStateCount(); p++) {
97
98 // Testing code:
99
100 // if (first) {
101 // tempAllSmoothedCn[p] = EmpiricalBayesPoissonSmoother.smooth(allCn[p]);
102 // System.err.println("Smooth values: " + new Vector(tempAllSmoothedCn[p]));
103 //
104 // tempAllSmoothedCn[p] = EmpiricalBayesPoissonSmoother.smoothWithSample(allCn[p]);
105 // System.err.println("Sample values: " + new Vector(tempAllSmoothedCn[p]));
106 // first = false;
107 // }
108
109 // System.exit(-1);
110
111
112 if (format.useSample) {
113 tempAllSmoothedCn[p] = EmpiricalBayesPoissonSmoother.smoothWithSample(allCn[p]);
114 tempAllSmoothedUn[p] = EmpiricalBayesPoissonSmoother.smoothWithSample(allUn[p]);
115 tempAllSmoothedCs[p] = EmpiricalBayesPoissonSmoother.smoothWithSample(allCs[p]);
116 tempAllSmoothedUs[p] = EmpiricalBayesPoissonSmoother.smoothWithSample(allUs[p]);
117 } else {
118 tempAllSmoothedCn[p] = EmpiricalBayesPoissonSmoother.smooth(allCn[p]);
119 tempAllSmoothedUn[p] = EmpiricalBayesPoissonSmoother.smooth(allUn[p]);
120 tempAllSmoothedCs[p] = EmpiricalBayesPoissonSmoother.smooth(allCs[p]);
121 tempAllSmoothedUs[p] = EmpiricalBayesPoissonSmoother.smooth(allUs[p]);
122 }
123
124 }
125
126 allSmoothedCn = transpose(tempAllSmoothedCn);
127 allSmoothedUn = transpose(tempAllSmoothedUn);
128 allSmoothedCs = transpose(tempAllSmoothedCs);
129 allSmoothedUs = transpose(tempAllSmoothedUs);
130
131 fieldWidth = 14;
132 firstField = 10;
133 numberFormatter = new NumberFormatter(6);
134 numberFormatter.setPadding(true);
135 numberFormatter.setFieldWidth(fieldWidth);
136 }
137
138 public void setIncludeMean(boolean b) {
139 format.includeMean = b;
140 }
141
142 public void setIncludeHPD(boolean b) {
143 format.includeHPD = b;
144 }
145
146 public void setIncludeSignificanceLevel(boolean b) {
147 format.includeSignificanceLevel = b;
148 }
149
150 public void setIncludeSignificantSymbol(boolean b) {
151 format.includeSignificantSymbol = b;
152 }
153
154 public void setIncludeSimulationOutcome(boolean b) {
155 format.includeSimulationOutcome = b;
156 }
157
158 public boolean getIncludeSimulationOutcome() {
159 return (format.includeSimulationOutcome);
160 }
161
162 public void setProportion(double d) {
163 format.proportion = d;
164 }
165
166 public void setSiteSimulation(String[] d) {
167 format.siteSimulation = d;
168 }
169
170 public void setIncludeSiteClassification(boolean b) {
171 format.includeSiteClassification = b;
172 }
173
174 public void setCutoff(double d) {
175 format.cutoff = d;
176 }
177
178 public void setSeparator(String s) {
179 format.separator = s;
180 }
181
182 public void setSignificanceTest(SignificanceTest t) {
183 format.test = t;
184 }
185
186 public void setUseSample(boolean u) {
187 format.useSample = u;
188 }
189
190 private String toStringSite(int index, OutputFormat format) {
191
192 double[] dN = getRatioArray(allSmoothedCn[index], allSmoothedUn[index]);
193 double[] dS = getRatioArray(allSmoothedCs[index], allSmoothedUs[index]);
194
195 double[] omegas = getRatioArray(dN, dS);
196 // for (int x = 0; x < dN.length; x ++){
197 // System.out.println(index+"\t"+allSmoothedCn[index][x]+"\t"+allSmoothedUn[index][x]+"\t"+dN[x]+"\t"+allSmoothedCs[index][x]+"\t"+allSmoothedUs[index][x]+"\t"+dS[x]+"\t"+omegas[x]);
198 // }
199
200 StringBuilder sb = new StringBuilder();
201 sb.append(numberFormatter.formatToFieldWidth(Integer.toString(index + 1), firstField));
202
203 double[] hpd = new double[2];
204 double[] minMax = getMinMax(omegas);
205 // this is weird, yes. But we used these 'HPD's to obtain the ROC curves for different cut-offs
206 if (format.proportion >= 1.0) {
207 hpd[0] = minMax[0] - (minMax[0] * (format.proportion - 1.0));
208 hpd[1] = minMax[1] + (minMax[1] * (format.proportion - 1.0));
209 System.out.println("hpd = " + hpd[0] + " - " + hpd[1]);
210 } else {
211 hpd = getHPDInterval(format.proportion, omegas);
212 }
213
214 if (format.includeMean) {
215 sb.append(format.separator);
216 // sb.append(numberFormatter.format(DiscreteStatistics.mean(omegas)));
217 sb.append(numberFormatter.format(DiscreteStatistics.median(omegas)));
218 }
219 if (format.includeHPD) {
220 sb.append(format.separator);
221 sb.append(numberFormatter.format(hpd[0]));
222 sb.append(format.separator);
223 sb.append(numberFormatter.format(hpd[1]));
224 }
225 if (format.includeSignificanceLevel || format.includeSignificantSymbol || format.includeSiteClassification || format.includeSimulationOutcome) {
226 boolean isSignificant = false;
227 String classification = "0";
228 String level;
229 if (format.test == SignificanceTest.NOT_EQUAL) {
230 if (hpd[0] < format.cutoff && hpd[1] < format.cutoff) {
231 level = numberFormatter.formatToFieldWidth(">" + format.proportion, fieldWidth);
232 isSignificant = true;
233 classification = "-";
234 } else if (hpd[0] > format.cutoff && hpd[1] > format.cutoff) {
235 level = numberFormatter.formatToFieldWidth(">" + format.proportion, fieldWidth);
236 isSignificant = true;
237 classification = "+";
238 } else {
239 level = numberFormatter.formatToFieldWidth("<=" + format.proportion, fieldWidth);
240 }
241 } else {
242 double levelPosValue = 0.0;
243 double levelNegValue = 0.0;
244 int total = 0;
245 for (double w : omegas) {
246 // if ((format.test == SignificanceTest.LESS_THAN && d < format.cutoff) ||
247 // (format.test == SignificanceTest.GREATER_THAN && d > format.cutoff)) {
248 if (w < format.cutoff) {
249 if (format.test == SignificanceTest.LESS_THAN || format.test == SignificanceTest.LESS_OR_GREATER_THAN) {
250 levelNegValue++;
251 }
252 } else if (w > format.cutoff) {
253 if (format.test == SignificanceTest.GREATER_THAN || format.test == SignificanceTest.LESS_OR_GREATER_THAN) {
254 levelPosValue++;
255 }
256 }
257 total++;
258 }
259 levelPosValue /= total;
260 levelNegValue /= total;
261 if (levelPosValue > format.proportion) {
262 isSignificant = true;
263 classification = "+";
264 } else if (levelNegValue > format.proportion) {
265 isSignificant = true;
266 classification = "-";
267 }
268 if (levelPosValue > levelNegValue) {
269 level = numberFormatter.format(levelPosValue);
270 } else {
271 level = numberFormatter.format(levelNegValue);
272 }
273 }
274
275 if (format.includeSignificanceLevel) {
276 sb.append(format.separator);
277 sb.append(level);
278 }
279
280 if (format.includeSiteClassification) {
281 sb.append(format.separator);
282 sb.append(classification);
283 }
284
285
286 if (format.includeSignificantSymbol) {
287 sb.append(format.separator);
288 if (isSignificant) {
289 sb.append("*");
290 } else {
291 // Do nothing?
292 }
293 }
294
295 if (format.includeSimulationOutcome) {
296 sb.append(format.separator);
297 sb.append(format.siteSimulation[index]);
298 sb.append(format.separator);
299 if (format.siteSimulation[index].equals("+") || format.siteSimulation[index].equals("-")) {
300 if (classification.equals(format.siteSimulation[index])) {
301 sb.append("TP"); // True Positive
302 } else {
303 sb.append("FN"); // True Negative
304 }
305 } else {
306 if (classification.equals(format.siteSimulation[index])) {
307 sb.append("TN"); // True Negative
308 } else {
309 sb.append("FP"); // False Positive
310 }
311 }
312 }
313 }
314 sb.append("\n");
315 return sb.toString();
316 }
317
318 public String header(OutputFormat format) {
319 StringBuilder sb = new StringBuilder();
320 sb.append("# Some information here\n");
321 sb.append("# Please cite: " + Utils.getCitationString(this));
322
323
324 sb.append(numberFormatter.formatToFieldWidth("Site", firstField));
325
326 if (format.includeMean) {
327 sb.append(format.separator);
328 sb.append(numberFormatter.formatToFieldWidth("Mean", fieldWidth));
329 }
330
331 if (format.includeHPD) {
332 sb.append(format.separator);
333 sb.append(numberFormatter.formatToFieldWidth("Lower", fieldWidth));
334 sb.append(format.separator);
335 sb.append(numberFormatter.formatToFieldWidth("Upper", fieldWidth));
336 }
337
338 if (format.includeSignificanceLevel) {
339 sb.append(format.separator);
340 sb.append(numberFormatter.formatToFieldWidth("Level", fieldWidth));
341 }
342
343 if (format.includeSiteClassification) {
344 sb.append(format.separator);
345 sb.append(numberFormatter.formatToFieldWidth("Classification", fieldWidth));
346 }
347
348 if (format.includeSignificantSymbol) {
349 sb.append(format.separator);
350 sb.append(numberFormatter.formatToFieldWidth("Significant", fieldWidth));
351 }
352 if (format.includeSimulationOutcome) {
353 sb.append(format.separator);
354 sb.append(numberFormatter.formatToFieldWidth("Simulated", fieldWidth));
355 sb.append(format.separator);
356 sb.append(numberFormatter.formatToFieldWidth("Evaluation", fieldWidth));
357 }
358 sb.append("\n");
359 return sb.toString();
360 }
361
362 public String toString() {
363
364 StringBuilder sb = new StringBuilder();
365 sb.append(header(format));
366 for (int i = 0; i < numSites; ++i) {
367 sb.append(toStringSite(i, format));
368 }
369
370 sb.append(toStringSite(0, format));
371
372 return sb.toString();
373 }
374
375 @Override
376 public Citation.Category getCategory() {
377 return Citation.Category.COUNTING_PROCESSES;
378 }
379
380 @Override
381 public String getDescription() {
382 return "Renaissance counting";
383 }
384
385 @Override
386 public List<Citation> getCitations() {
387 return Collections.singletonList(CommonCitations.LEMEY_2012_RENAISSANCE);
388 }
389
390 private class OutputFormat {
391 boolean useSample;
392 boolean includeMean;
393 boolean includeHPD;
394 boolean includeSignificanceLevel;
395 boolean includeSignificantSymbol;
396 boolean includeSiteClassification;
397 boolean includeSimulationOutcome;
398 String[] siteSimulation;
399 double cutoff;
400 double proportion;
401 SignificanceTest test;
402 String separator;
403
404 OutputFormat() {
405 this(false, true, true, true, true, true, false, null, 1.0, 0.95, SignificanceTest.NOT_EQUAL, "\t");
406 }
407
408 OutputFormat(boolean useSample,
409 boolean includeMean,
410 boolean includeHPD,
411 boolean includeSignificanceLevel,
412 boolean includeSignificantSymbol,
413 boolean includeSiteClassification,
414 boolean includeSimulationOutcome,
415 String[] siteSimulation,
416 double cutoff,
417 double proportion,
418 SignificanceTest test,
419 String separator) {
420 this.useSample = useSample;
421 this.includeMean = includeMean;
422 this.includeHPD = includeHPD;
423 this.includeSignificanceLevel = includeSignificanceLevel;
424 this.includeSignificantSymbol = includeSignificantSymbol;
425 this.includeSiteClassification = includeSiteClassification;
426 this.includeSimulationOutcome = includeSimulationOutcome;
427 this.siteSimulation = siteSimulation;
428 this.cutoff = cutoff;
429 this.proportion = proportion;
430 this.test = test;
431 this.separator = separator;
432 }
433 }
434
435 public enum SignificanceTest {
436 GREATER_THAN("gt"), //>
437 LESS_THAN("lt"), //<
438 NOT_EQUAL("ne"), //!=
439 LESS_OR_GREATER_THAN("logt"); //<>
440
441 private SignificanceTest(String text) {
442 this.text = text;
443 }
444
445 public String getText() {
446 return text;
447 }
448
449 public static SignificanceTest parseFromString(String text) {
450 for (SignificanceTest test : SignificanceTest.values()) {
451 if (test.getText().compareToIgnoreCase(text) == 0)
452 return test;
453 }
454 return null;
455 }
456
457 private final String text;
458 }
459
460 private static double[] listToDoubleArray(List list) {
461 Double[] resultObjArray = (Double[]) list.toArray(new Double[0]);
462 double[] result = toPrimitiveDoubleArray(resultObjArray);
463 return result;
464 }
465
466 private double[][] transpose(double[][] in) {
467 double[][] out = new double[in[0].length][in.length];
468 for (int r = 0; r < in.length; r++) {
469 for (int c = 0; c < in[0].length; c++) {
470 out[c][r] = in[r][c];
471 }
472 }
473 return out;
474 }
475
476 private static double[] getFirstHalfArray(double[] condAndUncond) {
477 int count = (condAndUncond.length) / 2;
478 double[] returnArray = new double[count];
479 for (int a = 0; a < count; a++) {
480 returnArray[a] = condAndUncond[a];
481 }
482 return returnArray;
483 }
484
485 private static double[] getSecondHalfArray(double[] condAndUncond) {
486 int count = (condAndUncond.length) / 2;
487 double[] returnArray = new double[count];
488 for (int a = 0; a < count; a++) {
489 returnArray[a] = condAndUncond[count + a];
490 }
491 return returnArray;
492 }
493
494 private static double[] getRatioArray(double[] enumArray, double[] denomArray) {
495 double[] returnArray = new double[enumArray.length];
496 for (int x = 0; x < enumArray.length; x++) {
497 returnArray[x] = enumArray[x] / denomArray[x];
498 }
499 return returnArray;
500 }
501
502 private static double[] getMinMax(double[] values) {
503 double[] returnArray = new double[2];
504
505 double min = Double.MAX_VALUE;
506 double max = 0;
507
508 for (int x = 0; x < values.length; x++) {
509 if (values[x] > max) {
510 max = values[x];
511 }
512 if (values[x] < min) {
513 min = values[x];
514 }
515 }
516
517 returnArray[0] = min;
518 returnArray[1] = max;
519
520 return returnArray;
521
522 }
523
524 private static double[] getHPDInterval(double proportion, double[] values) {
525
526 double[] returnArray = new double[2];
527
528 int length = values.length;
529 int[] indices = new int[length];
530 HeapSort.sort(values, indices);
531 double minRange = Double.MAX_VALUE;
532 int hpdIndex = 0;
533
534 int diff = (int) Math.round(proportion * (double) length);
535
536 for (int i = 0; i <= (length - diff); i++) {
537 double minValue = values[indices[i]];
538 double maxValue = values[indices[i + diff - 1]];
539 double range = Math.abs(maxValue - minValue);
540 if (range < minRange) {
541 minRange = range;
542 hpdIndex = i;
543 }
544 }
545 returnArray[0] = values[indices[hpdIndex]];
546 returnArray[1] = values[indices[hpdIndex + diff - 1]];
547 return returnArray;
548 }
549
550 private static double[] toPrimitiveDoubleArray(Double[] array) {
551 double[] returnArray = new double[array.length];
552 for (int i = 0; i < array.length; i++) {
553 returnArray[i] = array[i].doubleValue();
554 }
555 return returnArray;
556 }
557
558 private static String[] parseVariableLengthStringArray(String inString) {
559
560 List<String> returnList = new ArrayList<String>();
561 StringTokenizer st = new StringTokenizer(inString, ",");
562 while (st.hasMoreTokens()) {
563 returnList.add(st.nextToken());
564 }
565
566 if (returnList.size() > 0) {
567 String[] stringArray = new String[returnList.size()];
568 stringArray = returnList.toArray(stringArray);
569 return stringArray;
570 }
571 return null;
572 }
573
574 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
575
576 public String getParserName() {
577 return CNCS_TO_DNDS_PER_SITE_ANALYSIS;
578 }
579
580 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
581
582 String fileNameCN = xo.getStringAttribute(FileHelpers.FILE_NAME + CN);
583 String fileNameCS = xo.getStringAttribute(FileHelpers.FILE_NAME + CS);
584 try {
585
586 File fileCN = new File(fileNameCN);
587 File fileCS = new File(fileNameCS);
588 String nameCN = fileCN.getName();
589 String nameCS = fileCS.getName();
590 String parentCN = fileCN.getParent();
591 String parentCS = fileCS.getParent();
592
593 if (!fileCN.isAbsolute()) {
594 parentCN = System.getProperty("user.dir");
595 }
596 if (!fileCS.isAbsolute()) {
597 parentCS = System.getProperty("user.dir");
598 }
599
600 fileCN = new File(parentCN, nameCN);
601 fileCS = new File(parentCS, nameCS);
602
603 fileNameCN = fileCN.getAbsolutePath();
604 fileNameCS = fileCS.getAbsolutePath();
605
606 LogFileTraces tracesCN = new LogFileTraces(fileNameCN, fileCN);
607 LogFileTraces tracesCS = new LogFileTraces(fileNameCS, fileCS);
608 tracesCN.loadTraces();
609 tracesCS.loadTraces();
610
611 long maxStateCN = tracesCN.getMaxState();
612 long maxStateCS = tracesCS.getMaxState();
613
614 if (maxStateCN != maxStateCS) {
615 System.err.println("max states in" + fileNameCN + " and " + fileNameCS + " are not equal");
616 }
617
618 // leaving the burnin attribute off will result in 10% being used
619 long burnin = xo.getAttribute(BURN_IN, maxStateCN / 10);
620 //TODO: implement custom burn-in
621
622 if (burnin < 0 || burnin >= maxStateCN) {
623 burnin = maxStateCN / 5;
624 System.out.println("WARNING: Burn-in larger than total number of states - using 20%");
625 }
626
627 tracesCN.setBurnIn(burnin);
628 tracesCS.setBurnIn(burnin);
629
630 // TODO: Filter traces to include only dNdS columns
631
632 CnCsToDnDsPerSiteAnalysis analysis = new CnCsToDnDsPerSiteAnalysis(tracesCN, tracesCS);
633
634 analysis.setCutoff(xo.getAttribute(CUTOFF, 1.0));
635 analysis.setProportion(xo.getAttribute(PROPORTION, 0.95));
636 analysis.setSeparator(xo.getAttribute(SEPARATOR_STRING, "\t"));
637 analysis.setUseSample(xo.getAttribute(USE_SAMPLE, false));
638 analysis.setIncludeHPD(xo.getAttribute(INCLUDE_HPD, true));
639 analysis.setIncludeSignificanceLevel(xo.getAttribute(INCLUDE_SIGNIFICANCE_LEVEL, false));
640 analysis.setIncludeSignificantSymbol(xo.getAttribute(INCLUDE_SIGNIFICANT_SYMBOL, true));
641 analysis.setIncludeSiteClassification(xo.getAttribute(INCLUDE_SITE_CLASSIFICATION, true));
642 analysis.setIncludeSimulationOutcome(xo.getAttribute(INCLUDE_SIMULATION_OUTCOME, false));
643 if (analysis.getIncludeSimulationOutcome()) {
644 String sites = (String) xo.getAttribute(SITE_SIMULATION, "empty");
645 if (sites.equals("empty")) {
646 System.err.println("you want simulation evaluation but do not provide a site simulation string??");
647 } else {
648 String[] siteSimulation = parseVariableLengthStringArray(sites);
649 analysis.setSiteSimulation(siteSimulation);
650 }
651 }
652
653 return analysis;
654
655 } catch (FileNotFoundException fnfe) {
656 throw new XMLParseException("File '" + fileNameCN + " and " + fileNameCS + "' can not be opened for " + getParserName() + " element.");
657 } catch (java.io.IOException ioe) {
658 throw new XMLParseException(ioe.getMessage());
659 } catch (TraceException e) {
660 throw new XMLParseException(e.getMessage());
661 }
662 }
663
664 //************************************************************************
665 // AbstractXMLObjectParser implementation
666 //************************************************************************
667
668 public String getParserDescription() {
669 return "Performs a trace analysis of N and S counts.";
670 }
671
672 public Class getReturnType() {
673 return CnCsPerSiteAnalysis.class;
674 }
675
676 public XMLSyntaxRule[] getSyntaxRules() {
677 return rules;
678 }
679
680 private final XMLSyntaxRule[] rules = {
681 AttributeRule.newStringRule(FileHelpers.FILE_NAME + CN, true),
682 AttributeRule.newStringRule(FileHelpers.FILE_NAME + CS, true),
683 AttributeRule.newDoubleRule(CUTOFF, true),
684 AttributeRule.newDoubleRule(PROPORTION, true),
685 AttributeRule.newIntegerRule(BURN_IN, true),
686 AttributeRule.newBooleanRule(USE_SAMPLE, true),
687 AttributeRule.newBooleanRule(INCLUDE_HPD, true),
688 AttributeRule.newBooleanRule(INCLUDE_SIGNIFICANT_SYMBOL, true),
689 AttributeRule.newBooleanRule(INCLUDE_SIGNIFICANCE_LEVEL, true),
690 AttributeRule.newBooleanRule(INCLUDE_SITE_CLASSIFICATION, true),
691 AttributeRule.newBooleanRule(INCLUDE_SIMULATION_OUTCOME, true),
692 AttributeRule.newStringRule(SITE_SIMULATION, true),
693 AttributeRule.newStringRule(SIGNIFICANCE_TEST, true),
694 AttributeRule.newStringRule(SEPARATOR_STRING, true),
695 // new StringAttributeRule(FileHelpers.FILE_NAME,
696 // "The traceName of a BEAST log file (can not include trees, which should be logged separately"),
697 // new ElementRule(UNCONDITIONAL_S_COLUMN, new XMLSyntaxRule[]{
698 // new StringAttributeRule(Attribute.NAME, "The column name")}),
699 // new ElementRule(UNCONDITIONAL_N_COLUMN, new XMLSyntaxRule[]{
700 // new StringAttributeRule(Attribute.NAME, "The column name")}),
701 };
702 };
703
704 final private TraceList traceListN;
705 final private TraceList traceListS;
706 final private int numSites;
707 final private double[][] allSmoothedCn;
708 final private double[][] allSmoothedUn;
709 final private double[][] allSmoothedCs;
710 final private double[][] allSmoothedUs;
711 private OutputFormat format;
712
713
714 private int fieldWidth;
715 private int firstField;
716 private NumberFormatter numberFormatter;
717
718
719 }