| 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.app.treespace; |
| 27 |
|
| 28 |
import dr.util.NumberFormatter; |
| 29 |
import dr.app.gui.table.MultiLineTableCellContent; |
| 30 |
|
| 31 |
import javax.swing.*; |
| 32 |
import java.io.File; |
| 33 |
|
| 34 |
import jam.util.IconUtils; |
| 35 |
import jebl.evolution.trees.RootedTree; |
| 36 |
|
| 37 |
public class InputFile implements MultiLineTableCellContent { |
| 38 |
private final Icon treeIcon = IconUtils.getIcon(this.getClass(), "images/tree.png"); |
| 39 |
private final Icon treesIcon = IconUtils.getIcon(this.getClass(), "images/small_trees.png"); |
| 40 |
|
| 41 |
public enum Type { |
| 42 |
POSTERIOR_TREES("Posterior distribution of trees"), |
| 43 |
MODAL_TREE("Single tree"), |
| 44 |
LOG_FILE("Posterior distribution of parameters"); |
| 45 |
|
| 46 |
Type(final String name) { |
| 47 |
this.name = name; |
| 48 |
} |
| 49 |
|
| 50 |
@Override |
| 51 |
public String toString() { |
| 52 |
return name; |
| 53 |
} |
| 54 |
|
| 55 |
private final String name; |
| 56 |
} |
| 57 |
|
| 58 |
InputFile(File file) { |
| 59 |
if (file == null) { |
| 60 |
throw new IllegalArgumentException("File argument to InputFile cannot be null"); |
| 61 |
} |
| 62 |
this.file = file; |
| 63 |
this.tree = null; |
| 64 |
this.treeCount = 0; |
| 65 |
this.type = Type.LOG_FILE; |
| 66 |
} |
| 67 |
|
| 68 |
InputFile(File file, RootedTree tree) { |
| 69 |
if (file == null) { |
| 70 |
throw new IllegalArgumentException("File argument to InputFile cannot be null"); |
| 71 |
} |
| 72 |
this.file = file; |
| 73 |
this.tree = tree; |
| 74 |
this.treeCount = 0; |
| 75 |
this.type = Type.MODAL_TREE; |
| 76 |
} |
| 77 |
|
| 78 |
InputFile(File file, RootedTree tree, int treeCount) { |
| 79 |
if (file == null) { |
| 80 |
throw new IllegalArgumentException("File argument to InputFile cannot be null"); |
| 81 |
} |
| 82 |
this.file = file; |
| 83 |
this.tree = tree; |
| 84 |
this.treeCount = treeCount; |
| 85 |
this.type = Type.POSTERIOR_TREES; |
| 86 |
} |
| 87 |
|
| 88 |
public File getFile() { |
| 89 |
return file; |
| 90 |
} |
| 91 |
|
| 92 |
public Type getType() { |
| 93 |
return type; |
| 94 |
} |
| 95 |
|
| 96 |
public RootedTree getTree() { |
| 97 |
return tree; |
| 98 |
} |
| 99 |
|
| 100 |
public int getTreeCount() { |
| 101 |
return treeCount; |
| 102 |
} |
| 103 |
|
| 104 |
public void setTreeCount(final int treeCount) { |
| 105 |
this.treeCount = treeCount; |
| 106 |
} |
| 107 |
|
| 108 |
public int getBurnin() { |
| 109 |
return burnin; |
| 110 |
} |
| 111 |
|
| 112 |
public void setBurnin(final int burnin) { |
| 113 |
this.burnin = burnin; |
| 114 |
} |
| 115 |
|
| 116 |
public double getMostRecentSampleDate() { |
| 117 |
return mostRecentSampleDate; |
| 118 |
} |
| 119 |
|
| 120 |
public void setMostRecentSampleDate(double mostRecentSampleDate) { |
| 121 |
this.mostRecentSampleDate = mostRecentSampleDate; |
| 122 |
} |
| 123 |
|
| 124 |
public Icon getTableCellIcon() { |
| 125 |
switch (type) { |
| 126 |
case LOG_FILE: |
| 127 |
return null; |
| 128 |
case MODAL_TREE: |
| 129 |
return treeIcon; |
| 130 |
case POSTERIOR_TREES: |
| 131 |
return treesIcon; |
| 132 |
} |
| 133 |
return null; |
| 134 |
} |
| 135 |
|
| 136 |
private static final NumberFormatter nf = new NumberFormatter(6); |
| 137 |
|
| 138 |
public String getTableCellContent() { |
| 139 |
StringBuilder sb = new StringBuilder(); |
| 140 |
sb.append("<html>"); |
| 141 |
sb.append("<b>").append(file.getName()).append(": </b>").append(type.toString()).append("<br>"); |
| 142 |
if (type != Type.LOG_FILE) { |
| 143 |
sb.append("<small>Tip count: ").append(tree.getExternalNodes().size()); |
| 144 |
if (mostRecentSampleDate != 0.0) { |
| 145 |
if (type == Type.POSTERIOR_TREES) { |
| 146 |
sb.append(" | Tree count: ").append(treeCount < 0 ? " counting..." : treeCount); |
| 147 |
} else { |
| 148 |
sb.append(" | Root TMRCA: ").append(nf.format(mostRecentSampleDate - tree.getHeight(tree.getRootNode()))); |
| 149 |
} |
| 150 |
sb.append(" | Most recent tip: ").append(mostRecentSampleDate); |
| 151 |
} else { |
| 152 |
if (type == Type.POSTERIOR_TREES) { |
| 153 |
sb.append(" | Tree count: ").append(treeCount < 0 ? " counting..." : treeCount); |
| 154 |
} else { |
| 155 |
sb.append(" | Root height: ").append(nf.format(tree.getHeight(tree.getRootNode()))); |
| 156 |
} |
| 157 |
} |
| 158 |
if (type == Type.POSTERIOR_TREES) { |
| 159 |
sb.append(" | Burn-in: ").append(burnin); |
| 160 |
} |
| 161 |
sb.append("</small><br>"); |
| 162 |
} |
| 163 |
sb.append("</html>"); |
| 164 |
return sb.toString(); |
| 165 |
} |
| 166 |
|
| 167 |
public String getToolTipContent() { |
| 168 |
return getTableCellContent(); |
| 169 |
} |
| 170 |
|
| 171 |
@Override |
| 172 |
public String toString() { |
| 173 |
|
| 174 |
return file.getName(); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
private final Type type; |
| 179 |
private final File file; |
| 180 |
private int treeCount; |
| 181 |
private int burnin = 0; |
| 182 |
|
| 183 |
private RootedTree tree = null; |
| 184 |
private double mostRecentSampleDate = 0.0; |
| 185 |
} |