X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=weighted.cpp;h=a114d2ca0756c6fe671dc135acf0254ad1d5bf92;hb=b8f3e71c8a0310e25261464d27e6fcfe891483b0;hp=fa22716e397c4dddb1dd1ab29e2cd04d40b10311;hpb=fc7cf3aac8fd6106fd725b43baa8ab5ca6f836f8;p=mothur.git diff --git a/weighted.cpp b/weighted.cpp index fa22716..a114d2c 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -26,11 +26,16 @@ EstOutput Weighted::getValues(Tree* t) { //initialize weighted scores WScore[globaldata->Groups[i]+globaldata->Groups[l]] = 0.0; + vector groups; groups.push_back(globaldata->Groups[i]); groups.push_back(globaldata->Groups[l]); + D.push_back(0.0000); //initialize a spot in D for each combination /********************************************************/ //calculate a D value for each group combo for(int v=0;vgetNumLeaves();v++){ + + if (m->control_pressed) { return data; } + int index = v; double sum = 0.0000; @@ -39,22 +44,38 @@ EstOutput Weighted::getValues(Tree* t) { //if you have a BL if(t->tree[index].getBranchLength() != -1){ - sum += t->tree[index].getBranchLength(); + sum += abs(t->tree[index].getBranchLength()); } index = t->tree[index].getParent(); } //get last breanch length added if(t->tree[index].getBranchLength() != -1){ - sum += t->tree[index].getBranchLength(); + sum += abs(t->tree[index].getBranchLength()); } //is this sum from a sequence which is in one of the users groups if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) { //is this sum from a sequence which is in this groupCombo - if ((t->tree[v].getGroup() == globaldata->Groups[i]) || (t->tree[v].getGroup() == globaldata->Groups[l])) { - sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()]; - D[count] += sum; + if (inUsersGroups(t->tree[v].getGroup(), groups)) { + int numSeqsInGroupI, numSeqsInGroupL; + + map::iterator it; + it = t->tree[v].pcount.find(groups[0]); + if (it != t->tree[v].pcount.end()) { //this leaf node contains seqs from group i + numSeqsInGroupI = it->second; + }else{ numSeqsInGroupI = 0; } + + it = t->tree[v].pcount.find(groups[1]); + if (it != t->tree[v].pcount.end()) { //this leaf node contains seqs from group l + numSeqsInGroupL = it->second; + }else{ numSeqsInGroupL = 0; } + + double weightedSum = ((numSeqsInGroupI * sum) / (double)tmap->seqsPerGroup[groups[0]]) + ((numSeqsInGroupL * sum) / (double)tmap->seqsPerGroup[groups[1]]); + + //sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()]; + + D[count] += weightedSum; } } } @@ -69,6 +90,9 @@ EstOutput Weighted::getValues(Tree* t) { //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC. for (int b=0; bcontrol_pressed) { return data; } + //calculate a u value for each combo double u; //does this node have descendants from group b-1 @@ -85,7 +109,7 @@ EstOutput Weighted::getValues(Tree* t) { u -= (double) t->tree[i].pcount[globaldata->Groups[l]] / (double) tmap->seqsPerGroup[globaldata->Groups[l]]; } - u = abs(u) * t->tree[i].getBranchLength(); + u = abs(u * t->tree[i].getBranchLength()); //save groupcombs u value WScore[globaldata->Groups[b]+globaldata->Groups[l]] += u; @@ -109,14 +133,9 @@ EstOutput Weighted::getValues(Tree* t) { return data; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "Weighted", "getValues"); exit(1); } - } /**************************************************************************************************/ @@ -130,10 +149,13 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { WScore[(groupA+groupB)] = 0.0; float D = 0.0; + vector groups; groups.push_back(groupA); groups.push_back(groupB); /********************************************************/ //calculate a D value for the group combo for(int v=0;vgetNumLeaves();v++){ + if (m->control_pressed) { return data; } + int index = v; double sum = 0.0000; @@ -142,25 +164,44 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { //if you have a BL if(t->tree[index].getBranchLength() != -1){ - sum += t->tree[index].getBranchLength(); + sum += abs(t->tree[index].getBranchLength()); } index = t->tree[index].getParent(); } //get last breanch length added if(t->tree[index].getBranchLength() != -1){ - sum += t->tree[index].getBranchLength(); + sum += abs(t->tree[index].getBranchLength()); } - if ((t->tree[v].getGroup() == groupA) || (t->tree[v].getGroup() == groupB)) { - sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()]; - D += sum; + if (inUsersGroups(t->tree[v].getGroup(), groups)) { + int numSeqsInGroupI, numSeqsInGroupL; + + map::iterator it; + it = t->tree[v].pcount.find(groups[0]); + if (it != t->tree[v].pcount.end()) { //this leaf node contains seqs from group i + numSeqsInGroupI = it->second; + }else{ numSeqsInGroupI = 0; } + + it = t->tree[v].pcount.find(groups[1]); + if (it != t->tree[v].pcount.end()) { //this leaf node contains seqs from group l + numSeqsInGroupL = it->second; + }else{ numSeqsInGroupL = 0; } + + double weightedSum = ((numSeqsInGroupI * sum) / (double)tmap->seqsPerGroup[groups[0]]) + ((numSeqsInGroupL * sum) / (double)tmap->seqsPerGroup[groups[1]]); + + //sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()]; + + D += weightedSum; } } /********************************************************/ //calculate u for the group comb for(int i=0;igetNumNodes();i++){ + + if (m->control_pressed) { return data; } + double u; //does this node have descendants from groupA it = t->tree[i].pcount.find(groupA); @@ -177,7 +218,7 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { u -= (double) t->tree[i].pcount[groupB] / (double) tmap->seqsPerGroup[groupB]; } - u = abs(u) * t->tree[i].getBranchLength(); + u = abs(u * t->tree[i].getBranchLength()); //save groupcombs u value WScore[(groupA+groupB)] += u; @@ -195,14 +236,9 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { return data; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "Weighted", "getValues"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - }