]> git.donarmstrong.com Git - mothur.git/commitdiff
adding mothurout.h and .cpp to repo
authorwestcott <westcott>
Mon, 1 Mar 2010 11:59:21 +0000 (11:59 +0000)
committerwestcott <westcott>
Mon, 1 Mar 2010 11:59:21 +0000 (11:59 +0000)
15 files changed:
aligncommand.cpp
aligncommand.h
binsequencecommand.cpp
bootstrapsharedcommand.cpp
bootstrapsharedcommand.h
clustercommand.cpp
collect.cpp
collect.h
collectcommand.cpp
collectsharedcommand.cpp
engine.cpp
mothur.cpp
mothur.h
mothurout.cpp [new file with mode: 0644]
mothurout.h [new file with mode: 0644]

index 3b4b6c93e232a25bab87a855c6955d177926e823..94cba4a10e344f5e27593a4723adb662cb9ab458 100644 (file)
@@ -234,7 +234,13 @@ int AlignCommand::execute(){
                                
                                lines.push_back(new linePair(0, numFastaSeqs));
                                
-                               driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+                               int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+                               if (exitCommand == 0) { 
+                                       remove(accnosFileName.c_str()); 
+                                       remove(alignFileName.c_str()); 
+                                       remove(reportFileName.c_str()); 
+                                       return 0; 
+                               }
                                
                                //delete accnos file if its blank else report to user
                                if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
@@ -274,7 +280,7 @@ int AlignCommand::execute(){
                                        lines.push_back(new linePair(startPos, numSeqsPerProcessor));
                                }
                                
-                               createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
+                               int exitCommand = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
                                
                                rename((alignFileName + toString(processIDS[0]) + ".temp").c_str(), alignFileName.c_str());
                                rename((reportFileName + toString(processIDS[0]) + ".temp").c_str(), reportFileName.c_str());
@@ -310,6 +316,13 @@ int AlignCommand::execute(){
                                        }else{  m->mothurOut(" If the reverse compliment proved to be better it was reported.");  }
                                        m->mothurOutEndLine();
                                }else{ hasAccnos = false;  }
+                               
+                               if (exitCommand == 0) { 
+                                       remove(accnosFileName.c_str()); 
+                                       remove(alignFileName.c_str()); 
+                                       remove(reportFileName.c_str()); 
+                                       return 0; 
+                               }
                        }
 #else
                        ifstream inFASTA;
@@ -319,7 +332,13 @@ int AlignCommand::execute(){
                        
                        lines.push_back(new linePair(0, numFastaSeqs));
                        
-                       driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+                       int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+                       if (exitCommand == 0) { 
+                               remove(accnosFileName.c_str()); 
+                               remove(alignFileName.c_str()); 
+                               remove(reportFileName.c_str()); 
+                               return 0; 
+                       }
                        
                        //delete accnos file if its blank else report to user
                        if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
@@ -374,7 +393,9 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
                inFASTA.seekg(line->start);
                
                for(int i=0;i<line->numSeqs;i++){
-               
+                       
+                       if (m->control_pressed) {  return 0; }
+                       
                        Sequence* candidateSeq = new Sequence(inFASTA);  gobble(inFASTA);
                        int origNumBases = candidateSeq->getNumBases();
                        string originalUnaligned = candidateSeq->getUnaligned();
@@ -469,10 +490,11 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName,
 
 /**************************************************************************************************/
 
-void AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
+int AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
        try {
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                int process = 0;
+               int exitCommand;
                //              processIDS.resize(0);
                
                //loop through and create all the processes you want
@@ -483,7 +505,7 @@ void AlignCommand::createProcesses(string alignFileName, string reportFileName,
                                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){
-                               driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
+                               exitCommand = driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
                                exit(0);
                        }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
                }
@@ -493,6 +515,8 @@ void AlignCommand::createProcesses(string alignFileName, string reportFileName,
                        int temp = processIDS[i];
                        wait(&temp);
                }
+               
+               return exitCommand;
 #endif         
        }
        catch(exception& e) {
index 8042983911c1052e100133b4284f03ddce751031..f0496a54a9070b31dcb699a0deefc7cb51fc8a50 100644 (file)
@@ -37,7 +37,7 @@ private:
        Alignment* alignment;
        
        int driver(linePair*, string, string, string, string);
-       void createProcesses(string, string, string, string);
+       int createProcesses(string, string, string, string);
        void appendAlignFiles(string, string); 
        void appendReportFiles(string, string);
        
index 274a8901db3c8f17ad7e70519916c009e5613193..1601f32873ed6c8eefe41608ceda199a6fa5b5f5 100644 (file)
@@ -181,6 +181,7 @@ int BinSeqCommand::execute(){
                        readNamesFile();
                }
                
+               
                //read list file
                read = new ReadOTUFile(globaldata->getListFile());      
                read->read(&*globaldata); 
@@ -189,6 +190,8 @@ int BinSeqCommand::execute(){
                list = globaldata->gListVector;
                string lastLabel = list->getLabel();
                
+               if (m->control_pressed) {  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;
@@ -199,7 +202,7 @@ int BinSeqCommand::execute(){
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){
                                
                                error = process(list);  
-                               if (error == 1) { return 0; }   
+                               if (error == 1) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());         } return 0; }   
                                                        
                                processedLabels.insert(list->getLabel());
                                userLabels.erase(list->getLabel());
@@ -212,7 +215,7 @@ int BinSeqCommand::execute(){
                                list = input->getListVector(lastLabel);
                                
                                error = process(list);  
-                               if (error == 1) { return 0; }
+                               if (error == 1) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());         } return 0; }
                                                                                                        
                                processedLabels.insert(list->getLabel());
                                userLabels.erase(list->getLabel());
@@ -247,7 +250,7 @@ int BinSeqCommand::execute(){
                        list = input->getListVector(lastLabel);
                                
                        error = process(list);  
-                       if (error == 1) { return 0; }
+                       if (error == 1) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());         } return 0; }
                        
                        delete list;  
                }
@@ -315,7 +318,9 @@ int BinSeqCommand::process(ListVector* list) {
                                
                                //for each bin in the list vector
                                for (int i = 0; i < list->size(); i++) {
-
+                                       
+                                       if (m->control_pressed) {  return 1; }
+                                       
                                        binnames = list->get(i);
                                        while (binnames.find_first_of(',') != -1) { 
                                                name = binnames.substr(0,binnames.find_first_of(','));
@@ -333,7 +338,6 @@ int BinSeqCommand::process(ListVector* list) {
                                                                string group = groupMap->getGroup(name);
                                                                if (group == "not found") {  
                                                                        m->mothurOut(name + " is missing from your group file. Please correct. ");  m->mothurOutEndLine();
-                                                                       remove(outputFileName.c_str());
                                                                        return 1;
                                                                }else{
                                                                        name = name + "|" + group + "|" + toString(i+1);
@@ -343,7 +347,6 @@ int BinSeqCommand::process(ListVector* list) {
                                                        }
                                                }else { 
                                                        m->mothurOut(name + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine();
-                                                       remove(outputFileName.c_str());
                                                        return 1;
                                                }
                                                
@@ -361,7 +364,6 @@ int BinSeqCommand::process(ListVector* list) {
                                                        string group = groupMap->getGroup(binnames);
                                                        if (group == "not found") {  
                                                                m->mothurOut(binnames + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
-                                                               remove(outputFileName.c_str());
                                                                return 1;
                                                        }else{
                                                                binnames = binnames + "|" + group + "|" + toString(i+1);
@@ -371,7 +373,6 @@ int BinSeqCommand::process(ListVector* list) {
                                                }
                                        }else { 
                                                m->mothurOut(binnames + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine();
-                                               remove(outputFileName.c_str());
                                                return 1;
                                        }
                                }
index b44ce4b15d8f4121db33d12285616da1c8fde8f7..6b76918044201a7438413c0f695f83c141d5638f 100644 (file)
@@ -223,7 +223,8 @@ int BootSharedCommand::execute(){
                        if(allLines == 1 || labels.count(order->getLabel()) == 1){                      
                                
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
-                               process(order);
+                               int error = process(order);
+                               if (error == 1) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
                                
                                processedLabels.insert(order->getLabel());
                                userLabels.erase(order->getLabel());
@@ -236,7 +237,8 @@ int BootSharedCommand::execute(){
                                delete order;
                                order = input->getSharedOrderVector(lastLabel);                                                                                                 
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
-                               process(order);
+                               int error = process(order);
+                               if (error == 1) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
 
                                processedLabels.insert(order->getLabel());
                                userLabels.erase(order->getLabel());
@@ -271,7 +273,9 @@ int BootSharedCommand::execute(){
                                if (order != NULL) {    delete order;   }
                                order = input->getSharedOrderVector(lastLabel);                                                                                                 
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
-                               process(order);
+                               int error = process(order);
+                               if (error == 1) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
+                               
                                delete order;
 
                }
@@ -294,13 +298,15 @@ int BootSharedCommand::execute(){
 }
 //**********************************************************************************************************************
 
-void BootSharedCommand::createTree(ostream* out, Tree* t){
+int BootSharedCommand::createTree(ostream* out, Tree* t){
        try {
                
                //do merges and create tree structure by setting parents and children
                //there are numGroups - 1 merges to do
                for (int i = 0; i < (numGroups - 1); i++) {
                
+                       if (m->control_pressed) {  return 1; }
+               
                        float largest = -1000.0;
                        int row, column;
                        //find largest value in sims matrix by searching lower triangle
@@ -357,6 +363,8 @@ void BootSharedCommand::createTree(ostream* out, Tree* t){
        
                //print newick file
                t->print(*out);
+               
+               return 0;
        
        }
        catch(exception& e) {
@@ -382,7 +390,7 @@ void BootSharedCommand::printSims() {
        }
 }
 /***********************************************************/
-void BootSharedCommand::process(SharedOrderVector* order) {
+int BootSharedCommand::process(SharedOrderVector* order) {
        try{
                                EstOutput data;
                                vector<SharedRAbundVector*> subset;
@@ -400,18 +408,22 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                //create a file for each calculator with the 1000 trees in it.
                                for (int p = 0; p < iters; p++) {
                                        
+                                       if (m->control_pressed) {  return 1; }
+                                       
                                        util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order);  //fills group vectors from order vector.
 
                                
                                        //for each calculator                                                                                           
                                        for(int i = 0 ; i < treeCalculators.size(); i++) {
-                                       
+                                               
+                                               if (m->control_pressed) {  return 1; }
+                                               
                                                //initialize simMatrix
                                                simMatrix.clear();
                                                simMatrix.resize(numGroups);
-                                               for (int m = 0; m < simMatrix.size(); m++)      {
+                                               for (int o = 0; o < simMatrix.size(); o++)      {
                                                        for (int j = 0; j < simMatrix.size(); j++)      {
-                                                               simMatrix[m].push_back(0.0);
+                                                               simMatrix[o].push_back(0.0);
                                                        }
                                                }
                                
@@ -437,6 +449,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                                
                                                tempTree = new Tree();
                                                
+                                               if (m->control_pressed) {   delete tempTree; return 1; }
+                                               
                                                //creates tree from similarity matrix and write out file
                                                createTree(out[i], tempTree);
                                                
@@ -456,6 +470,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                        
                                        m->mothurOut("Generating consensus tree for " + treeCalculators[k]->getName()); m->mothurOutEndLine();
                                        
+                                       if (m->control_pressed) {  return 1; }
+                                       
                                        //set global data to calc trees
                                        globaldata->gTree = trees[k];
                                        
@@ -477,6 +493,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                        
                                //close ostream for each calc
                                for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); }
+                               
+                               return 0;
        
        }
        catch(exception& e) {
index aa0c3250aa07ac1d1b7b81e406a821a2f788c08b..be4a7648825ba541a253daa74817b120ed087f57 100644 (file)
@@ -32,9 +32,9 @@ public:
        void help();
        
 private:
-       void createTree(ostream*, Tree*);
+       int createTree(ostream*, Tree*);
        void printSims();
-       void process(SharedOrderVector*);
+       int process(SharedOrderVector*);
        
        
        GlobalData* globaldata;
index 5d9c7bccfbb250267553997fa3d6b16d7aa560b7..7484a621645c2449bfc9f158a391549f33da71dd 100644 (file)
@@ -154,6 +154,17 @@ int ClusterCommand::execute(){
                double saveCutoff = cutoff;
                
                while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){
+               
+                       if (m->control_pressed) { //clean up
+                               delete globaldata->gSparseMatrix;  globaldata->gSparseMatrix = NULL;
+                               delete globaldata->gListVector;  globaldata->gListVector = NULL;
+                               if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); }
+                               else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); }
+                               sabundFile.close();rabundFile.close();listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                               return 0;
+                       }
+               
                        if (print_start && isTrue(timing)) {
                                m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" 
                                        + toString(roundDist(matrix->getSmallDist(), precision)) 
index 08426a8499bdf41c0fab815f20421d4bc070de0f..62ed9f24a929bab17a0733c98b5771105a395c3f 100644 (file)
@@ -11,7 +11,7 @@
 
 /***********************************************************************/
 
-void Collect::getCurve(int increment = 1){
+int Collect::getCurve(int increment = 1){
         try {
                 RAbundVector* lookup = new RAbundVector(order->getNumBins());
                 SAbundVector* rank        = new SAbundVector(order->getMaxRank()+1);
@@ -23,7 +23,9 @@ void Collect::getCurve(int increment = 1){
                         displays[i]->init(label);                   //sets displays label
                 }                                                                           
                 for(int i=0;i<numSeqs;i++){
-
+                                               
+                                               if (m->control_pressed) { delete lookup; delete rank; delete ccd;  return 1;  }
+                                               
                         int binNumber = order->get(i);
                         int abundance = lookup->get(binNumber);
                 
@@ -50,6 +52,8 @@ void Collect::getCurve(int increment = 1){
                                delete lookup;
                                delete rank;
                                delete ccd;
+                               
+                               return 0;
         }
         catch(exception& e) {
                        m->errorOut(e, "Collect", "getCurve");
@@ -58,7 +62,7 @@ void Collect::getCurve(int increment = 1){
 }
 
 /***********************************************************************/
-void Collect::getSharedCurve(int increment = 1){
+int Collect::getSharedCurve(int increment = 1){
 try {
                 globaldata = GlobalData::getInstance();
                 vector<SharedRAbundVector*> lookup; 
@@ -94,6 +98,9 @@ try {
                 
                 //sample all the members
                 for(int i=0;i<numSeqs;i++){
+                               
+                                               if (m->control_pressed) { for (int j = 0; j < lookup.size(); j++) {  delete lookup[j]; } delete ccd;  return 1;  }
+                                               
                         //get first sample
                         individual chosen = sharedorder->get(i);
                         int abundance; 
@@ -155,6 +162,8 @@ try {
                                for (int i = 0; i < lookup.size(); i++) {
                                        delete lookup[i];
                                }
+                               
+                               return 0;
 
         }
         catch(exception& e) {
index 0db15045024f2ea8c30d4c316d539f564df690cf..879755f5744e456e37aefb5f302ec9483a9393e9 100644 (file)
--- a/collect.h
+++ b/collect.h
@@ -22,8 +22,8 @@ public:
                                        numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel())  { m = MothurOut::getInstance(); }
 
        ~Collect(){             };
-       void getCurve(int);
-       void getSharedCurve(int);
+       int getCurve(int);
+       int getSharedCurve(int);
        
 private:
        SharedOrderVector* sharedorder;
index d8da50e0d2f559f25657008d046e7ec6951c4552..9bf2c9a88c49f49f27d8a641aabc4d9f8d2ab3fe 100644 (file)
@@ -140,7 +140,9 @@ int CollectCommand::execute(){
                else {  inputFileNames = parseSharedFile(globaldata->getSharedFile());  globaldata->setFormat("rabund");  }
        
                for (int p = 0; p < inputFileNames.size(); p++) {
-               
+                       
+                       if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());         }  globaldata->Groups.clear(); return 0; }
+                       
                        if (outputDir == "") { outputDir += hasPath(inputFileNames[p]); }
                        string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
                        globaldata->inputFileName = inputFileNames[p];
@@ -230,15 +232,38 @@ int CollectCommand::execute(){
                        //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;
+                       
+                       if (m->control_pressed) {  
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                               delete input;  globaldata->ginput = NULL;
+                               delete read;
+                               delete order; globaldata->gorder = NULL;
+                               delete validCalculator;
+                               globaldata->Groups.clear();
+                               return 0;
+                       }
+
 
                        while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                                
                                if(allLines == 1 || labels.count(order->getLabel()) == 1){
                                        
                                        cCurve = new Collect(order, cDisplays);
-                                       cCurve->getCurve(freq);
+                                       int error = cCurve->getCurve(freq);
                                        delete cCurve;
                                        
+                                       if (error == 1) {
+                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                                               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                               delete input;  globaldata->ginput = NULL;
+                                               delete read;
+                                               delete order; globaldata->gorder = NULL;
+                                               delete validCalculator;
+                                               globaldata->Groups.clear();
+                                               return 0;
+                                       }
+                                       
                                        m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        processedLabels.insert(order->getLabel());
                                        userLabels.erase(order->getLabel());
@@ -253,9 +278,20 @@ int CollectCommand::execute(){
                                        order = (input->getOrderVector(lastLabel));
                                        
                                        cCurve = new Collect(order, cDisplays);
-                                       cCurve->getCurve(freq);
+                                       int error = cCurve->getCurve(freq);
                                        delete cCurve;
                                        
+                                       if (error == 1) {
+                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                                               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                               delete input;  globaldata->ginput = NULL;
+                                               delete read;
+                                               delete order; globaldata->gorder = NULL;
+                                               delete validCalculator;
+                                               globaldata->Groups.clear();
+                                               return 0;
+                                       }
+                                       
                                        m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        processedLabels.insert(order->getLabel());
                                        userLabels.erase(order->getLabel());
@@ -291,8 +327,19 @@ int CollectCommand::execute(){
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                
                                cCurve = new Collect(order, cDisplays);
-                               cCurve->getCurve(freq);
+                               int error = cCurve->getCurve(freq);
                                delete cCurve;
+                               
+                               if (error == 1) {
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                                       for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                       delete input;  globaldata->ginput = NULL;
+                                       delete read;
+                                       delete order; globaldata->gorder = NULL;
+                                       delete validCalculator;
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
                                delete order;
                        }
                        
index 0c937f62c83a5a1b1cac914c1a2e01b356dddc03..201709ea83ff099f9afe97b2e3af69bdb4fbe1ce 100644 (file)
@@ -266,8 +266,19 @@ int CollectSharedCommand::execute(){
                                
                                //create collectors curve
                                cCurve = new Collect(order, cDisplays);
-                               cCurve->getSharedCurve(freq);
+                               int error = cCurve->getSharedCurve(freq);
                                delete cCurve;
+                               
+                               if (error == 1) {
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                                       for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                       delete input;  globaldata->ginput = NULL;
+                                       delete read;
+                                       delete order; globaldata->gorder = NULL;
+                                       delete validCalculator;
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
                        
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                processedLabels.insert(order->getLabel());
@@ -283,8 +294,20 @@ int CollectSharedCommand::execute(){
                                
                                //create collectors curve
                                cCurve = new Collect(order, cDisplays);
-                               cCurve->getSharedCurve(freq);
+                               int error = cCurve->getSharedCurve(freq);
                                delete cCurve;
+                               
+                               if (error == 1) {
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                                       for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                       delete input;  globaldata->ginput = NULL;
+                                       delete read;
+                                       delete order; globaldata->gorder = NULL;
+                                       delete validCalculator;
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
+
                        
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                processedLabels.insert(order->getLabel());
@@ -321,9 +344,21 @@ int CollectSharedCommand::execute(){
                        order = input->getSharedOrderVector(lastLabel);
 
                        cCurve = new Collect(order, cDisplays);
-                       cCurve->getSharedCurve(freq);
+                       int error = cCurve->getSharedCurve(freq);
                        delete cCurve;
                        
+                       if (error == 1) {
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                               for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                               delete input;  globaldata->ginput = NULL;
+                               delete read;
+                               delete order; globaldata->gorder = NULL;
+                               delete validCalculator;
+                               globaldata->Groups.clear();
+                               return 0;
+                       }
+
+                       
                        m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                        delete order;
                }
index fdd017ab34c7a083b3f09bc270498155b3cb3766..5e9ac5f36372a5bdbd4da64d1a87d3bac57b5954 100644 (file)
@@ -69,6 +69,7 @@ bool InteractEngine::getInput(){
                                //executes valid command
                                Command* command = cFactory->getCommand(commandName, options);
                                quitCommandCalled = command->execute();
+                               mout->control_pressed = 0;
                                
                        }else {
                                mout->mothurOut("Your input contains errors. Please try again."); 
@@ -183,6 +184,7 @@ bool BatchEngine::getInput(){
                                        //executes valid command
                                        Command* command = cFactory->getCommand(commandName, options);
                                        quitCommandCalled = command->execute();
+                                       mout->control_pressed = 0;
                                }else {         
                                        mout->mothurOut("Invalid."); 
                                        mout->mothurOutEndLine();
@@ -262,6 +264,7 @@ bool ScriptEngine::getInput(){
                                //executes valid command
                                Command* command = cFactory->getCommand(commandName, options);
                                quitCommandCalled = command->execute();
+                               mout->control_pressed = 0;
                        }else {         
                                mout->mothurOut("Invalid."); 
                                mout->mothurOutEndLine();
index ba058ba3fde6d2dd2d25458f88be358f1c7c0408..7cd77a1c2fd8fec087e740a7340f4a74c19ea801 100644 (file)
@@ -18,13 +18,20 @@ GlobalData* GlobalData::_uniqueInstance = 0;
 CommandFactory* CommandFactory::_uniqueInstance = 0;
 MothurOut* MothurOut::_uniqueInstance = 0;
 
+/***********************************************************************/
+volatile int ctrlc_pressed = 0;
+void ctrlc_handler ( int sig ) {
+       MothurOut* m = MothurOut::getInstance();
+    ctrlc_pressed = 1;
+       m->control_pressed = ctrlc_pressed;
+}
+/***********************************************************************/
 int main(int argc, char *argv[]){
        MothurOut* m = MothurOut::getInstance();
        try {
                
-               //string log = "mothur.logFile";
-               //remove(log.c_str());
-               
+               signal(SIGINT, ctrlc_handler );
+                               
                time_t ltime = time(NULL); /* calendar time */  
                string logFileName = "mothur." + toString(ltime) + ".logfile";
                
index db11ed17238ac25f9fc2979431afbb0bdcbb8ec3..26fd77508c4ce7aa4e647f4382a9259ba977d3b9 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -193,7 +193,6 @@ string toString(const T&x, int i){
     return output.str();
 }
 /***********************************************************************/
-
 inline int openOutputFileAppend(string fileName, ofstream& fileHandle){
        
        fileHandle.open(fileName.c_str(), ios::app);
diff --git a/mothurout.cpp b/mothurout.cpp
new file mode 100644 (file)
index 0000000..0f4faed
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *  m->mothurOut.cpp
+ *  Mothur
+ *
+ *  Created by westcott on 2/25/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "mothurout.h"
+
+/******************************************************/
+MothurOut* MothurOut::getInstance() {
+       if( _uniqueInstance == 0) {
+               _uniqueInstance = new MothurOut();
+       }
+       return _uniqueInstance;
+}
+/*********************************************************************************************/
+void MothurOut::setFileName(string filename)  {
+       try {
+               logFileName = filename;
+               openOutputFile(filename, out);
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "setFileName");
+               exit(1);
+       }
+}
+/*********************************************************************************************/
+MothurOut::~MothurOut() {
+       try {
+               _uniqueInstance = 0;
+               out.close();
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "MothurOut");
+               exit(1);
+       }
+}
+
+/*********************************************************************************************/
+void MothurOut::mothurOut(string output) {
+       try {
+       
+               cout << output;
+               out << output;
+               
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "MothurOut");
+               exit(1);
+       }
+}
+/*********************************************************************************************/
+void MothurOut::mothurOutEndLine() {
+       try {
+               cout << endl;
+               out << endl;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "MothurOutEndLine");
+               exit(1);
+       }
+}
+/*********************************************************************************************/
+void MothurOut::mothurOutJustToLog(string output) {
+       try {
+               out << output;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "MothurOutJustToLog");
+               exit(1);
+       }
+}
+/*********************************************************************************************/
+void MothurOut::errorOut(exception& e, string object, string function) {
+       mothurOut("Error: ");
+       mothurOut(toString(e.what()));
+       mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");
+       mothurOutEndLine();
+}
+/*********************************************************************************************/
+
+
+
+
+
diff --git a/mothurout.h b/mothurout.h
new file mode 100644 (file)
index 0000000..ac1ec3f
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef MOTHUROUT_H
+#define MOTHUROUT_H
+
+/*
+ *  m->mothurOut.h
+ *  Mothur
+ *
+ *  Created by westcott on 2/25/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+
+/***********************************************/
+
+class MothurOut {
+       
+       public:
+               static MothurOut* getInstance();
+               void setFileName(string);
+               
+               void mothurOut(string);
+               void mothurOutEndLine();
+               void mothurOutJustToLog(string);
+               void errorOut(exception&, string, string);
+               int control_pressed;
+               
+
+       private:
+               static MothurOut* _uniqueInstance;
+               MothurOut( const MothurOut& ); // Disable copy constructor
+               void operator=( const MothurOut& ); // Disable assignment operator
+               MothurOut() {};
+               ~MothurOut();
+
+               string logFileName;
+               ofstream out;
+
+};
+/***********************************************/
+
+#endif
+