Debian Codegraph @

src/dr/evomodel/antigenic/phyloclustering/statistics/CausalMutationsLogger.java

raw symbols SCIP
1 package dr.evomodel.antigenic.phyloclustering.statistics;
2
3 import java.util.Iterator;
4 import java.util.LinkedList;
5
6 import dr.evomodel.antigenic.phyloclustering.TreeClusteringVirusesPrior;
7 import dr.evomodel.tree.TreeModel;
8 import dr.inference.loggers.LogColumn;
9 import dr.inference.loggers.Loggable;
10 import dr.inference.model.Parameter;
11 import dr.inference.model.Variable;
12 import dr.xml.AbstractXMLObjectParser;
13 import dr.xml.ElementRule;
14 import dr.xml.XMLObject;
15 import dr.xml.XMLObjectParser;
16 import dr.xml.XMLParseException;
17 import dr.xml.XMLSyntaxRule;
18
19 public class CausalMutationsLogger implements Loggable {
20
21 /**
22 * @return the log columns.
23 */
24 public LogColumn[] getColumns() {
25
26
27 int numDimension = treeModel.getNodeCount();
28 LogColumn[] columns = new LogColumn[numDimension];
29 for (int i = 0; i < numDimension; i++) {
30 //columns[i] = new StatisticColumn(getDimensionName(i), i);
31 String traitName = "" + (i) + ":";
32 LinkedList<Integer>[] mutationList= clusterPrior.getMutationList();
33 if(mutationList[i] != null){
34 Iterator itr = mutationList[i].iterator();
35 int count = 0;
36 while(itr.hasNext()){
37 if(count > 0){
38 traitName +=",";
39 }
40 int curMutation = ((Integer) itr.next()).intValue();
41 traitName += curMutation;
42 count++;
43 }
44 }
45
46
47 final int curNode = i;
48 columns[i] = new LogColumn.Abstract(traitName){
49 @Override
50 protected String getFormattedValue(){
51 //return "AAA";
52 LinkedList<Integer>[] causalList= clusterPrior.getCausalList();
53 return parseCausalList(causalList[curNode]);
54 }
55 };
56 }
57 return columns;
58 }
59
60
61
62 public String parseCausalList(LinkedList<Integer> causalMutations){
63 String stateList = "";
64 if(causalMutations != null){
65 Iterator itr = causalMutations.iterator();
66 while(itr.hasNext()){
67 int curState = ((Integer) itr.next()).intValue();
68 stateList += curState;
69 }
70 stateList = "s" + new StringBuilder(stateList).reverse().toString(); //need to reverse printing the states to be correct.
71 }
72 else{
73 stateList = "s";
74 }
75 return(stateList);
76 }
77
78 public static final String PARSER_NAME = "causalMutationsLogger";
79 private TreeModel treeModel;
80 private TreeClusteringVirusesPrior clusterPrior;
81
82 public CausalMutationsLogger(TreeModel tree, TreeClusteringVirusesPrior clusterPrior_in) {
83 this.treeModel = tree;
84 this.clusterPrior = clusterPrior_in;
85 }
86
87 public void variableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
88 // do nothing
89 //System.out.println("hi got printed");
90 }
91
92 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
93
94
95
96 public String getParserName() {
97 return PARSER_NAME;
98 }
99
100 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
101 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
102 TreeClusteringVirusesPrior clusterPrior = (TreeClusteringVirusesPrior) xo.getChild(TreeClusteringVirusesPrior.class);
103
104 return new CausalMutationsLogger( treeModel, clusterPrior);
105
106 }
107
108 //************************************************************************
109 // AbstractXMLObjectParser implementation
110 //************************************************************************
111
112 public String getParserDescription() {
113 return ".";
114 }
115
116 public Class getReturnType() {
117 return CausalMutationsLogger.class;
118 }
119
120 public XMLSyntaxRule[] getSyntaxRules() {
121 return rules;
122 }
123
124 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
125 new ElementRule(TreeModel.class),
126 new ElementRule(TreeClusteringVirusesPrior.class),
127 };
128 };
129
130
131
132 }