]> git.donarmstrong.com Git - mothur.git/blobdiff - weighted.cpp
testing 1.13.0
[mothur.git] / weighted.cpp
index c9ad81295aaacb3bd4ae7eb8f7e8ca7c1cef9b80..fd7f8541494e78ade54e78f6832e7f4eab20ea2e 100644 (file)
@@ -51,12 +51,12 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) {
                                        if(i == processors - 1){
                                                numPairsPerProcessor = numPairs - i * numPairsPerProcessor;
                                        }
-                                       lines.push_back(new linePair(startPos, numPairsPerProcessor));
+                                       lines.push_back(linePair(startPos, numPairsPerProcessor));
                                }
 
                                data = createProcesses(t, namesOfGroupCombos, sums);
                                
-                               for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
+                               lines.clear();
                        }
                #else
                        data = driver(t, namesOfGroupCombos, 0, namesOfGroupCombos.size(), sums);
@@ -88,17 +88,19 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector<string> > namesOfGro
                                processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
                                process++;
                        }else if (pid == 0){
+       
                                EstOutput Myresults;
-                               Myresults = driver(t, namesOfGroupCombos, lines[process]->start, lines[process]->num, sums);
-                               
-                               if (m->control_pressed) { exit(0); }
-                               
+                               Myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, sums);
+                       
                                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();
@@ -107,14 +109,14 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector<string> > namesOfGro
                        }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
                }
        
-               results = driver(t, namesOfGroupCombos, lines[0]->start, lines[0]->num, sums);
-               
+               results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, sums);
+       
                //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
@@ -154,15 +156,10 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector<string> > namesOfGro
 /**************************************************************************************************/
 EstOutput Weighted::driver(Tree* t, vector< vector<string> > namesOfGroupCombos, int start, int num, vector<double>& sums) { 
  try {
-               globaldata = GlobalData::getInstance();
-               
                EstOutput results;
                vector<double> D;
                
                int count = 0;
-               int total = num;
-               int twentyPercent = (total * 0.20);
-
                for (int h = start; h < (start+num); h++) {
                
                        if (m->control_pressed) { return results; }
@@ -194,14 +191,12 @@ EstOutput Weighted::driver(Tree* t, vector< vector<string> > namesOfGroupCombos,
                                D[count] += weightedSum;
                        }
                        count++;
-                       
-                       //report progress
-                       if((count) % twentyPercent == 0){       m->mothurOut("Percentage complete: " + toString(int((count / (float)total) * 100.0))); m->mothurOutEndLine();           }
                }
                
-               m->mothurOut("Percentage complete: 100"); m->mothurOutEndLine();
-               
                //calculate u for the group comb 
+               int total = t->getNumNodes();
+               int twentyPercent = (total * 0.20);
+               
                for(int i=0;i<t->getNumNodes();i++){
                        for (int h = start; h < (start+num); h++) {
                                
@@ -231,10 +226,13 @@ EstOutput Weighted::driver(Tree* t, vector< vector<string> > namesOfGroupCombos,
                                //save groupcombs u value
                                WScore[(groupA+groupB)] += u;
                        }
+                       //report progress
+                       if((i) % twentyPercent == 0){   m->mothurOut("Percentage complete: " + toString(int((i / (float)total) * 100.0))); m->mothurOutEndLine();               }
                }
                
-               /********************************************************/
+               m->mothurOut("Percentage complete: 100"); m->mothurOutEndLine();
                
+               /********************************************************/
                //calculate weighted score for the group combination
                double UN;      
                count = 0;