]> git.donarmstrong.com Git - mothur.git/blobdiff - libshuffcommand.cpp
moved utilities out of mothur.h and into mothurOut class.
[mothur.git] / libshuffcommand.cpp
index 93db3be8f6142875fdf158519005b994dd8ca2db..773d8d351211f3ab9794770e72aad77235754b53 100644 (file)
@@ -47,7 +47,7 @@ LibShuffCommand::LibShuffCommand(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->getPhylipFile()); //if user entered a file with a path then preserve it        
+                               outputDir += m->hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it     
                        }
                        
                        //make sure the user has already run the read.dist command
@@ -61,7 +61,7 @@ LibShuffCommand::LibShuffCommand(string option)  {
                        if (groups == "not found") { groups = ""; savegroups = groups; }
                        else { 
                                savegroups = groups;
-                               splitAtDash(groups, Groups);
+                               m->splitAtDash(groups, Groups);
                                globaldata->Groups = Groups;
                        }
                                
@@ -139,37 +139,53 @@ int LibShuffCommand::execute(){
        
                savedDXYValues = form->evaluateAll();
                savedMinValues = form->getSavedMins();
+               
+               if (m->control_pressed) {  delete form; globaldata->Groups.clear(); delete globaldata->gMatrix;  globaldata->gMatrix = NULL; return 0; }
        
                pValueCounts.resize(numGroups);
                for(int i=0;i<numGroups;i++){
                        pValueCounts[i].assign(numGroups, 0);
                }
-               
+       
+               if (m->control_pressed) {  delete form; globaldata->Groups.clear(); delete globaldata->gMatrix;  globaldata->gMatrix = NULL; return 0; }
+                               
                Progress* reading = new Progress();
                
                for(int i=0;i<numGroups-1;i++) {
                        for(int j=i+1;j<numGroups;j++) {
+                               
+                               if (m->control_pressed) {  delete form; globaldata->Groups.clear(); delete globaldata->gMatrix;  globaldata->gMatrix = NULL; delete reading; return 0; }
+
                                reading->newLine(groupNames[i]+'-'+groupNames[j], iters);
                                int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix
                                int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
        
-                               for(int p=0;p<iters;p++) {              
+                               for(int p=0;p<iters;p++) {      
+                                       
+                                       if (m->control_pressed) {  delete form; globaldata->Groups.clear(); delete globaldata->gMatrix;  globaldata->gMatrix = NULL; delete reading; return 0; }
+                                       
                                        form->randomizeGroups(spoti,spotj); 
                                        if(form->evaluatePair(spoti,spotj) >= savedDXYValues[spoti][spotj])     {       pValueCounts[i][j]++;   }
                                        if(form->evaluatePair(spotj,spoti) >= savedDXYValues[spotj][spoti])     {       pValueCounts[j][i]++;   }
+                                       
+                                       if (m->control_pressed) {  delete form; globaldata->Groups.clear(); delete globaldata->gMatrix;  globaldata->gMatrix = NULL; delete reading; return 0; }
+                                       
                                        reading->update(p);                     
                                }
                                form->resetGroup(spoti);
                                form->resetGroup(spotj);
                        }
                }
+               
+               if (m->control_pressed) {  delete form; globaldata->Groups.clear(); delete globaldata->gMatrix;  globaldata->gMatrix = NULL; delete reading; return 0; }
+       
                reading->finish();
                delete reading;
 
                m->mothurOutEndLine();
                printSummaryFile();
                printCoverageFile();
-               
+                               
                //clear out users groups
                globaldata->Groups.clear();
                delete form;
@@ -177,6 +193,9 @@ int LibShuffCommand::execute(){
                //delete globaldata's copy of the gmatrix to free up memory
                delete globaldata->gMatrix;  globaldata->gMatrix = NULL;
                
+               if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].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();    }
@@ -192,12 +211,12 @@ int LibShuffCommand::execute(){
 
 //**********************************************************************************************************************
 
-void LibShuffCommand::printCoverageFile() {
+int LibShuffCommand::printCoverageFile() {
        try {
 
                ofstream outCov;
-               summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage";
-               openOutputFile(summaryFile, outCov);
+               summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage";
+               m->openOutputFile(summaryFile, outCov);
                outputNames.push_back(summaryFile);
                outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint);
                //cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
@@ -218,6 +237,9 @@ void LibShuffCommand::printCoverageFile() {
                                int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
                                
                                for(int k=0;k<savedMinValues[spoti][spotj].size();k++){
+                                       
+                                       if(m->control_pressed)  { outCov.close(); return 0; }
+                                       
                                        if(allDistances[savedMinValues[spoti][spotj][k]].size() != 0){
                                                allDistances[savedMinValues[spoti][spotj][k]][indices[i][j]]++;
                                        }
@@ -251,6 +273,7 @@ void LibShuffCommand::printCoverageFile() {
                }
                for (int i=0;i<numGroups;i++){
                        for(int j=i+1;j<numGroups;j++){
+                               if(m->control_pressed)  { outCov.close(); return 0; }
                                outCov << '\t' << groupNames[i] << '-' << groupNames[j] << '\t';
                                outCov << groupNames[j] << '-' << groupNames[i];
                        }
@@ -264,6 +287,8 @@ void LibShuffCommand::printCoverageFile() {
                        }
                        for(int i=0;i<numGroups;i++){
                                for(int j=i+1;j<numGroups;j++){
+                                       if(m->control_pressed)  { outCov.close(); return 0; }
+                                       
                                        outCov << it->second[indices[i][j]]/(float)lastRow[indices[i][j]] << '\t';
                                        outCov << it->second[indices[j][i]]/(float)lastRow[indices[j][i]] << '\t';
                                }
@@ -271,6 +296,8 @@ void LibShuffCommand::printCoverageFile() {
                        outCov << endl;
                }
                outCov.close();
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "LibShuffCommand", "printCoverageFile");
@@ -280,12 +307,12 @@ void LibShuffCommand::printCoverageFile() {
 
 //**********************************************************************************************************************
 
-void LibShuffCommand::printSummaryFile() {
+int LibShuffCommand::printSummaryFile() {
        try {
 
                ofstream outSum;
-               summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary";
-               openOutputFile(summaryFile, outSum);
+               summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary";
+               m->openOutputFile(summaryFile, outSum);
                outputNames.push_back(summaryFile);
 
                outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint);
@@ -298,6 +325,8 @@ void LibShuffCommand::printSummaryFile() {
                int precision = (int)log10(iters);
                for(int i=0;i<numGroups;i++){
                        for(int j=i+1;j<numGroups;j++){
+                               if(m->control_pressed)  { outSum.close(); return 0; }
+                               
                                int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix
                                int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
                                
@@ -325,6 +354,7 @@ void LibShuffCommand::printSummaryFile() {
                }
                
                outSum.close();
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "LibShuffCommand", "printSummaryFile");