- for(int i=0;i<t->getNumNodes();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; b<numGroups; b++) {
- for (int l = n; l < numGroups; l++) {
-
- /********************************************************/
- //calculate a D value for each group combo
- for(int v=0;v<t->getNumLeaves();v++){
- int index = v;
- double sum = 0.0000;
-
- //while you aren't at root
- while(t->tree[index].getParent() != -1){
-
- //if you have a BL
- if(t->tree[index].getBranchLength() != -1){
- sum += 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();
- }
+ EstOutput Myresults;
+ Myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct);
+
+ //m->mothurOut("Merging results."); m->mothurOutEndLine();
+
+ //pass numSeqs to parent
+ ofstream out;
+
+ string tempFile = outputDir + toString(getpid()) + ".weighted.results.temp";
+
+ m->openOutputFile(tempFile, out);
+
+ out << Myresults.size() << endl;
+ for (int i = 0; i < Myresults.size(); i++) { out << Myresults[i] << '\t'; } out << endl;
+ out.close();
+
+ 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, ct);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<(processors-1);i++) {
+ int temp = processIDS[i];
+ wait(&temp);
+ }
+
+ if (m->control_pressed) { return results; }
+
+ //get data created by processes
+ for (int i=0;i<(processors-1);i++) {
+ ifstream in;
+ string s = outputDir + toString(processIDS[i]) + ".weighted.results.temp";
+ m->openInputFile(s, in);
+
+ //get quantiles
+ while (!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);
+ }
+ in.close();
+ m->mothurRemove(s);
+ }
+
+ //m->mothurOut("DONE."); m->mothurOutEndLine(); m->mothurOutEndLine();
+
+ return results;
+#endif
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Weighted", "createProcesses");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+EstOutput Weighted::driver(Tree* t, vector< vector<string> > namesOfGroupCombos, int start, int num, CountTable* ct) {
+ try {
+ EstOutput results;
+ vector<double> D;
+
+ int count = 0;
+ for (int h = start; h < (start+num); h++) {
+
+ if (m->control_pressed) { return results; }
+
+ //initialize weighted score
+ string groupA = namesOfGroupCombos[h][0];
+ string groupB = namesOfGroupCombos[h][1];
+
+ set<int> validBranches;
+ WScore[groupA+groupB] = 0.0;
+ D.push_back(0.0000); //initialize a spot in D for each combination
+
+ //adding the wieghted sums from group i
+ for (int j = 0; j < t->groupNodeInfo[groupA].size(); j++) { //the leaf nodes that have seqs from group i
+ map<string, int>::iterator it = t->tree[t->groupNodeInfo[groupA][j]].pcount.find(groupA);
+ int numSeqsInGroupI = it->second;
+
+ double sum = getLengthToRoot(t, t->groupNodeInfo[groupA][j], groupA, groupB);
+ double weightedSum = ((numSeqsInGroupI * sum) / (double)ct->getGroupCount(groupA));
+
+ 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<string, int>::iterator it = t->tree[t->groupNodeInfo[groupB][j]].pcount.find(groupB);
+ int numSeqsInGroupL = it->second;
+
+ double sum = getLengthToRoot(t, t->groupNodeInfo[groupB][j], groupA, groupB);
+ double weightedSum = ((numSeqsInGroupL * sum) / (double)ct->getGroupCount(groupB));
+
+ 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();