Debian Codegraph @

src/dr/evomodel/branchmodel/lineagespecific/BranchSpecificTrait.java

raw symbols SCIP
1 /*
2 * BranchSpecificTrait.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.branchmodel.lineagespecific;
27
28 import dr.evolution.tree.*;
29 import dr.evomodel.branchmodel.BranchModel;
30 import dr.evomodel.substmodel.SubstitutionModel;
31 import dr.evomodel.tree.TreeModel;
32 import dr.inference.model.CompoundParameter;
33 import dr.inference.model.Parameter;
34
35 /**
36 * @author Filip Bielejec
37 * @version $Id$
38 *
39 */
40 public class BranchSpecificTrait implements TreeTraitProvider {
41
42 private Helper helper;
43 private TreeModel treeModel;
44
45 public BranchSpecificTrait(
46 TreeModel treeModel,
47 Parameter uCategories,
48 CompoundParameter uniqueParameters,
49 final String parameterName) {
50
51 this.treeModel = treeModel;
52 helper = new Helper();
53
54 TreeTrait<Double> uTrait = new TreeTrait.D() {
55
56 @Override
57 public String getTraitName() {
58 return parameterName;
59 }
60
61 @Override
62 public dr.evolution.tree.TreeTrait.Intent getIntent() {
63 return Intent.BRANCH;
64 }
65
66 @Override
67 public Double getTrait(Tree tree, NodeRef node) {
68
69 double value = 0.0;
70
71
72
73
74
75
76
77
78
79
80
81 return null;
82 }
83
84
85
86 };
87
88
89 }//END: Constructor
90
91 public BranchSpecificTrait(
92 TreeModel treeModel,
93 final BranchModel branchModel,
94 // , final CompoundParameter parameter
95 final String parameterName
96 ) {
97
98 this.treeModel = treeModel;
99 helper = new Helper();
100
101 //TODO: this could annotate with all Variables in Substitution model
102 TreeTrait<Double> uTrait = new TreeTrait.D() {
103
104 @Override
105 public String getTraitName() {
106 return parameterName;//parameter.getId();
107 }
108
109 @Override
110 public dr.evolution.tree.TreeTrait.Intent getIntent() {
111 return Intent.BRANCH;
112 }
113
114 @Override
115 public Double getTrait(Tree tree, NodeRef branch) {
116
117 double value = 0.0;
118
119 int[] uCats = branchModel.getBranchModelMapping(branch).getOrder();
120 int category = uCats[0];
121
122 SubstitutionModel substmodel = branchModel.getSubstitutionModels().get(category);
123 value = (Double) substmodel.getVariable(0).getValue(0);
124
125
126 return value;
127
128 }//END: getTrait
129 };
130
131 helper.addTrait(uTrait);
132
133 }//END: Constructor
134
135 public TreeTrait[] getTreeTraits() {
136 return helper.getTreeTraits();
137 }
138
139 public TreeTrait getTreeTrait(String key) {
140 return helper.getTreeTrait(key);
141 }
142
143 public String toString() {
144
145 String annotatedTree = TreeUtils.newick(treeModel,
146 new TreeTraitProvider[] { this });
147
148 return annotatedTree;
149
150 }// END: toString
151
152 }//END: class