Debian Codegraph @

src/dr/evomodel/antigenic/phyloclustering/statistics/AnnotateLocationParameterTreeTrait.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.MatrixParameter;
10 import dr.inference.model.Parameter;
11 import dr.xml.AbstractXMLObjectParser;
12 import dr.xml.AttributeRule;
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
20 public class AnnotateLocationParameterTreeTrait implements TreeTraitProvider {
21
22 protected Helper treeTraits = new Helper();
23 private TreeModel treeModel;
24 public static final String ANNOTATELOCATIONPARAMETERTREETRAIT = "annotateLocationParameterTreeTrait";
25 public final static String locationParameterStr = "virusLocationsTreeNodes";
26 //public final static String serumDriftStr = "serumDrift"; //but maybe serum drift is off
27 public final static String indicatorsStr = "indicators";
28 public final static String hasDriftStr = "hasDrift";
29
30 public final static String MU1_SCALE_PARAMETER = "mu1Scale";
31 public final static String MU2_SCALE_PARAMETER = "mu2Scale";
32 public final static String MUMEAN_PARAMETER = "muMean";
33
34
35 private MatrixParameter locationParameter;
36 private Parameter indicators;
37 // private Parameter serumDrift;
38 private Parameter mu1ScaleParameter;
39 private Parameter mu2ScaleParameter;
40 private Parameter muMeanParameter;
41 private boolean hasDrift;
42
43
44
45
46 // public AnnotateMuTreeTrait(TreeModel treeModel_in, MatrixParameter muTreeNode_in, Parameter indicators_in, Parameter serumDrift_in, boolean driftTreeClusterMu){
47 public AnnotateLocationParameterTreeTrait(TreeModel treeModel_in, MatrixParameter locationTreeNode_in, Parameter indicators_in, boolean driftTreeClusterMu, Parameter mu1Scale, Parameter mu2Scale, Parameter muMean) {
48
49 this.treeModel = treeModel_in;
50 this.locationParameter = locationTreeNode_in;
51 this.indicators = indicators_in;
52 //this.serumDrift = serumDrift_in;
53 this.mu1ScaleParameter = mu1Scale;
54 this.mu2ScaleParameter = mu2Scale;
55 this.muMeanParameter = muMean;
56 this.hasDrift = driftTreeClusterMu;
57
58 treeTraits.addTrait(new TreeTrait.IA() {
59
60 public String getTraitName() {
61 //System.out.println("print label");
62 // return tag;
63 return "antigenic";
64 }
65
66
67
68 public String getTraitString(Tree tree, NodeRef node) {
69
70 if(tree != treeModel){
71 System.out.println("Something is wrong. Why is tree not equal to treeModel?");
72 System.exit(0);
73 }
74
75 double firstCoord = locationParameter.getParameter(node.getNumber()).getParameterValue(0);
76 double secondCoord = locationParameter.getParameter(node.getNumber()).getParameterValue(1);
77
78 //if(hasDrift && serumDrift != null ){
79 // //multiply the first coordinate by the drift term
80 // firstCoord = firstCoord * serumDrift.getParameterValue(0);
81 //}
82 if(hasDrift && mu1ScaleParameter != null && muMeanParameter != null ){
83 //multiply the first coordinate by the drift term
84 firstCoord = firstCoord * mu1ScaleParameter.getParameterValue(0);
85 }
86 if(hasDrift && mu2ScaleParameter != null ){
87 //multiply the first coordinate by the drift term
88 secondCoord = secondCoord * mu2ScaleParameter.getParameterValue(0);
89 }
90
91 String outputStr = "{"+ firstCoord + "," + secondCoord +"}";
92
93 return outputStr;
94 }
95
96
97
98 public Intent getIntent() {
99 //System.out.println("getIntent");
100 return Intent.NODE;
101 }
102
103 public Class getTraitClass() {
104 System.out.println("getTraitClass ran. Not expected. Quit now");
105 System.exit(0);
106 return int[].class;
107 }
108
109
110 public int[] getTrait(Tree tree, NodeRef node) {
111 // return getStatesForNode(tree, node);
112 System.out.println("getTrait ran. Not expected. Quit now");
113 System.exit(0);
114 //int x[] = new int[10];
115 return null;
116 }
117
118
119 });
120
121
122 }
123
124
125
126 public TreeTrait[] getTreeTraits() {
127 //System.out.println("hihi");
128 return treeTraits.getTreeTraits();
129 }
130
131
132 public TreeTrait getTreeTrait(String key) {
133 System.out.println("not expected to run getTreeTrait. Quit now");
134 System.exit(0);
135 return treeTraits.getTreeTrait(key);
136 }
137
138
139
140
141 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
142
143
144 public String getParserName() {
145 return ANNOTATELOCATIONPARAMETERTREETRAIT;
146 }
147
148 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
149 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
150
151 XMLObject cxo = xo.getChild(locationParameterStr);
152 MatrixParameter locationParameter = (MatrixParameter) cxo.getChild(MatrixParameter.class);
153
154 cxo = xo.getChild(indicatorsStr);
155 Parameter indicators = (Parameter) cxo.getChild(Parameter.class);
156
157 // cxo = xo.getChild(serumDriftStr);
158 // Parameter serumDrift = (Parameter) cxo.getChild(Parameter.class);
159
160 boolean hasDrift = xo.getAttribute(hasDriftStr, false);
161
162 Parameter mu1Scale = null;
163 if (xo.hasChildNamed(MU1_SCALE_PARAMETER)) {
164 mu1Scale = (Parameter) xo.getElementFirstChild(MU1_SCALE_PARAMETER);
165 }
166
167 Parameter mu2Scale = null;
168 if (xo.hasChildNamed(MU2_SCALE_PARAMETER)) {
169 mu2Scale = (Parameter) xo.getElementFirstChild(MU2_SCALE_PARAMETER);
170 }
171
172 Parameter muMean = null;
173 if(xo.hasChildNamed(MUMEAN_PARAMETER)){
174 muMean = (Parameter) xo.getElementFirstChild(MUMEAN_PARAMETER);
175 }
176 // return new AnnotateMuTreeTrait( treeModel, clusterLabelsTreeNode, indicators, serumDrift,driftTreeClusterMu);
177 return new AnnotateLocationParameterTreeTrait( treeModel, locationParameter, indicators, hasDrift, mu1Scale, mu2Scale, muMean);
178
179 }
180
181 //************************************************************************
182 // AbstractXMLObjectParser implementation
183 //************************************************************************
184
185 public String getParserDescription() {
186 return "Integrate mu coordinates into the tree.";
187 }
188
189 public Class getReturnType() {
190 return AnnotateLocationParameterTreeTrait.class;
191 }
192
193 public XMLSyntaxRule[] getSyntaxRules() {
194 return rules;
195 }
196
197 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
198 new ElementRule(TreeModel.class),
199 new ElementRule(locationParameterStr, MatrixParameter.class),
200 new ElementRule(indicatorsStr,Parameter.class),
201 // new ElementRule(serumDriftStr, Parameter.class),
202 new ElementRule(MU1_SCALE_PARAMETER, Parameter.class, "Optional parameter for scaling the first dimension of mu"),
203 new ElementRule(MU2_SCALE_PARAMETER, Parameter.class, "Optional parameter for scaling the second dimension of mu"),
204 new ElementRule(MUMEAN_PARAMETER, Parameter.class),
205 AttributeRule.newBooleanRule(hasDriftStr, true, "whether to multiple the mu by the drift term"),
206
207 };
208 };
209
210
211 }