5 * Created by Sarah Westcott on 2/9/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "unweighted.h"
12 /**************************************************************************************************/
14 EstOutput Unweighted::getValues(Tree* t) {
16 globaldata = GlobalData::getInstance();
18 vector<string> groups;
19 double UniqueBL; //a branch length is unique if it's chidren are from the same group
20 double totalBL; //all branch lengths
21 double UW; //Unweighted Value = UniqueBL / totalBL;
23 //if the users enters no groups then give them the score of all groups
24 int numGroups = globaldata->Groups.size();
26 //calculate number of comparsions
28 for (int r=0; r<numGroups; r++) {
29 for (int l = r+1; l < numGroups; l++) {
34 //numComp+1 for AB, AC, BC, ABC
35 data.resize(numComp+1,0);
38 for (int a=0; a<numGroups; a++) {
39 for (int l = a+1; l < numGroups; l++) {
40 UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group
41 totalBL = 0.00; //all branch lengths
42 UW = 0.00; //Unweighted Value = UniqueBL / totalBL;
43 //copyIpcount.clear();
45 //groups in this combo
46 groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
48 for(int i=0;i<t->getNumNodes();i++){
49 if (m->control_pressed) { return data; }
51 //pcountSize = 0, they are from a branch that is entirely from a group the user doesn't want
52 //pcountSize = 2, not unique to one group
53 //pcountSize = 1, unique to one group
56 for (int j = 0; j < groups.size(); j++) {
57 map<string, int>::iterator itGroup = t->tree[i].pcount.find(groups[j]);
58 if (itGroup != t->tree[i].pcount.end()) { pcountSize++; }
61 if (pcountSize == 0) { }
62 else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); }
64 if ((t->tree[i].getBranchLength() != -1) && (pcountSize != 0)) {
65 totalBL += abs(t->tree[i].getBranchLength());
69 UW = (UniqueBL / totalBL);
71 if (isnan(UW) || isinf(UW)) { UW = 0; }
82 //get score for all users groups
83 for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
84 if (tmap->namesOfGroups[i] != "xxx") {
85 groups.push_back(tmap->namesOfGroups[i]);
89 for (int i = 0; i < globaldata->Groups.size(); i++) {
90 groups.push_back(globaldata->Groups[i]);
94 UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group
95 totalBL = 0.00; //all branch lengths
96 UW = 0.00; //Unweighted Value = UniqueBL / totalBL;
98 for(int i=0;i<t->getNumNodes();i++){
100 if (m->control_pressed) { return data; }
102 //pcountSize = 0, they are from a branch that is entirely from a group the user doesn't want
103 //pcountSize = 2, not unique to one group
104 //pcountSize = 1, unique to one group
107 for (int j = 0; j < groups.size(); j++) {
108 map<string, int>::iterator itGroup = t->tree[i].pcount.find(groups[j]);
109 if (itGroup != t->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } }
112 if (pcountSize == 0) { }
113 else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); }
115 if ((t->tree[i].getBranchLength() != -1) && (pcountSize != 0)) {
116 totalBL += abs(t->tree[i].getBranchLength());
120 UW = (UniqueBL / totalBL);
122 if (isnan(UW) || isinf(UW)) { UW = 0; }
130 catch(exception& e) {
131 m->errorOut(e, "Unweighted", "getValues");
136 /**************************************************************************************************/
138 EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
140 globaldata = GlobalData::getInstance();
142 vector<string> groups;
143 double UniqueBL; //a branch length is unique if it's chidren are from the same group
144 double totalBL; //all branch lengths
145 double UW; //Unweighted Value = UniqueBL / totalBL;
148 //if the users enters no groups then give them the score of all groups
149 int numGroups = globaldata->Groups.size();
151 //calculate number of comparsions
153 for (int r=0; r<numGroups; r++) {
154 for (int l = r+1; l < numGroups; l++) {
159 //numComp+1 for AB, AC, BC, ABC
160 data.resize(numComp+1,0);
163 for (int a=0; a<numGroups; a++) {
164 for (int l = a+1; l < numGroups; l++) {
165 UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group
166 totalBL = 0.00; //all branch lengths
167 UW = 0.00; //Unweighted Value = UniqueBL / totalBL;
169 //copy random tree passed in
170 copyTree->getCopy(t);
172 //groups in this combo
173 groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
175 //swap labels in the groups you want to compare
176 copyTree->assembleRandomUnifracTree(groups[0], groups[1]);
178 if (m->control_pressed) { delete copyTree; return data; }
180 for(int i=0;i<copyTree->getNumNodes();i++){
182 if (m->control_pressed) { return data; }
184 //pcountSize = 0, they are from a branch that is entirely from a group the user doesn't want
185 //pcountSize = 2, not unique to one group
186 //pcountSize = 1, unique to one group
189 for (int j = 0; j < groups.size(); j++) {
190 map<string, int>::iterator itGroup = copyTree->tree[i].pcount.find(groups[j]);
191 if (itGroup != copyTree->tree[i].pcount.end()) { pcountSize++; }
194 if (pcountSize == 0) { }
195 else if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(copyTree->tree[i].getBranchLength()); }
197 if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize != 0)) {
198 totalBL += abs(copyTree->tree[i].getBranchLength());
203 UW = (UniqueBL / totalBL);
205 if (isnan(UW) || isinf(UW)) { UW = 0; }
215 if (numGroups == 0) {
216 //get score for all users groups
217 for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
218 if (tmap->namesOfGroups[i] != "xxx") {
219 groups.push_back(tmap->namesOfGroups[i]);
223 for (int i = 0; i < globaldata->Groups.size(); i++) {
224 groups.push_back(globaldata->Groups[i]);
228 UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group
229 totalBL = 0.00; //all branch lengths
230 UW = 0.00; //Unweighted Value = UniqueBL / totalBL;
232 //copy random tree passed in
233 copyTree->getCopy(t);
235 //swap labels in all the groups you want to compare
236 copyTree->assembleRandomUnifracTree(groups);
238 if (m->control_pressed) { delete copyTree; return data; }
240 for(int i=0;i<copyTree->getNumNodes();i++){
242 if (m->control_pressed) { return data; }
244 //pcountSize = 0, they are from a branch that is entirely from a group the user doesn't want
245 //pcountSize = 2, not unique to one group
246 //pcountSize = 1, unique to one group
249 for (int j = 0; j < groups.size(); j++) {
250 map<string, int>::iterator itGroup = copyTree->tree[i].pcount.find(groups[j]);
251 if (itGroup != copyTree->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } }
254 if (pcountSize == 0) { }
255 else if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(copyTree->tree[i].getBranchLength()); }
257 if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize != 0)) {
258 totalBL += abs(copyTree->tree[i].getBranchLength());
262 UW = (UniqueBL / totalBL);
264 if (isnan(UW) || isinf(UW)) { UW = 0; }
274 catch(exception& e) {
275 m->errorOut(e, "Unweighted", "getValues");