X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=unweighted.cpp;h=fb2f0b22afa3cc2143ad95afe6c45e4e093db222;hb=5334a314651228c55fd0f206dec0209bc3148b24;hp=8103688fb04d34542ee2174728d3399055a5d452;hpb=4745a956b3116a719f52f341d2a2db84df4817da;p=mothur.git diff --git a/unweighted.cpp b/unweighted.cpp index 8103688..fb2f0b2 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -66,7 +66,6 @@ EstOutput Unweighted::getValues(Tree* t, int p, string o) { lines.push_back(linePair(startPos, numPairsPerProcessor)); } - data = createProcesses(t, namesOfGroupCombos); lines.clear(); } @@ -87,7 +86,6 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector > namesOfG try { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) int process = 1; - int num = 0; vector processIDS; EstOutput results; @@ -116,7 +114,11 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector > namesOfG out.close(); exit(0); - }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } } results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num); @@ -170,17 +172,22 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo EstOutput results; results.resize(num); int count = 0; + int numLeaves = t->getNumLeaves(); int total = num; int twentyPercent = (total * 0.20); if (twentyPercent == 0) { twentyPercent = 1; } - for (int h = start; h < (start+num); h++) { + for (int h = start; h < (start+num); h++) { + //cout << namesOfGroupCombos[h][0] << '\t' << namesOfGroupCombos[h][1] << endl; if (m->control_pressed) { return results; } double UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group double totalBL = 0.00; //all branch lengths double UW = 0.00; //Unweighted Value = UniqueBL / totalBL; + map tempTotals; //maps node to total Branch Length + map nodePcountSize; //maps node to pcountSize + map::iterator itCount; for(int i=0;igetNumNodes();i++){ @@ -195,15 +202,47 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo map::iterator itGroup = t->tree[i].pcount.find(namesOfGroupCombos[h][j]); if (itGroup != t->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } } } + + nodePcountSize[i] = pcountSize; + //cout << i << '\t' << t->tree[i].getName() << " br = " << abs(t->tree[i].getBranchLength()) << '\t'; if (pcountSize == 0) { } - else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); } + else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); } + + //if you are a leaf from a users group add to total + if (i < numLeaves) { + if ((t->tree[i].getBranchLength() != -1) && pcountSize != 0) { + //cout << "added to total" << endl; + totalBL += abs(t->tree[i].getBranchLength()); + } + tempTotals[i] = 0.0; //we don't care about you, or we have already added you + }else{ //if you are not a leaf + //do both your chidren have have descendants from the users groups? + int lc = t->tree[i].getLChild(); + int rc = t->tree[i].getRChild(); - if ((t->tree[i].getBranchLength() != -1) && (pcountSize != 0)) { - totalBL += abs(t->tree[i].getBranchLength()); + //if yes, add your childrens tempTotals + if ((nodePcountSize[lc] != 0) && (nodePcountSize[rc] != 0)) { + totalBL += tempTotals[lc] + tempTotals[rc]; + //cout << "added to total " << tempTotals[lc] << '\t' << tempTotals[rc] << endl; + if (t->tree[i].getBranchLength() != -1) { + tempTotals[i] = abs(t->tree[i].getBranchLength()); + }else { + tempTotals[i] = 0.0; + } + }else if ((nodePcountSize[lc] == 0) && (nodePcountSize[rc] == 0)) { tempTotals[i] = 0.0; //we don't care about you + }else { //if no, your tempTotal is your childrens temp totals + your branch length + if (t->tree[i].getBranchLength() != -1) { + tempTotals[i] = tempTotals[lc] + tempTotals[rc] + abs(t->tree[i].getBranchLength()); + }else { + tempTotals[i] = tempTotals[lc] + tempTotals[rc]; + } + } + //cout << "temptotal = "<< tempTotals[i] << endl; } + } - + //cout << UniqueBL << '\t' << totalBL << endl; UW = (UniqueBL / totalBL); if (isnan(UW) || isinf(UW)) { UW = 0; } @@ -281,7 +320,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB, int p, st } lines.push_back(linePair(startPos, numPairsPerProcessor)); } - + data = createProcesses(t, namesOfGroupCombos, true); lines.clear(); @@ -303,7 +342,6 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector > namesOfG try { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) int process = 1; - int num = 0; vector processIDS; EstOutput results; @@ -330,7 +368,11 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector > namesOfG out.close(); exit(0); - }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } } results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, usingGroups); @@ -353,12 +395,13 @@ EstOutput Unweighted::createProcesses(Tree* t, vector< vector > namesOfG if (!in.eof()) { int num; in >> num; m->gobble(in); - + if (m->control_pressed) { break; } double w; for (int j = 0; j < num; j++) { in >> w; + results.push_back(w); } m->gobble(in); @@ -382,8 +425,7 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo EstOutput results; results.resize(num); int count = 0; - int total = num; - int twentyPercent = (total * 0.20); + int numLeaves = t->getNumLeaves(); Tree* copyTree = new Tree; @@ -400,8 +442,10 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo double UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group double totalBL = 0.00; //all branch lengths double UW = 0.00; //Unweighted Value = UniqueBL / totalBL; + map tempTotals; //maps node to total Branch Length + map nodePcountSize; //maps node to pcountSize - for(int i=0;igetNumNodes();i++){ + for(int i=0;igetNumNodes();i++){ if (m->control_pressed) { return data; } @@ -411,16 +455,46 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo int pcountSize = 0; for (int j = 0; j < namesOfGroupCombos[h].size(); j++) { - map::iterator itGroup = t->tree[i].pcount.find(namesOfGroupCombos[h][j]); - if (itGroup != t->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } } + map::iterator itGroup = copyTree->tree[i].pcount.find(namesOfGroupCombos[h][j]); + if (itGroup != copyTree->tree[i].pcount.end()) { pcountSize++; if (pcountSize > 1) { break; } } } + nodePcountSize[i] = pcountSize; + if (pcountSize == 0) { } - else if ((t->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(t->tree[i].getBranchLength()); } + else if ((copyTree->tree[i].getBranchLength() != -1) && (pcountSize == 1)) { UniqueBL += abs(copyTree->tree[i].getBranchLength()); } + + //if you are a leaf from a users group add to total + if (i < numLeaves) { + if ((copyTree->tree[i].getBranchLength() != -1) && pcountSize != 0) { + totalBL += abs(copyTree->tree[i].getBranchLength()); + } + tempTotals[i] = 0.0; //we don't care about you, or we have already added you + }else{ //if you are not a leaf + //do both your chidren have have descendants from the users groups? + int lc = copyTree->tree[i].getLChild(); + int rc = copyTree->tree[i].getRChild(); + + //if yes, add your childrens tempTotals + if ((nodePcountSize[lc] != 0) && (nodePcountSize[rc] != 0)) { + totalBL += tempTotals[lc] + tempTotals[rc]; + + if (copyTree->tree[i].getBranchLength() != -1) { + tempTotals[i] = abs(copyTree->tree[i].getBranchLength()); + }else { + tempTotals[i] = 0.0; + } + }else if ((nodePcountSize[lc] == 0) && (nodePcountSize[rc] == 0)) { tempTotals[i] = 0.0; //we don't care about you + }else { //if no, your tempTotal is your childrens temp totals + your branch length + if (t->tree[i].getBranchLength() != -1) { + tempTotals[i] = tempTotals[lc] + tempTotals[rc] + abs(copyTree->tree[i].getBranchLength()); + }else { + tempTotals[i] = tempTotals[lc] + tempTotals[rc]; + } + } - if ((t->tree[i].getBranchLength() != -1) && (pcountSize != 0)) { - totalBL += abs(t->tree[i].getBranchLength()); } + } UW = (UniqueBL / totalBL);