]> git.donarmstrong.com Git - mothur.git/blobdiff - summarysharedcommand.cpp
moved utilities out of mothur.h and into mothurOut class.
[mothur.git] / summarysharedcommand.cpp
index b6b4f522df0b1fc0eeb96d3851d8eda0419a35aa..cda2ef07da552d6ea4f25504e5b207a84d2594c7 100644 (file)
@@ -69,7 +69,7 @@ SummarySharedCommand::SummarySharedCommand(string option)  {
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
                                outputDir = ""; 
-                               outputDir += hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it        
+                               outputDir += m->hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it     
                        }
 
                        //check for optional parameter and set defaults
@@ -77,7 +77,7 @@ SummarySharedCommand::SummarySharedCommand(string option)  {
                        label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
-                               if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
+                               if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
@@ -92,17 +92,17 @@ SummarySharedCommand::SummarySharedCommand(string option)  {
                        else { 
                                 if (calc == "default")  {  calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        }
-                       splitAtDash(calc, Estimators);
+                       m->splitAtDash(calc, Estimators);
                        
                        groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
-                               splitAtDash(groups, Groups);
+                               m->splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                        
                        string temp = validParameter.validFile(parameters, "all", false);                               if (temp == "not found") { temp = "false"; }
-                       all = isTrue(temp);
+                       all = m->isTrue(temp);
                        
                        if (abort == false) {
                        
@@ -157,8 +157,8 @@ SummarySharedCommand::SummarySharedCommand(string option)  {
                                        }
                                }
                                
-                               outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "shared.summary";
-                               openOutputFile(outputFileName, outputFileHandle);
+                               outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "shared.summary";
+                               m->openOutputFile(outputFileName, outputFileHandle);
                                outputNames.push_back(outputFileName);
                                
                                mult = false;
@@ -239,8 +239,8 @@ int SummarySharedCommand::execute(){
                
                //create file and put column headers for multiple groups file
                if (mult == true) {
-                       outAllFileName = ((getRootName(globaldata->inputFileName)) + "sharedmultiple.summary");
-                       openOutputFile(outAllFileName, outAll);
+                       outAllFileName = ((m->getRootName(globaldata->inputFileName)) + "sharedmultiple.summary");
+                       m->openOutputFile(outAllFileName, outAll);
                        outputNames.push_back(outAllFileName);
                        
                        outAll << "label" <<'\t' << "comparison" << '\t'; 
@@ -267,13 +267,34 @@ int SummarySharedCommand::execute(){
                        remove(outAllFileName.c_str());
                        outputNames.pop_back();
                }
-                                       
+               
+               if (m->control_pressed) {
+                       if (mult) { outAll.close();  remove(outAllFileName.c_str());  }
+                       outputFileHandle.close(); remove(outputFileName.c_str()); 
+                       delete input; globaldata->ginput = NULL;
+                       for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+                       for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
+                       globaldata->Groups.clear(); 
+                       return 0;
+               }
+                                                               
+                                                                                                               
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
                set<string> processedLabels;
                set<string> userLabels = labels;
                        
                //as long as you are not at the end of the file or done wih the lines you want
                while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+                       if (m->control_pressed) {
+                               if (mult) { outAll.close();  remove(outAllFileName.c_str());  }
+                               outputFileHandle.close(); remove(outputFileName.c_str()); 
+                               delete input; globaldata->ginput = NULL;
+                               for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+                               for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
+                               globaldata->Groups.clear(); 
+                               return 0;
+                       }
+
                
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
                                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
@@ -283,7 +304,7 @@ int SummarySharedCommand::execute(){
                                userLabels.erase(lookup[0]->getLabel());
                        }
                        
-                       if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+                       if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
                                        string saveLabel = lookup[0]->getLabel();
                                        
                                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
@@ -307,6 +328,15 @@ int SummarySharedCommand::execute(){
                        lookup = input->getSharedRAbundVectors();
                }
                
+               if (m->control_pressed) {
+                       if (mult) { outAll.close();  remove(outAllFileName.c_str());  }
+                       outputFileHandle.close(); remove(outputFileName.c_str()); 
+                       delete input; globaldata->ginput = NULL;
+                       for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
+                       globaldata->Groups.clear(); 
+                       return 0;
+               }
+
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -330,7 +360,7 @@ int SummarySharedCommand::execute(){
                                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                }
                
-
+                               
                //reset groups parameter
                globaldata->Groups.clear();  
                
@@ -339,9 +369,14 @@ int SummarySharedCommand::execute(){
                if (mult == true) {  outAll.close();  }
                
                for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
-               
                delete input;  globaldata->ginput = NULL;
                
+               if (m->control_pressed) {
+                       remove(outAllFileName.c_str());  
+                       remove(outputFileName.c_str()); 
+                       return 0;
+               }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
@@ -356,7 +391,7 @@ int SummarySharedCommand::execute(){
 }
 
 /***********************************************************/
-void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
+int SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
        try {
                                //loop through calculators and add to file all for all calcs that can do mutiple groups
                                if (mult == true) {
@@ -374,6 +409,9 @@ void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                        for(int i=0;i<sumCalculators.size();i++){
                                                if (sumCalculators[i]->getMultiple() == true) { 
                                                        sumCalculators[i]->getValues(thisLookup);
+                                                       
+                                                       if (m->control_pressed) { return 1; }
+                                                       
                                                        outAll << '\t';
                                                        sumCalculators[i]->print(outAll);
                                                }
@@ -402,6 +440,9 @@ void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                for(int i=0;i<sumCalculators.size();i++) {
 
                                                        sumCalculators[i]->getValues(subset); //saves the calculator outputs
+                                                       
+                                                       if (m->control_pressed) { return 1; }
+                                                       
                                                        outputFileHandle << '\t';
                                                        sumCalculators[i]->print(outputFileHandle);
                                                }
@@ -409,7 +450,7 @@ void SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                        }
                                        n++;
                                }
-
+                       return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "SummarySharedCommand", "process");