| 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.evomodel.arg; |
| 27 |
|
| 28 |
import dr.evolution.colouring.TreeColouring; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evolution.tree.TreeUtils; |
| 31 |
import dr.evomodel.branchratemodel.BranchRateModel; |
| 32 |
import dr.evomodel.coalescent.structure.ColourSamplerModel; |
| 33 |
import dr.inference.loggers.LogFormatter; |
| 34 |
import dr.inference.loggers.MCLogger; |
| 35 |
import dr.inference.model.Likelihood; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class OldTreeLogger extends MCLogger { |
| 45 |
|
| 46 |
public static final String LOG_TREE = "logTree"; |
| 47 |
public static final String NEXUS_FORMAT = "nexusFormat"; |
| 48 |
public static final String USING_RATES = "usingRates"; |
| 49 |
public static final String BRANCH_LENGTHS = "branchLengths"; |
| 50 |
public static final String TIME = "time"; |
| 51 |
public static final String SUBSTITUTIONS = "substitutions"; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public static final String LOG = "log"; |
| 56 |
public static final String ECHO = "echo"; |
| 57 |
public static final String ECHO_EVERY = "echoEvery"; |
| 58 |
public static final String TITLE = "title"; |
| 59 |
public static final String FILE_NAME = "fileName"; |
| 60 |
public static final String FORMAT = "format"; |
| 61 |
public static final String TAB = "tab"; |
| 62 |
public static final String HTML = "html"; |
| 63 |
public static final String PRETTY = "pretty"; |
| 64 |
public static final String LOG_EVERY = "logEvery"; |
| 65 |
|
| 66 |
public static final String COLUMNS = "columns"; |
| 67 |
public static final String COLUMN = "column"; |
| 68 |
public static final String LABEL = "label"; |
| 69 |
public static final String SIGNIFICANT_FIGURES = "sf"; |
| 70 |
public static final String DECIMAL_PLACES = "dp"; |
| 71 |
public static final String WIDTH = "width"; |
| 72 |
|
| 73 |
|
| 74 |
private Tree tree; |
| 75 |
private BranchRateModel branchRateModel = null; |
| 76 |
private String rateLabel; |
| 77 |
|
| 78 |
private ColourSamplerModel colourSamplerModel = null; |
| 79 |
private String colouringLabel; |
| 80 |
|
| 81 |
private Likelihood likelihood = null; |
| 82 |
private String likelihoodLabel; |
| 83 |
|
| 84 |
private boolean nexusFormat = false; |
| 85 |
public boolean usingRates = false; |
| 86 |
public boolean substitutions = false; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public OldTreeLogger(Tree tree, BranchRateModel branchRateModel, String rateLabel, |
| 92 |
ColourSamplerModel colourSamplerModel, String colouringLabel, |
| 93 |
Likelihood likelihood, String likelihoodLabel, |
| 94 |
LogFormatter formatter, int logEvery, boolean nexusFormat, boolean substitutions) { |
| 95 |
|
| 96 |
super(formatter, logEvery, false); |
| 97 |
|
| 98 |
this.nexusFormat = nexusFormat; |
| 99 |
this.branchRateModel = branchRateModel; |
| 100 |
this.rateLabel = rateLabel; |
| 101 |
|
| 102 |
this.colourSamplerModel = colourSamplerModel; |
| 103 |
this.colouringLabel = colouringLabel; |
| 104 |
|
| 105 |
this.likelihood = likelihood; |
| 106 |
this.likelihoodLabel = likelihoodLabel; |
| 107 |
|
| 108 |
if (branchRateModel != null) { |
| 109 |
this.substitutions = substitutions; |
| 110 |
} |
| 111 |
this.tree = tree; |
| 112 |
} |
| 113 |
|
| 114 |
public void startLogging() { |
| 115 |
|
| 116 |
if (nexusFormat) { |
| 117 |
int taxonCount = tree.getTaxonCount(); |
| 118 |
logLine("#NEXUS"); |
| 119 |
logLine(""); |
| 120 |
logLine("Begin taxa;"); |
| 121 |
logLine("\tDimensions ntax=" + taxonCount + ";"); |
| 122 |
logLine("\tTaxlabels"); |
| 123 |
for (int i = 0; i < taxonCount; i++) { |
| 124 |
logLine("\t\t" + tree.getTaxon(i).getId()); |
| 125 |
} |
| 126 |
logLine("\t\t;"); |
| 127 |
logLine("End;"); |
| 128 |
logLine(""); |
| 129 |
logLine("Begin trees;"); |
| 130 |
|
| 131 |
if (!useTaxonLabels()) { |
| 132 |
|
| 133 |
logLine("\tTranslate"); |
| 134 |
for (int i = 0; i < taxonCount; i++) { |
| 135 |
int k = i + 1; |
| 136 |
if (k < taxonCount) { |
| 137 |
logLine("\t\t" + k + " " + tree.getTaxonId(i) + ","); |
| 138 |
} else { |
| 139 |
logLine("\t\t" + k + " " + tree.getTaxonId(i)); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
logLine("\t\t;"); |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
public void log(long state) { |
| 150 |
|
| 151 |
if (logEvery <= 0 || ((state % logEvery) == 0)) { |
| 152 |
StringBuffer buffer = new StringBuffer("tree STATE_"); |
| 153 |
buffer.append(state); |
| 154 |
if (likelihood != null) { |
| 155 |
buffer.append(" [&"); |
| 156 |
buffer.append(likelihoodLabel); |
| 157 |
buffer.append("="); |
| 158 |
buffer.append(likelihood.getLogLikelihood()); |
| 159 |
buffer.append("]"); |
| 160 |
} |
| 161 |
|
| 162 |
buffer.append(additionalInfo()); |
| 163 |
|
| 164 |
buffer.append(" = [&R] "); |
| 165 |
|
| 166 |
TreeColouring colouring = null; |
| 167 |
if (colourSamplerModel != null) { |
| 168 |
colouring = colourSamplerModel.getTreeColouring(); |
| 169 |
} |
| 170 |
|
| 171 |
Tree printTree = getPrintTree(); |
| 172 |
|
| 173 |
if (substitutions) { |
| 174 |
TreeUtils.newick(printTree, printTree.getRoot(), useTaxonLabels(), TreeUtils.BranchLengthType.LENGTHS_AS_SUBSTITUTIONS, |
| 175 |
null, branchRateModel, null, null, buffer); |
| 176 |
} else { |
| 177 |
TreeUtils.newick(printTree, printTree.getRoot(), useTaxonLabels(), TreeUtils.BranchLengthType.LENGTHS_AS_TIME, |
| 178 |
null, branchRateModel, null, null, buffer); |
| 179 |
} |
| 180 |
|
| 181 |
buffer.append(";"); |
| 182 |
logLine(buffer.toString()); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
protected String additionalInfo() { |
| 187 |
return ""; |
| 188 |
} |
| 189 |
|
| 190 |
protected Tree getPrintTree() { |
| 191 |
return tree; |
| 192 |
} |
| 193 |
|
| 194 |
protected Tree getTree() { |
| 195 |
return tree; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
protected boolean useTaxonLabels() { |
| 200 |
return false; |
| 201 |
} |
| 202 |
|
| 203 |
public void stopLogging() { |
| 204 |
|
| 205 |
logLine("End;"); |
| 206 |
super.stopLogging(); |
| 207 |
} |
| 208 |
|
| 209 |
} |