X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=weighted.cpp;h=fa22716e397c4dddb1dd1ab29e2cd04d40b10311;hb=fc7cf3aac8fd6106fd725b43baa8ab5ca6f836f8;hp=915cf368353dcdbb1617b9d239ce17ff6890450b;hpb=cfeefe1f7d36e9ffd3fba5f2f2b906724393e442;p=mothur.git diff --git a/weighted.cpp b/weighted.cpp index 915cf36..fa22716 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -17,24 +17,14 @@ EstOutput Weighted::getValues(Tree* t) { int numGroups; vector D; - //if the user has not entered specific groups to analyze then do them all - if (globaldata->Groups.size() == 0) { - numGroups = tmap->getNumGroups(); - }else { - numGroups = globaldata->Groups.size(); - } + numGroups = globaldata->Groups.size(); //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3; - int n = 1; int count = 0; - for (int i=1; iGroups.size() == 0) { - WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] = 0.0; - }else { - WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] = 0.0; - } + WScore[globaldata->Groups[i]+globaldata->Groups[l]] = 0.0; D.push_back(0.0000); //initialize a spot in D for each combination @@ -59,106 +49,62 @@ EstOutput Weighted::getValues(Tree* t) { sum += t->tree[index].getBranchLength(); } - if (globaldata->Groups.size() == 0) { - //is this sum from a sequence which is in one of the users groups - if (inUsersGroups(t->tree[v].getGroup(), tmap->namesOfGroups) == true) { - //is this sum from a sequence which is in this groupCombo - if ((t->tree[v].getGroup() == tmap->namesOfGroups[i-1]) || (t->tree[v].getGroup() == tmap->namesOfGroups[l])) { - sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()]; - D[count] += sum; - } - } - }else { - //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-1]) || (t->tree[v].getGroup() == globaldata->Groups[l])) { - sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()]; - D[count] += sum; - } + //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; } } } /*********************************************************/ count++; } - n++; } data.clear(); //clear out old values for(int i=0;igetNumNodes();i++){ //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC. - n = 1; - for (int b=1; bGroups.size() == 0) { - //does this node have descendants from group b-1 - it = t->tree[i].pcount.find(tmap->namesOfGroups[b-1]); - //if it does u = # of its descendants with a certain group / total number in tree with a certain group - if (it != t->tree[i].pcount.end()) { - u = (double) t->tree[i].pcount[tmap->namesOfGroups[b-1]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[b-1]]; - }else { u = 0.00; } + //does this node have descendants from group b-1 + it = t->tree[i].pcount.find(globaldata->Groups[b]); + //if it does u = # of its descendants with a certain group / total number in tree with a certain group + if (it != t->tree[i].pcount.end()) { + u = (double) t->tree[i].pcount[globaldata->Groups[b]] / (double) tmap->seqsPerGroup[globaldata->Groups[b]]; + }else { u = 0.00; } - //does this node have descendants from group l - it = t->tree[i].pcount.find(tmap->namesOfGroups[l]); - //if it does subtract their percentage from u - if (it != t->tree[i].pcount.end()) { - u -= (double) t->tree[i].pcount[tmap->namesOfGroups[l]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[l]]; - } - - u = abs(u) * t->tree[i].getBranchLength(); - - //save groupcombs u value - WScore[tmap->namesOfGroups[b-1]+tmap->namesOfGroups[l]] += u; - - //the user has entered specific groups - }else { - //does this node have descendants from group b-1 - it = t->tree[i].pcount.find(globaldata->Groups[b-1]); - //if it does u = # of its descendants with a certain group / total number in tree with a certain group - if (it != t->tree[i].pcount.end()) { - u = (double) t->tree[i].pcount[globaldata->Groups[b-1]] / (double) tmap->seqsPerGroup[globaldata->Groups[b-1]]; - }else { u = 0.00; } - - //does this node have descendants from group l - it = t->tree[i].pcount.find(globaldata->Groups[l]); - //if it does subtract their percentage from u - if (it != t->tree[i].pcount.end()) { - u -= (double) t->tree[i].pcount[globaldata->Groups[l]] / (double) tmap->seqsPerGroup[globaldata->Groups[l]]; - } + //does this node have descendants from group l + it = t->tree[i].pcount.find(globaldata->Groups[l]); + //if it does subtract their percentage from u + if (it != t->tree[i].pcount.end()) { + 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-1]+globaldata->Groups[l]] += u; - } + //save groupcombs u value + WScore[globaldata->Groups[b]+globaldata->Groups[l]] += u; /*********************************************************/ } - n++; } } //calculate weighted score for each group combination double UN; - n = 1; count = 0; - for (int i=1; iGroups.size() == 0) { - UN = (WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] / D[count]); - }else {//they have entered specific groups - UN = (WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] / D[count]); - } + for (int i=0; iGroups[i]+globaldata->Groups[l]] / D[count]); + if (isnan(UN) || isinf(UN)) { UN = 0; } data.push_back(UN); count++; } - n++; } return data; }