Debian Codegraph @

src/dr/evomodel/antigenic/NPAntigenicLikelihood.java

raw symbols SCIP
1 /*
2 * NPAntigenicLikelihood.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evomodel.antigenic;
27
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Set;
32 import java.util.logging.Logger;
33
34 import dr.evolution.tree.NodeRef;
35 import dr.evolution.tree.TreeUtils;
36 import dr.evomodel.tree.TreeModel;
37 import dr.evomodelxml.treelikelihood.TreeTraitParserUtilities;
38 import dr.inference.model.AbstractModelLikelihood;
39 import dr.inference.model.CompoundParameter;
40 import dr.inference.model.Model;
41 import dr.inference.model.Parameter;
42 import dr.inference.model.Variable;
43 import dr.math.GammaFunction;
44 import dr.xml.AbstractXMLObjectParser;
45 import dr.xml.ElementRule;
46 import dr.xml.StringAttributeRule;
47 import dr.xml.XMLObject;
48 import dr.xml.XMLObjectParser;
49 import dr.xml.XMLParseException;
50 import dr.xml.XMLSyntaxRule;
51
52 /**
53 * @author Gabriela Cybis
54 * @author Marc Suchard
55 */
56 public class NPAntigenicLikelihood extends AbstractModelLikelihood {
57
58 public static final String NP_ANTIGENIC_LIKELIHOOD = "NPAntigenicLikelihood";
59
60
61
62 public NPAntigenicLikelihood (TreeModel treeModel,CompoundParameter traitParameter , Parameter assignments, Parameter links,
63 Parameter chi, Parameter clusterPrec, Parameter priorMean, Parameter priorPrec,
64 Parameter transformFactor,Parameter means1, Parameter means2, Parameter locationDrift,
65 Parameter offsets, Boolean hasDrift){
66 super(NP_ANTIGENIC_LIKELIHOOD);
67
68
69 this.assignments = assignments;
70 this.links = links;
71 this.clusterPrec = clusterPrec;
72 this.priorPrec = priorPrec;
73 this.priorMean = priorMean;
74 this.treeModel= treeModel;
75 this.traitParameter= traitParameter;
76 this.transformFactor=transformFactor;
77 this.means1=means1;
78 this.means2=means2;
79 this.alpha= chi;
80 this.locationDrift=locationDrift;
81 this.offsets=offsets;
82 // this.hasDrift=hasDrift;
83 this.hasDrift=false;
84
85
86
87 addVariable(traitParameter);
88 addVariable(assignments);
89 addVariable(links);
90 addModel(treeModel);
91 addVariable(chi);
92 addVariable(transformFactor);
93 addVariable(alpha);
94 // addVariable(locationDrift);
95 addVariable(offsets);
96
97 numdata = traitParameter.getParameterCount();
98 this.allTips= TreeUtils.getExternalNodes(treeModel,treeModel.getRoot());
99
100
101
102 setDepMatrix();
103
104
105
106
107
108 for (int i=0; i<numdata; i++){
109 assignments.setParameterValue(i, i);
110 links.setParameterValue(i,i);
111
112 }
113
114
115
116 this.logLikelihoodsVector = new double[links.getDimension()+1];
117 this.logLikelihoodsVectorKnown = new boolean[links.getDimension()+1];
118 this.storedLogLikelihoodsVector = new double[links.getDimension()+1];
119
120
121
122 this.m = new double[2];
123 m[0]= priorMean.getParameterValue(0);
124 m[1]= priorMean.getParameterValue(1);
125
126
127 this.v0 = 2;
128 // double v1 = 3;
129
130 this.k0= priorPrec.getParameterValue(0)/clusterPrec.getParameterValue(0);
131 // double k1= k0+1;
132
133
134 this.T0Inv= new double[2][2];
135 T0Inv[0][0]= v0/clusterPrec.getParameterValue(0);
136 T0Inv[1][1]= v0/clusterPrec.getParameterValue(0);
137 T0Inv[1][0]= 0.0;
138 T0Inv[0][1]= 0.0;
139
140
141 this.logDetT0= -Math.log(T0Inv[0][0]*T0Inv[1][1]);
142
143
144 /* for(int i=0;i<logLikelihoodsVector.length-1;i++){
145
146 double[][] T1Inv = new double[2][2];
147 T1Inv[0][0]=T0Inv[0][0]+(k0/k1)* data[i][0]*data[i][0];
148 T1Inv[0][1]=T0Inv[0][1]+(k0/k1)* data[i][0]*data[i][1];
149 T1Inv[1][0]=T0Inv[1][0]+(k0/k1)* data[i][1]*data[i][0];
150 T1Inv[1][1]=T0Inv[1][1]+(k0/k1)* data[i][1]*data[i][1];
151
152
153 double logDetT1=-Math.log(T1Inv[0][0]*T1Inv[1][1]-T1Inv[0][1]*T1Inv[1][0]);
154
155
156 logLikelihoodsVector[i]= -(1*2/2)*Math.log(Math.PI);
157 logLikelihoodsVector[i]+= Math.log(k0) - Math.log(k1);
158 logLikelihoodsVector[i]+= (v1/2)*logDetT1 - (v0/2)*logDetT0;
159 logLikelihoodsVector[i]+= GammaFunction.lnGamma(v1/2)+ GammaFunction.lnGamma((v1/2)-0.5);
160 logLikelihoodsVector[i]+=-GammaFunction.lnGamma(v0/2)- GammaFunction.lnGamma((v0/2)-0.5);
161
162
163 }
164 */
165
166
167
168
169 }
170
171
172 /*
173 public void setInitialAssignmentsToDates(){
174
175
176
177
178
179
180
181 double[] offsetValues = new double[numdata];
182 for (int i=0; i<numdata; i++){
183 offsetValues[i] =offsets.getParameterValue(findOffsetIndex(i));
184
185 }
186
187
188 boolean[] assigned = new boolean[numdata];
189 for (int i=0; i<numdata;i++ ){
190 assigned[i]=false;
191 }
192
193 int group = 0;
194 for (int i=0; i<numdata; i++){
195 if (!assigned[i]){
196
197 int last = i;
198 for (int j=0;j<numdata;j++){
199
200 if (offsetValues[j]==offsetValues[i]||offsetValues[j]==offsetValues[i]+1||offsetValues[j]==offsetValues[i]+2||offsetValues[j]==offsetValues[i]+3||offsetValues[j]==offsetValues[i]+4){
201 links.setParameterValue(j,last);
202 assignments.setParameterValue(j, group);
203 assigned[j]=true;
204 last=j;
205 }
206
207 }
208 links.setParameterValue(i,last);
209 group ++;
210
211 }
212
213
214
215 }
216
217
218 printInformation(links);
219 printInformation(assignments);
220
221
222
223 }
224
225
226 private int findOffsetIndex(int traitParameterIndex){
227 String NAME = traitParameter.getParameter(traitParameterIndex).getParameterName();
228 boolean notFound =true;
229 int i=0;
230
231
232 while (notFound){
233
234 if(offsets.getDimensionName(i).compareTo(NAME)==0){
235
236 notFound=false;
237 }else{
238 i++;
239 }
240 }
241
242 // printInformation((double) i);
243 // printInformation(offsets.getDimensionName(i),NAME);
244
245 return i;
246 }
247
248
249
250
251 private void setData(){
252 dataMatrixKnown=true;
253 int dim = traitParameter.getParameter(0).getSize();
254
255
256 for (int i=0; i<numdata; i++){
257 for (int j=1; j<dim; j++){
258 data[i][j]= traitParameter.getParameter(i).getParameterValue(j);
259 }
260 //if (hasDrift){
261 // int offsetIndex = findOffsetIndex(i);
262 // Data[i][0] += locationDrift.getParameterValue(0)*offsets.getParameterValue(offsetIndex);
263 //} else{
264 data[i][0]= traitParameter.getParameter(i).getParameterValue(0);
265 //}
266 }
267
268
269
270 }
271
272
273 private void setDatum(int virus){
274
275
276 int dim = traitParameter.getParameter(0).getSize();
277
278
279 for (int j=1; j<dim; j++){
280 data[virus][j]= traitParameter.getParameter(virus).getParameterValue(j);
281 }
282 //if (hasDrift){
283 // int offsetIndex = findOffsetIndex(i);
284 // Data[i][0] += locationDrift.getParameterValue(0)*offsets.getParameterValue(offsetIndex);
285 //} else{
286 data[virus][0]= traitParameter.getParameter(virus).getParameterValue(0);
287 //}
288
289
290
291
292 }
293 */
294
295
296 private void setDepMatrix(){
297
298 depMatrixKnown = true;
299
300 depMatrix=new double[numdata][numdata];
301 List<NodeRef> childList = new ArrayList<NodeRef>();
302
303 recursion(treeModel.getRoot(),childList);
304 logCorrectMatrix(transformFactor.getParameterValue(0));
305 logDepMatrix = new double[numdata][numdata];
306 for(int i=0;i<numdata;i++){
307 for(int j=0;j<i;j++){
308 logDepMatrix[i][j]=Math.log(depMatrix[i][j]);
309 logDepMatrix[j][i]=logDepMatrix[j][i];
310
311 }
312 }
313
314 }
315
316
317
318
319
320 public double getLogLikGroup(int groupNumber){
321 double L =0.0;
322
323
324 int ngroup=0;
325 for (int i=0;i<assignments.getDimension(); i++){
326 if((int) assignments.getParameterValue(i) == groupNumber){
327 ngroup++;}}
328
329
330 if (ngroup != 0){
331 double[][] group = new double[ngroup][2];
332
333
334 double mean[]=new double[2];
335
336 int count = 0;
337 for (int i=0;i<assignments.getDimension(); i++){
338 if((int) assignments.getParameterValue(i) == groupNumber){
339 group[count][0] = getData(i,0);
340 group[count][1] = getData(i,0);
341 mean[0]+=group[count][0];
342 mean[1]+=group[count][1];
343 count++;}}
344
345 mean[0]/=ngroup;
346 mean[1]/=ngroup;
347
348
349
350 double kn= k0+ngroup;
351 double vn= v0+ngroup;
352
353
354 double[][] sumdif=new double[2][2];
355
356 for(int i=0;i<ngroup;i++){
357 sumdif[0][0]+= (group[i][0]-mean[0])*(group[i][0]-mean[0]);
358 sumdif[0][1]+= (group[i][0]-mean[0])*(group[i][1]-mean[1]);
359 sumdif[1][0]+= (group[i][0]-mean[0])*(group[i][1]-mean[1]);
360 sumdif[1][1]+= (group[i][1]-mean[1])*(group[i][1]-mean[1]);
361 }
362
363
364
365 double[][] TnInv = new double[2][2];
366 TnInv[0][0]=T0Inv[0][0]+ngroup*(k0/kn)*(mean[0]-m[0])*(mean[0]-m[0])+sumdif[0][0];
367 TnInv[0][1]=T0Inv[0][1]+ngroup*(k0/kn)*(mean[1]-m[1])*(mean[0]-m[0])+sumdif[0][1];
368 TnInv[1][0]=T0Inv[1][0]+ngroup*(k0/kn)* (mean[0]-m[0])*(mean[1]-m[1])+sumdif[1][0];
369 TnInv[1][1]=T0Inv[1][1]+ngroup*(k0/kn)* (mean[1]-m[1])*(mean[1]-m[1])+sumdif[1][1];
370
371
372 double logDetTn=-Math.log(TnInv[0][0]*TnInv[1][1]-TnInv[0][1]*TnInv[1][0]);
373
374
375 L+= -(ngroup)*Math.log(Math.PI);
376 L+= Math.log(k0) - Math.log(kn);
377 L+= (vn/2)*logDetTn - (v0/2)*logDetT0;
378 L+= GammaFunction.lnGamma(vn/2)+ GammaFunction.lnGamma((vn/2)-0.5);
379 L+=-GammaFunction.lnGamma(v0/2)- GammaFunction.lnGamma((v0/2)-0.5);
380
381
382
383
384
385
386 }
387 logLikelihoodsVectorKnown[groupNumber]=true;
388 return L;
389
390 }
391
392
393
394
395
396
397
398 public Model getModel() {
399 return this;
400 }
401
402
403
404 public double[] getLogLikelihoodsVector(){
405 return logLikelihoodsVector;
406 }
407
408 public Parameter getLinks(){
409 return links;
410 }
411
412 public Parameter getAssignments(){
413 return assignments;
414 }
415
416
417 public double getData(int virus, int dim){
418 return traitParameter.getParameter(virus).getParameterValue(dim);
419 }
420
421 public double[][] getDepMatrix(){
422 return depMatrix;
423 }
424
425
426 public double[][] getLogDepMatrix(){
427 return logDepMatrix;
428 }
429
430 public Parameter getPriorMean(){
431 return priorMean;
432 }
433 public Parameter getPriorPrec(){
434 return priorPrec;
435 }
436 public Parameter getClusterPrec(){
437 return clusterPrec;
438 }
439
440 public void setLogLikelihoodsVector(int pos, double value){
441 logLikelihoodsVector[pos]=value;
442 }
443
444 public void setAssingments(int pos, double value){
445 assignments.setParameterValue(pos,value);
446 }
447
448 public void setLinks(int pos, double value){
449 links.setParameterValue(pos,value);
450 }
451
452 public void setMeans(int pos, double[] value){
453 means1.setParameterValue(pos,value[0]);
454 means2.setParameterValue(pos,value[1]);
455 }
456
457
458 public double getLogLikelihood() {
459 if (!logLikelihoodKnown) {
460
461 logLikelihood = computeLogLikelihood();
462 }
463
464 return logLikelihood;
465 }
466
467
468
469
470 public double computeLogLikelihood() {
471
472
473 if (!depMatrixKnown ){
474 setDepMatrix();
475 }
476
477
478
479
480 double logL = 0.0;
481 for (int j=0 ; j<logLikelihoodsVector.length;j++){
482
483 if(!logLikelihoodsVectorKnown[j]){
484 logLikelihoodsVector[j]=getLogLikGroup(j);
485 }
486 logL +=logLikelihoodsVector[j];
487
488 }
489
490 for (int j=0 ; j<links.getDimension();j++){
491 if(links.getParameterValue(j)==j){
492 logL += Math.log(alpha.getParameterValue(0));
493 }
494 else{logL += Math.log(depMatrix[j][(int) links.getParameterValue(j)]);
495
496 }
497
498 double sumDist=0.0;
499 for (int i=0;i<numdata;i++){
500 if(i!=j){sumDist += depMatrix[i][j];
501 }
502 }
503
504 logL-= Math.log(alpha.getParameterValue(0)+sumDist);
505 }
506
507
508
509 logLikelihoodKnown=true;
510 // printInformation(logL);
511
512 return logL;
513
514
515 }
516
517
518
519 /* Getting matrix from tree*/
520
521 void recursion( NodeRef node, List childList){
522
523
524 List<NodeRef> leftChildTipList = new ArrayList<NodeRef>();
525 List<NodeRef> rightChildTipList = new ArrayList<NodeRef>();
526
527 if(!treeModel.isExternal(node)){
528 recursion(treeModel.getChild(node, 0),leftChildTipList);
529 recursion(treeModel.getChild(node, 1),rightChildTipList);
530
531
532 double lBranch = treeModel.getBranchLength(treeModel.getChild(node, 0));
533 double rBranch = treeModel.getBranchLength(treeModel.getChild(node, 1));
534
535
536 Set<NodeRef> notLeftChildList = new HashSet<NodeRef>();
537 notLeftChildList.addAll(allTips);
538 for (NodeRef i :leftChildTipList){
539 notLeftChildList.remove(i);
540 }
541 Set<NodeRef> notRightChildList = new HashSet<NodeRef>();
542 notRightChildList.addAll(allTips);
543 for (NodeRef i :rightChildTipList){
544 notRightChildList.remove(i);
545 }
546
547 for (NodeRef lChild : leftChildTipList){
548 for (NodeRef Child : notLeftChildList){
549 depMatrix[Child.getNumber()][lChild.getNumber()] += lBranch;
550 depMatrix[lChild.getNumber()][Child.getNumber()] += lBranch;
551 }
552 }
553
554
555 for (NodeRef rChild : rightChildTipList){
556 for (NodeRef Child : notRightChildList){
557 depMatrix[Child.getNumber()][rChild.getNumber()] += rBranch;
558 depMatrix[rChild.getNumber()][Child.getNumber()] += rBranch;
559 }
560 }
561
562
563 childList.addAll(leftChildTipList);
564 childList.addAll(rightChildTipList);
565 }
566 else{
567 childList.add(node);
568 }
569
570 }
571
572
573
574 void logCorrectMatrix(double p){
575 for (int i=0; i<numdata; i++){
576 for (int j=0; j<i; j++){
577 depMatrix[i][j]=1/Math.pow(depMatrix[i][j],p);
578 depMatrix[j][i]=depMatrix[i][j];
579 }}
580
581 }
582
583
584
585
586
587
588
589
590 public double getTreeDist(int i, int j){
591 double dist=0;
592
593 NodeRef MRCA = findMRCA(i,j);
594
595 NodeRef Parent = treeModel.getExternalNode(i);
596 while (Parent!=MRCA){
597 dist+=treeModel.getBranchLength(Parent);
598 Parent = treeModel.getParent(Parent);
599 }
600
601 Parent = treeModel.getExternalNode(j);
602 while (Parent!=MRCA){
603 dist+=treeModel.getBranchLength(Parent);
604 Parent = treeModel.getParent(Parent);
605 }
606
607 return dist;
608 }
609
610
611 private NodeRef findMRCA(int iTip, int jTip) {
612 Set<String> leafNames = new HashSet<String>();
613 leafNames.add(treeModel.getTaxonId(iTip));
614 leafNames.add(treeModel.getTaxonId(jTip));
615 return TreeUtils.getCommonAncestorNode(treeModel, leafNames);
616 }
617
618
619 public void printInformtion(double[][] Mat) {
620 StringBuffer sb = new StringBuffer("matrix \n");
621 for(int i=0;i <numdata; i++){
622 sb.append(" \n");
623 for(int j=0; j<numdata; j++){
624 sb.append(Mat[i][j]+" \t");
625 }
626 }
627
628 Logger.getLogger("dr.evomodel").info(sb.toString()); };
629
630
631 public void printInformation(Parameter Vec) {
632 StringBuffer sb = new StringBuffer("Vector \n");
633
634 for (int i = 0; i<numdata; i++){
635 sb.append(Vec.getParameterValue(i)+" \t");
636 }
637
638
639 Logger.getLogger("dr.evomodel").info(sb.toString()); };
640
641
642
643
644 public void printInformation(int[] Vec) {
645 StringBuffer sb = new StringBuffer("Vector \n");
646 for(int i=0;i <numdata; i++){
647
648 sb.append(Vec[i]+" \t");
649
650 }
651
652 Logger.getLogger("dr.evomodel").info(sb.toString()); };
653
654
655
656
657 public void printOrder() {
658 StringBuffer sb = new StringBuffer("taxa \n");
659 for(int i=0;i <numdata; i++){
660 sb.append(" \n");
661
662 sb.append(treeModel.getTaxonId(i));
663 }
664
665 Logger.getLogger("dr.evomodel").info(sb.toString()); };
666
667
668
669
670
671 public void printInformation(double x) {
672 StringBuffer sb = new StringBuffer("Info \n");
673 sb.append(x);
674
675 Logger.getLogger("dr.evomodel").info(sb.toString()); };
676
677 public void printInformation(String x) {
678 StringBuffer sb = new StringBuffer("Info \n");
679 sb.append(x);
680
681 Logger.getLogger("dr.evomodel").info(sb.toString()); };
682
683 public void printInformation(String x, String y) {
684 StringBuffer sb = new StringBuffer("Info \n");
685 sb.append(x + " and " + y);
686
687 Logger.getLogger("dr.evomodel").info(sb.toString()); };
688
689
690
691 @Override
692 protected void storeState() {
693 System.arraycopy(logLikelihoodsVector, 0, storedLogLikelihoodsVector, 0, logLikelihoodsVector.length);
694 }
695
696 @Override
697 protected void restoreState() {
698 double[] tmp = logLikelihoodsVector;
699 logLikelihoodsVector = storedLogLikelihoodsVector;
700 storedLogLikelihoodsVector = tmp;
701
702 depMatrixKnown = !proposedChangeDepMatrix;
703 proposedChangeDepMatrix =false;
704
705 // dataMatrixKnown = !proposedChangeDataMatrix;
706 // proposedChangeDataMatrix =false;
707
708 logLikelihoodKnown = false;
709 }
710
711
712
713
714
715 public void makeDirty() {
716 }
717
718 public void acceptState() {
719 // DO NOTHING
720 proposedChangeDepMatrix =false;
721 proposedChangeDataMatrix =false;
722 }
723
724
725 protected void handleModelChangedEvent(Model model, Object object, int index) {
726 if (model == treeModel)
727 depMatrixKnown=false;
728 logLikelihoodKnown=false;
729 return;
730 }
731
732
733 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
734 logLikelihoodKnown = false;
735
736 if (variable == transformFactor) {
737 depMatrixKnown=false;
738 proposedChangeDepMatrix=true;
739 }
740
741 // if (variable == traitParameter || variable == locationDrift ){
742 if (variable == traitParameter){
743 // dataMatrixKnown=false;
744 // proposedChangeDataMatrix=true;
745
746 int loc= index / 2;
747 int changedGroup=(int)assignments.getParameterValue(loc);
748 logLikelihoodsVectorKnown[changedGroup]=false;
749 }
750
751 }
752
753 Set<NodeRef> allTips;
754 CompoundParameter traitParameter;
755 Parameter alpha;
756 Parameter clusterPrec ;
757 Parameter priorPrec ;
758 Parameter priorMean ;
759 Parameter assignments;
760 Parameter links;
761 Parameter means2;
762 Parameter means1;
763 Parameter locationDrift;
764 Parameter offsets;
765 boolean hasDrift;
766
767 private boolean depMatrixKnown= false;
768 private boolean[] dataMatrixKnown;
769 private boolean logLikelihoodKnown=false;
770 private double logLikelihood =0.0;
771 private boolean[] logLikelihoodsVectorKnown;
772
773
774 boolean proposedChangeDepMatrix=false;
775 boolean proposedChangeDataMatrix=false;
776
777
778
779
780 TreeModel treeModel;
781 String traitName;
782 //double[][] data;
783 double[][] depMatrix;
784 double[][] logDepMatrix;
785 double[] logLikelihoodsVector;
786 double[] storedLogLikelihoodsVector;
787 int numdata;
788 Parameter transformFactor;
789 double k0;
790 double v0;
791 double[][] T0Inv;
792 double[] m;
793 double logDetT0;
794
795 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
796 public final static String CLUSTER_PREC = "clusterPrec";
797 public final static String PRIOR_PREC = "priorPrec";
798 public final static String PRIOR_MEAN = "priorMean";
799 public final static String ASSIGNMENTS = "assignments";
800 public final static String LINKS = "links";
801 public final static String MEANS_1 = "clusterMeans1";
802 public final static String MEANS_2 = "clusterMeans2";
803 public final static String TRANSFORM_FACTOR = "transformFactor";
804 public final static String CHI = "chi";
805 public final static String OFFSETS = "offsets";
806 public final static String LOCATION_DRIFT = "locationDrift";
807
808
809
810
811 boolean integrate = false;
812
813
814 public String getParserName() {
815 return NP_ANTIGENIC_LIKELIHOOD;
816 }
817
818 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
819
820 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
821 //String traitName = (String) xo.getAttribute(TRAIT_NAME);
822
823 XMLObject cxo = xo.getChild(CLUSTER_PREC);
824 Parameter clusterPrec = (Parameter) cxo.getChild(Parameter.class);
825
826 cxo = xo.getChild(PRIOR_PREC);
827 Parameter priorPrec = (Parameter) cxo.getChild(Parameter.class);
828
829 cxo = xo.getChild(PRIOR_MEAN);
830 Parameter priorMean = (Parameter) cxo.getChild(Parameter.class);
831
832 cxo = xo.getChild(ASSIGNMENTS);
833 Parameter assignments = (Parameter) cxo.getChild(Parameter.class);
834
835
836 cxo = xo.getChild(LINKS);
837 Parameter links = (Parameter) cxo.getChild(Parameter.class);
838
839 cxo = xo.getChild(MEANS_2);
840 Parameter means2 = (Parameter) cxo.getChild(Parameter.class);
841
842 cxo = xo.getChild(MEANS_1);
843 Parameter means1 = (Parameter) cxo.getChild(Parameter.class);
844
845 cxo = xo.getChild(CHI);
846 Parameter chi = (Parameter) cxo.getChild(Parameter.class);
847
848 cxo = xo.getChild(TRANSFORM_FACTOR);
849 Parameter transformFactor = (Parameter) cxo.getChild(Parameter.class);
850
851
852
853 cxo=xo.getChild(LOCATION_DRIFT) ;
854 Parameter locationDrift= (Parameter) cxo.getChild(Parameter.class);
855
856 cxo=xo.getChild(OFFSETS);
857 Parameter offsets =(Parameter) cxo.getChild(Parameter.class);
858
859 boolean hasDrift = false;
860 if (offsets.getDimension()>1){
861 hasDrift=true;
862 }
863
864
865
866 TreeTraitParserUtilities utilities = new TreeTraitParserUtilities();
867 String traitName = TreeTraitParserUtilities.DEFAULT_TRAIT_NAME;
868
869
870 TreeTraitParserUtilities.TraitsAndMissingIndices returnValue =
871 utilities.parseTraitsFromTaxonAttributes(xo, traitName, treeModel, integrate);
872 // traitName = returnValue.traitName;
873 CompoundParameter traitParameter = returnValue.traitParameter;
874
875
876
877
878
879 return new NPAntigenicLikelihood(treeModel,traitParameter, assignments, links, chi,clusterPrec, priorMean,priorPrec,
880 transformFactor, means1,means2,locationDrift,offsets,hasDrift);
881 }
882
883 //************************************************************************
884 // AbstractXMLObjectParser implementation
885 //************************************************************************
886
887 public String getParserDescription() {
888 return "conditional likelihood ddCRP";
889 }
890
891 public Class getReturnType() {
892 return NPAntigenicLikelihood.class;
893 }
894
895 public XMLSyntaxRule[] getSyntaxRules() {
896 return rules;
897 }
898
899 private final XMLSyntaxRule[] rules = {
900 new StringAttributeRule(TreeTraitParserUtilities.TRAIT_NAME, "The name of the trait for which a likelihood should be calculated"),
901
902 new ElementRule(TreeTraitParserUtilities.TRAIT_PARAMETER, new XMLSyntaxRule[]{
903 new ElementRule(Parameter.class)
904 }),
905 new ElementRule(PRIOR_PREC,
906 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
907 new ElementRule(CLUSTER_PREC,
908 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
909 new ElementRule(PRIOR_MEAN,
910 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
911 new ElementRule(ASSIGNMENTS,
912 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
913 new ElementRule(LINKS,
914 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
915 new ElementRule(TRANSFORM_FACTOR,
916 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
917
918 new ElementRule(MEANS_1,
919 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
920 new ElementRule(MEANS_2,
921 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
922 new ElementRule(CHI, new XMLSyntaxRule[] {
923 new ElementRule(Parameter.class),
924 }),
925 new ElementRule(OFFSETS, Parameter.class),
926 new ElementRule(LOCATION_DRIFT, Parameter.class),
927
928 new ElementRule(TreeModel.class),
929
930 };
931 };
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958 }