Debian Codegraph @

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

raw symbols SCIP
1 package dr.evomodel.antigenic.phyloclustering.statistics;
2
3
4 import dr.evolution.tree.NodeRef;
5 import dr.evolution.tree.Tree;
6 import dr.evolution.tree.TreeTrait;
7 import dr.evolution.tree.TreeTraitProvider;
8 import dr.evomodel.tree.TreeModel;
9 import dr.inference.model.Parameter;
10 import dr.xml.AbstractXMLObjectParser;
11 import dr.xml.ElementRule;
12 import dr.xml.XMLObject;
13 import dr.xml.XMLObjectParser;
14 import dr.xml.XMLParseException;
15 import dr.xml.XMLSyntaxRule;
16
17 public class ClusterLabelsVirusesTreeTrait implements TreeTraitProvider {
18
19 protected Helper treeTraits = new Helper();
20 private TreeModel treeModel;
21 public static final String CLUSTERLABELSTREETRAIT = "clusterLabelsVirusesTreeTrait";
22 public final static String CLUSTERLABELSTREENODE = "clusterLabelsTreeNodes";
23
24 private Parameter clusterLabelsTreeNode;
25
26
27 public ClusterLabelsVirusesTreeTrait(TreeModel treeModel_in, Parameter clusterLabelsTreeNode_in){
28
29 this.treeModel = treeModel_in;
30 this.clusterLabelsTreeNode = clusterLabelsTreeNode_in;
31
32 treeTraits.addTrait(new TreeTrait.IA() {
33
34 public String getTraitName() {
35 //System.out.println("print label");
36 // return tag;
37 return "cluster";
38 }
39
40 public String getTraitString(Tree tree, NodeRef node) {
41
42 if(tree != treeModel){
43 System.out.println("Something is wrong. Why is tree not equal to treeModel?");
44 System.exit(0);
45 }
46
47 //the problem is, I don't know how to only do the processing to get the clusterLabels
48 //right before this routine is run...
49 //so I have to keep a parameter or variable somewhere to store the clusterLabels information of the tree nodes
50 //whenever the cluster assignment is changed..
51 //the states have to be precomputed so this only prints..
52
53 //System.out.println("node=" + node.getNumber());
54
55 String clusterLabelString = ((int) clusterLabelsTreeNode.getParameterValue(node.getNumber()) ) + "";
56 //String clusterLabelString = node.getNumber() + ""; //to get the node numbering of the tree.
57
58 //if(node.getNumber() ==0){
59 // //System.out.println("print ");
60 // for(int i=0; i < treeModel.getNodeCount(); i++){
61 // System.out.print( clusterLabelsTreeNode.getParameterValue(i) + "\t");
62 // }
63 // System.out.println("");
64 //}
65 //return formattedState(getStatesForNode(tree, node), dataType);
66 return clusterLabelString;
67 }
68
69
70 public Intent getIntent() {
71 //System.out.println("getIntent");
72 return Intent.NODE;
73 }
74
75 public Class getTraitClass() {
76 System.out.println("getTraitClass ran. Not expected. Quit now");
77 System.exit(0);
78 return int[].class;
79 }
80
81
82 public int[] getTrait(Tree tree, NodeRef node) {
83 // return getStatesForNode(tree, node);
84 System.out.println("getTrait ran. Not expected. Quit now");
85 System.exit(0);
86 //int x[] = new int[10];
87 return null;
88 }
89
90
91 });
92
93
94 }
95
96
97
98 public TreeTrait[] getTreeTraits() {
99 //System.out.println("hihi");
100 return treeTraits.getTreeTraits();
101 }
102
103
104 public TreeTrait getTreeTrait(String key) {
105 System.out.println("not expected to run getTreeTrait. Quit now");
106 System.exit(0);
107 return treeTraits.getTreeTrait(key);
108 }
109
110
111
112
113 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
114
115
116 public String getParserName() {
117 return CLUSTERLABELSTREETRAIT;
118 }
119
120 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
121 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
122
123 XMLObject cxo = xo.getChild(CLUSTERLABELSTREENODE);
124 Parameter clusterLabelsTreeNode = (Parameter) cxo.getChild(Parameter.class);
125
126 return new ClusterLabelsVirusesTreeTrait( treeModel, clusterLabelsTreeNode);
127
128 }
129
130 //************************************************************************
131 // AbstractXMLObjectParser implementation
132 //************************************************************************
133
134 public String getParserDescription() {
135 return "Integrate ClusterLabels of viruses into the tree.";
136 }
137
138 public Class getReturnType() {
139 return ClusterLabelsVirusesTreeTrait.class;
140 }
141
142 public XMLSyntaxRule[] getSyntaxRules() {
143 return rules;
144 }
145
146 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
147 new ElementRule(TreeModel.class),
148 new ElementRule(CLUSTERLABELSTREENODE, Parameter.class),
149
150 };
151 };
152
153
154 }