]> git.donarmstrong.com Git - mothur.git/commitdiff
working on unifrac parallelization
authorwestcott <westcott>
Wed, 1 Sep 2010 13:05:31 +0000 (13:05 +0000)
committerwestcott <westcott>
Wed, 1 Sep 2010 13:05:31 +0000 (13:05 +0000)
unifracweightedcommand.cpp
validparameter.cpp
weighted.cpp

index ad012b542b82a99ad0ac40782688c325360268b0..5a2a5ec5c504796869b7f0392e6709e66eb62e9f 100644 (file)
@@ -192,22 +192,24 @@ int UnifracWeightedCommand::execute() {
                                
                                //get scores for random trees
                                for (int j = 0; j < iters; j++) {
-                                       int count = 0;
                                        
                                        #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                                                if(processors == 1){
                                                        driver(T[i], randT, namesOfGroupCombos, 0, namesOfGroupCombos.size(), sums, rScores);
                                                }else{
                                                        createProcesses(T[i], randT, namesOfGroupCombos, sums, rScores);
-                                                       for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
                                                }
                                        #else
                                                driver(T[i], randT, namesOfGroupCombos, 0, namesOfGroupCombos.size(), sums, rScores);
                                        #endif
                                        
                                        if (m->control_pressed) { delete output; outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str());  } return 0; }
+                                       
+                                       //report progress
+                                       m->mothurOut("Iter: " + toString(j+1)); m->mothurOutEndLine();          
                                }
-                               
+
+                               for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
                                
                                //find the signifigance of the score for summary file
                                for (int f = 0; f < numComp; f++) {
@@ -290,14 +292,12 @@ int UnifracWeightedCommand::createProcesses(Tree* t, Tree* randT, vector< vector
                                process++;
                        }else if (pid == 0){
                                driver(t, randT, namesOfGroupCombos, lines[process]->start, lines[process]->num, sums, scores);
-                               
-                               m->mothurOut("Merging results."); m->mothurOutEndLine();
-                               
+                       
                                //pass numSeqs to parent
                                ofstream out;
                                string tempFile = outputDir + toString(getpid()) + ".weightedcommand.results.temp";
                                m->openOutputFile(tempFile, out);
-                               for (int i = lines[process]->start; i < (lines[process]->start + lines[process]->num); i++) {  out << scores[i][0] << '\t';  } out << endl;
+                               for (int i = lines[process]->start; i < (lines[process]->start + lines[process]->num); i++) {  out << scores[i][(scores[i].size()-1)] << '\t';  } out << endl;
                                out.close();
                                
                                exit(0);
@@ -318,13 +318,12 @@ int UnifracWeightedCommand::createProcesses(Tree* t, Tree* randT, vector< vector
                        string s = outputDir + toString(processIDS[i]) + ".weightedcommand.results.temp";
                        m->openInputFile(s, in);
                        
-                       for (int i = lines[process]->start; i < (lines[process]->start + lines[process]->num); i++) { in >> scores[i][0]; }
+                       double tempScore;
+                       for (int i = lines[process]->start; i < (lines[process]->start + lines[process]->num); i++) { in >> tempScore; scores[i].push_back(tempScore); }
                        in.close();
                        remove(s.c_str());
                }
                
-               m->mothurOut("DONE."); m->mothurOutEndLine(); m->mothurOutEndLine();
-               
                return 0;
 #endif         
        }
@@ -337,12 +336,9 @@ int UnifracWeightedCommand::createProcesses(Tree* t, Tree* randT, vector< vector
 /**************************************************************************************************/
 int UnifracWeightedCommand::driver(Tree* t, Tree* randT, vector< vector<string> > namesOfGroupCombos, int start, int num, vector<double>& sums, vector< vector<double> >& scores) { 
  try {
-               int count = 0;
-               int total = num;
-               int twentyPercent = (total * 0.20);
-
+       
                for (int h = start; h < (start+num); h++) {
-               
+       cout << "doing " << h << endl;  
                        if (m->control_pressed) { return 0; }
                
                        //initialize weighted score
@@ -365,15 +361,8 @@ int UnifracWeightedCommand::driver(Tree* t, Tree* randT, vector< vector<string>
                                                                                
                        //save scores
                        scores[h].push_back(randomData[0]);
-                       
-                       count++;
-
-                       //report progress
-                       if((count) % twentyPercent == 0){       m->mothurOut("Random comparison percentage complete: " + toString(int((count / (float)total) * 100.0))); m->mothurOutEndLine();         }
                }
                
-               m->mothurOut("Random comparison percentage complete: 100"); m->mothurOutEndLine();
-               
                return 0;
 
        }
index 38a90940095b799634494a20ddf3d1688f2a0f3a..50cd4e316186847b350a13b465f6d032ed91fcb8 100644 (file)
@@ -309,7 +309,7 @@ void ValidParameters::initParameterRanges() {
                string precisionArray[] = {">=","10", "<","NA", "between"};
                parameterRanges["precision"] = addParameters(precisionArray, rangeSize);
                
-               string itersArray[] = {">=","10", "<","NA", "between"};
+               string itersArray[] = {">=","1", "<","NA", "between"};
                parameterRanges["iters"] = addParameters(itersArray, rangeSize);
 
                string abundArray[] = {">=","5", "<","NA", "between"};
index c9ad81295aaacb3bd4ae7eb8f7e8ca7c1cef9b80..5f58f2eee439d16a11d2a2b9fbbb86397794b729 100644 (file)
@@ -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); }
-                               
+                       
                                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();
@@ -108,13 +110,13 @@ EstOutput Weighted::createProcesses(Tree* t, vector< vector<string> > namesOfGro
                }
        
                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,11 @@ 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 +225,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;