X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=weighted.cpp;h=7a31da4d55d398f47d022de7b80396bb44f6c6b4;hb=43ed0accfbc2852849e104ff7eccdd2c42acd4ec;hp=30e4a7682dc4ae4ad840fcdf2f7a31921fc8c351;hpb=5694c92fbf646fe01abc87bde2af59e14a9a56b6;p=mothur.git diff --git a/weighted.cpp b/weighted.cpp index 30e4a76..7a31da4 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -13,15 +13,13 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) { try { - globaldata = GlobalData::getInstance(); - data.clear(); //clear out old values int numGroups; vector D; processors = p; outputDir = o; - numGroups = globaldata->Groups.size(); + numGroups = m->getNumGroups(); if (m->control_pressed) { return data; } @@ -31,12 +29,12 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) { for (int l = 0; l < i; l++) { //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]); + vector groups; groups.push_back((m->getGroups())[i]); groups.push_back((m->getGroups())[l]); namesOfGroupCombos.push_back(groups); } } - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) if(processors == 1){ data = driver(t, namesOfGroupCombos, 0, namesOfGroupCombos.size()); }else{ @@ -71,7 +69,7 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) { EstOutput Weighted::createProcesses(Tree* t, vector< vector > namesOfGroupCombos) { try { -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; vector processIDS; @@ -141,7 +139,7 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector > namesOfGro m->gobble(in); } in.close(); - remove(s.c_str()); + m->mothurRemove(s); } m->mothurOut("DONE."); m->mothurOutEndLine(); m->mothurOutEndLine(); @@ -183,7 +181,7 @@ EstOutput Weighted::driver(Tree* t, vector< vector > namesOfGroupCombos, D[count] += weightedSum; } - + //adding the wieghted sums from group l for (int j = 0; j < t->groupNodeInfo[groupB].size(); j++) { //the leaf nodes that have seqs from group l map::iterator it = t->tree[t->groupNodeInfo[groupB][j]].pcount.find(groupB); @@ -194,15 +192,13 @@ EstOutput Weighted::driver(Tree* t, vector< vector > namesOfGroupCombos, D[count] += weightedSum; } - count++; } - + //calculate u for the group comb - for (int h = start; h < (start+num); h++) { //report progress - m->mothurOut("Processing combo: " + toString(h)); m->mothurOutEndLine(); + //m->mothurOut("Processing combo: " + toString(h)); m->mothurOutEndLine(); string groupA = namesOfGroupCombos[h][0]; string groupB = namesOfGroupCombos[h][1]; @@ -224,18 +220,28 @@ EstOutput Weighted::driver(Tree* t, vector< vector > namesOfGroupCombos, //does this node have descendants from group l it = t->tree[i].pcount.find(groupB); + //if it does subtract their percentage from u if (it != t->tree[i].pcount.end()) { u -= (double) t->tree[i].pcount[groupB] / (double) tmap->seqsPerGroup[groupB]; } - //if this is not the root then add it - if (rootForGrouping[namesOfGroupCombos[h]].count(i) == 0) { - u = abs(u * t->tree[i].getBranchLength()); - WScore[(groupA+groupB)] += u; + if (includeRoot) { + if (t->tree[i].getBranchLength() != -1) { + u = abs(u * t->tree[i].getBranchLength()); + WScore[(groupA+groupB)] += u; + } + }else { + //if this is not the root then add it + if (rootForGrouping[namesOfGroupCombos[h]].count(i) == 0) { + if (t->tree[i].getBranchLength() != -1) { + u = abs(u * t->tree[i].getBranchLength()); + WScore[(groupA+groupB)] += u; + } + } } - } + } /********************************************************/ @@ -244,7 +250,6 @@ EstOutput Weighted::driver(Tree* t, vector< vector > namesOfGroupCombos, count = 0; for (int h = start; h < (start+num); h++) { UN = (WScore[namesOfGroupCombos[h][0]+namesOfGroupCombos[h][1]] / D[count]); - if (isnan(UN) || isinf(UN)) { UN = 0; } results.push_back(UN); count++; @@ -260,7 +265,6 @@ EstOutput Weighted::driver(Tree* t, vector< vector > namesOfGroupCombos, /**************************************************************************************************/ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { try { - globaldata = GlobalData::getInstance(); data.clear(); //clear out old values @@ -317,14 +321,23 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { u -= (double) t->tree[i].pcount[groupB] / (double) tmap->seqsPerGroup[groupB]; } - //if this is not the root then add it - if (rootForGrouping[groups].count(i) == 0) { - u = abs(u * t->tree[i].getBranchLength()); - WScore[(groupA+groupB)] += u; + if (includeRoot) { + if (t->tree[i].getBranchLength() != -1) { + u = abs(u * t->tree[i].getBranchLength()); + WScore[(groupA+groupB)] += u; + } + }else{ + //if this is not the root then add it + if (rootForGrouping[groups].count(i) == 0) { + if (t->tree[i].getBranchLength() != -1) { + u = abs(u * t->tree[i].getBranchLength()); + WScore[(groupA+groupB)] += u; + } + } } } /********************************************************/ - + //calculate weighted score for the group combination double UN; UN = (WScore[(groupA+groupB)] / D); @@ -359,37 +372,43 @@ double Weighted::getLengthToRoot(Tree* t, int v, string groupA, string groupB) { while(t->tree[index].getParent() != -1){ if (m->control_pressed) { return sum; } - - //am I the root for this grouping? if so I want to stop "early" - //does my sibling have descendants from the users groups? - int parent = t->tree[index].getParent(); - int lc = t->tree[parent].getLChild(); - int rc = t->tree[parent].getRChild(); - int sib = lc; - if (lc == index) { sib = rc; } + int parent = t->tree[index].getParent(); - map::iterator itGroup; - int pcountSize = 0; - itGroup = t->tree[sib].pcount.find(groupA); - if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; } - itGroup = t->tree[sib].pcount.find(groupB); - if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; } - - //if yes, I am not the root so add me - if (pcountSize != 0) { - if (t->tree[index].getBranchLength() != -1) { - sum += abs(t->tree[index].getBranchLength()) + tempTotal; - tempTotal = 0.0; - }else { - sum += tempTotal; - tempTotal = 0.0; - } - rootForGrouping[grouping].clear(); - rootForGrouping[grouping].insert(parent); - }else { //if no, I may be the root so add my br to tempTotal until I am proven innocent - if (t->tree[index].getBranchLength() != -1) { - tempTotal += abs(t->tree[index].getBranchLength()); + if (includeRoot) { //add everyone + if(t->tree[index].getBranchLength() != -1){ sum += abs(t->tree[index].getBranchLength()); } + }else { + + //am I the root for this grouping? if so I want to stop "early" + //does my sibling have descendants from the users groups? + int lc = t->tree[parent].getLChild(); + int rc = t->tree[parent].getRChild(); + + int sib = lc; + if (lc == index) { sib = rc; } + + map::iterator itGroup; + int pcountSize = 0; + itGroup = t->tree[sib].pcount.find(groupA); + if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; } + itGroup = t->tree[sib].pcount.find(groupB); + if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; } + + //if yes, I am not the root so add me + if (pcountSize != 0) { + if (t->tree[index].getBranchLength() != -1) { + sum += abs(t->tree[index].getBranchLength()) + tempTotal; + tempTotal = 0.0; + }else { + sum += tempTotal; + tempTotal = 0.0; + } + rootForGrouping[grouping].clear(); + rootForGrouping[grouping].insert(parent); + }else { //if no, I may be the root so add my br to tempTotal until I am proven innocent + if (t->tree[index].getBranchLength() != -1) { + tempTotal += abs(t->tree[index].getBranchLength()); + } } } @@ -398,12 +417,12 @@ double Weighted::getLengthToRoot(Tree* t, int v, string groupA, string groupB) { //get all nodes above the root to add so we don't add their u values above index = *(rootForGrouping[grouping].begin()); + while(t->tree[index].getParent() != -1){ int parent = t->tree[index].getParent(); rootForGrouping[grouping].insert(parent); index = parent; } - return sum; } catch(exception& e) {