]> git.donarmstrong.com Git - mothur.git/commitdiff
added checks for ^C to quit command instead of program
authorwestcott <westcott>
Wed, 3 Mar 2010 12:33:53 +0000 (12:33 +0000)
committerwestcott <westcott>
Wed, 3 Mar 2010 12:33:53 +0000 (12:33 +0000)
125 files changed:
aligncommand.cpp
alignmentdb.cpp
bayesian.cpp
bellerophon.cpp
bellerophon.h
binsequencecommand.cpp
bootstrapsharedcommand.cpp
ccode.cpp
ccode.h
chimera.cpp
chimera.h
chimeracheckrdp.cpp
chimeracheckrdp.h
chimeraseqscommand.cpp
chimeraseqscommand.h
chimeraslayer.cpp
chimeraslayer.h
classifyseqscommand.cpp
collectcommand.cpp
collectsharedcommand.cpp
consensuscommand.cpp
consensuscommand.h
decalc.cpp
deconvolutecommand.cpp
distancecommand.cpp
distancecommand.h
dlibshuff.cpp
engine.cpp
fastamap.cpp
filterseqscommand.cpp
formatcolumn.cpp
formatcolumn.h
formatmatrix.h
formatphylip.cpp
formatphylip.h
fullmatrix.cpp
fullmatrix.h
getgroupcommand.cpp
getlabelcommand.cpp
getlistcountcommand.cpp
getoturepcommand.cpp
getrabundcommand.cpp
getsabundcommand.cpp
getseqscommand.cpp
getseqscommand.h
getsharedotucommand.cpp
getsharedotucommand.h
groupmap.cpp
hcluster.cpp
hcluster.h
hclustercommand.cpp
heatmap.cpp
heatmapcommand.cpp
heatmapsim.cpp
heatmapsimcommand.cpp
knn.cpp
libshuffcommand.cpp
libshuffcommand.h
listseqscommand.cpp
listseqscommand.h
maligner.cpp
matrixoutputcommand.cpp
matrixoutputcommand.h
mergefilecommand.cpp
mgclustercommand.cpp
mothur.cpp
mothurout.h
otuhierarchycommand.cpp
parselistscommand.cpp
parselistscommand.h
parsimony.cpp
parsimonycommand.cpp
parsimonycommand.h
pcacommand.cpp
pcacommand.h
phylotypecommand.cpp
pintail.cpp
pintail.h
preclustercommand.cpp
progress.cpp
rarefact.cpp
rarefact.h
rarefactcommand.cpp
rarefactsharedcommand.cpp
readblast.cpp
readblast.h
readcluster.cpp
readcluster.h
readcolumn.cpp
readcolumn.h
readdistcommand.cpp
readmatrix.hpp
readphylip.cpp
readphylip.h
readtree.cpp
readtreecommand.cpp
removeseqscommand.cpp
removeseqscommand.h
reversecommand.cpp
screenseqscommand.cpp
screenseqscommand.h
secondarystructurecommand.cpp
seqsummarycommand.cpp
sharedcommand.cpp
sharedcommand.h
slayer.cpp
slayer.h
slibshuff.cpp
summarycommand.cpp
summarysharedcommand.cpp
summarysharedcommand.h
taxonomyequalizer.cpp
tree.cpp
tree.h
treegroupscommand.cpp
treegroupscommand.h
trimseqscommand.cpp
trimseqscommand.h
unifracunweightedcommand.cpp
unifracunweightedcommand.h
unifracweightedcommand.cpp
unweighted.cpp
venn.cpp
venncommand.cpp
weighted.cpp

index 94cba4a10e344f5e27593a4723adb662cb9ab458..257587fa048ac3b494fa4f0ed4481f2cd505e513 100644 (file)
@@ -213,6 +213,8 @@ int AlignCommand::execute(){
                vector<string> outputNames;
                
                for (int s = 0; s < candidateFileNames.size(); s++) {
+                       if (m->control_pressed) { return 0; }
+                       
                        m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine();
                        
                        if (outputDir == "") {  outputDir += hasPath(candidateFileNames[s]); }
@@ -234,8 +236,9 @@ int AlignCommand::execute(){
                                
                                lines.push_back(new linePair(0, numFastaSeqs));
                                
-                               int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
-                               if (exitCommand == 0) { 
+                               driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+                               
+                               if (m->control_pressed) { 
                                        remove(accnosFileName.c_str()); 
                                        remove(alignFileName.c_str()); 
                                        remove(reportFileName.c_str()); 
@@ -280,7 +283,7 @@ int AlignCommand::execute(){
                                        lines.push_back(new linePair(startPos, numSeqsPerProcessor));
                                }
                                
-                               int exitCommand = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); 
+                               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());
@@ -317,7 +320,7 @@ int AlignCommand::execute(){
                                        m->mothurOutEndLine();
                                }else{ hasAccnos = false;  }
                                
-                               if (exitCommand == 0) { 
+                               if (m->control_pressed) { 
                                        remove(accnosFileName.c_str()); 
                                        remove(alignFileName.c_str()); 
                                        remove(reportFileName.c_str()); 
@@ -332,8 +335,9 @@ int AlignCommand::execute(){
                        
                        lines.push_back(new linePair(0, numFastaSeqs));
                        
-                       int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
-                       if (exitCommand == 0) { 
+                       driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+                       
+                       if (m->control_pressed) { 
                                remove(accnosFileName.c_str()); 
                                remove(alignFileName.c_str()); 
                                remove(reportFileName.c_str()); 
@@ -494,7 +498,7 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s
        try {
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                int process = 0;
-               int exitCommand;
+               int exitCommand = 1;
                //              processIDS.resize(0);
                
                //loop through and create all the processes you want
index 59405efe05963c8d153828d7f8f56976c440f197..51fb17517f3598fa975c5349fcf9fe4af1dbec90 100644 (file)
@@ -28,6 +28,8 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, floa
                while (!fastaFile.eof()) {
                        Sequence temp(fastaFile);  gobble(fastaFile);
                        
+                       if (m->control_pressed) {  templateSequences.clear(); break;  }
+                       
                        if (temp.getName() != "") {
                                templateSequences.push_back(temp);
                                //save longest base
@@ -67,20 +69,21 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, floa
                        search = new KmerDB(fastaFileName, 8);
                }
                
-               if (needToGenerate) {
-               
-                       //add sequences to search 
-                       for (int i = 0; i < templateSequences.size(); i++) {
-                               search->addSequence(templateSequences[i]);
+               if (!(m->control_pressed)) {
+                       if (needToGenerate) {
+                               //add sequences to search 
+                               for (int i = 0; i < templateSequences.size(); i++) {
+                                       search->addSequence(templateSequences[i]);
+                               }
+                               search->generateDB();
+                               
+                       }else if ((method == "kmer") && (!needToGenerate)) {
+                               ifstream kmerFileTest(kmerDBName.c_str());
+                               search->readKmerDB(kmerFileTest);       
                        }
-                       search->generateDB();
                        
-               }else if ((method == "kmer") && (!needToGenerate)) {
-                       ifstream kmerFileTest(kmerDBName.c_str());
-                       search->readKmerDB(kmerFileTest);       
+                       search->setNumSeqs(numSeqs);
                }
-               
-               search->setNumSeqs(numSeqs);
        }
        catch(exception& e) {
                m->errorOut(e, "AlignmentDB", "AlignmentDB");
index 42fb0232ad758fed402d6a2db2fe1ca10752b85a..af1fa27f2202de76086e562c775229f4f241e387 100644 (file)
@@ -56,6 +56,7 @@ Classify(tfile, tempFile, method, ksize, 0.0, 0.0, 0.0, 0.0), kmerSize(ksize), c
                        
                        //for each word
                        for (int i = 0; i < numKmers; i++) {
+                               if (m->control_pressed) { break; }
                                
                                out << i << '\t';
                                
@@ -114,6 +115,8 @@ string Bayesian::getTaxonomy(Sequence* seq) {
                }
        
                int index = getMostProbableTaxonomy(queryKmers);
+               
+               if (m->control_pressed) { return tax; }
                                        
                //bootstrap - to set confidenceScore
                int numToSelect = queryKmers.size() / 8;
@@ -143,6 +146,8 @@ string Bayesian::bootstrapResults(vector<int> kmers, int tax, int numToSelect) {
                map<int, int>::iterator itConvert;
                
                for (int i = 0; i < iters; i++) {
+                       if (m->control_pressed) { return "control"; }
+                       
                        vector<int> temp;
                                                
                        for (int j = 0; j < numToSelect; j++) {
index 02b282926bbb2dbe1eae2ed61997c2cbe4bccb8b..2c545fea5b141eff17bb9bf6aa3a8ea9745f9582 100644 (file)
@@ -27,12 +27,15 @@ Bellerophon::Bellerophon(string name, string o)  {
 }
 
 //***************************************************************************************************************
-void Bellerophon::print(ostream& out, ostream& outAcc) {
+int Bellerophon::print(ostream& out, ostream& outAcc) {
        try {
                int above1 = 0;
                out << "Name\tScore\tLeft\tRight\t" << endl;
                //output prefenence structure to .chimeras file
                for (int i = 0; i < pref.size(); i++) {
+                       
+                       if (m->control_pressed) {  return 0; }
+                       
                        out << pref[i].name << '\t' << setprecision(3) << pref[i].score[0] << '\t' << pref[i].leftParent[0] << '\t' << pref[i].rightParent[0] << endl;
                        
                        //calc # of seqs with preference above 1.0
@@ -62,6 +65,8 @@ void Bellerophon::print(ostream& out, ostream& outAcc) {
                m->mothurOut("97.5%-tile:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine();
                spot = 0;
                m->mothurOut("Maximum:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine();
+               
+               return 1;
 
        }
        catch(exception& e) {
@@ -89,6 +94,8 @@ int Bellerophon::getChimeras() {
                        filterSeqs->execute();
                        delete filterSeqs;
                        
+                       if (m->control_pressed) { return 0; }
+                       
                        //reset fastafile to filtered file
                        if (outputDir == "") { fastafile = getRootName(fastafile) + "filter.fasta"; }
                        else                             { fastafile = outputDir + getRootName(getSimpleName(fastafile)) + "filter.fasta"; }
@@ -96,10 +103,12 @@ int Bellerophon::getChimeras() {
                }
                
                distCalculator = new eachGapDist();
-cout << "fastafile = " << fastafile << endl;           
+               
                //read in sequences
                seqs = readSeqs(fastafile);
-       cout << "here:"<< endl; 
+               
+               if (m->control_pressed) { return 0; }
+       
                if (unaligned) { m->mothurOut("Your sequences need to be aligned when you use the bellerophon method."); m->mothurOutEndLine(); return 1;  }
                
                int numSeqs = seqs.size();
@@ -142,10 +151,15 @@ cout << "fastafile = " << fastafile << endl;
                int count = 0;
                while (count < iters) {
                                
+                               if (m->control_pressed) { return 0; }
+                               
                                //create 2 vectors of sequences, 1 for left side and one for right side
                                vector<Sequence> left;  vector<Sequence> right;
                                
                                for (int i = 0; i < seqs.size(); i++) {
+                               
+                                       if (m->control_pressed) { return 0; }
+                                       
 //cout << "midpoint = " << midpoint << "\twindow = " << window << endl;
 //cout << "whole = " << seqs[i]->getAligned().length() << endl;
                                        //save left side
@@ -176,8 +190,13 @@ cout << "fastafile = " << fastafile << endl;
                                SparseMatrix* SparseRight = new SparseMatrix();
                                
                                createSparseMatrix(0, left.size(), SparseLeft, left);
+                               
+                               if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
+                               
                                createSparseMatrix(0, right.size(), SparseRight, right);
                                
+                               if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
+                               
                                vector<SeqMap> distMapRight;
                                vector<SeqMap> distMapLeft;
                                
@@ -191,11 +210,13 @@ cout << "fastafile = " << fastafile << endl;
                                //cout << "left" << endl << endl;
                                for (MatData currentCell = SparseLeft->begin(); currentCell != SparseLeft->end(); currentCell++) {
                                        distMapLeft[currentCell->row][currentCell->column] = currentCell->dist;
+                                       if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
                                        //cout << " i = " << currentCell->row << " j = " << currentCell->column << " dist = " << currentCell->dist << endl;
                                }
                                //cout << "right" << endl << endl;
                                for (MatData currentCell = SparseRight->begin(); currentCell != SparseRight->end(); currentCell++) {
                                        distMapRight[currentCell->row][currentCell->column] = currentCell->dist;
+                                       if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }
                                        //cout << " i = " << currentCell->row << " j = " << currentCell->column << " dist = " << currentCell->dist << endl;
                                }
                                
@@ -246,6 +267,8 @@ int Bellerophon::createSparseMatrix(int startSeq, int endSeq, SparseMatrix* spar
                for(int i=startSeq; i<endSeq; i++){
                        
                        for(int j=0;j<i;j++){
+                               
+                               if (m->control_pressed) { return 0; }
                        
                                distCalculator->calcDist(s[i], s[j]);
                                float dist = distCalculator->getDist();
@@ -264,7 +287,7 @@ int Bellerophon::createSparseMatrix(int startSeq, int endSeq, SparseMatrix* spar
        }
 }
 /***************************************************************************************************************/
-void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right, int mid){
+int Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right, int mid){
        try {
                
                float dme = 0.0;
@@ -288,6 +311,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
                        SeqMap currentRight = right[i];         // same as left but with distances on the right side.
                        
                        for (int j = 0; j < i; j++) {
+                       
+                               if (m->control_pressed) {  return 0; }
                                
                                itL = currentLeft.find(j);
                                itR = currentRight.find(j);
@@ -352,6 +377,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
 //cout << endl << "dme = " << dme << endl;
                //recalculate prefernences based on dme
                for (int i = 0; i < pref.size(); i++) {
+               
+                       if (m->control_pressed) {  return 0; }
 //cout << "unadjusted pref " << i << " = " << pref[i].score[1] << endl;        
                        // gives the actual percentage of the dme this seq adds
                        pref[i].score[1] = pref[i].score[1] / dme;
@@ -368,6 +395,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
                //is this score bigger then the last score
                for (int i = 0; i < pref.size(); i++) {  
                        
+                       if (m->control_pressed) {  return 0; }
+                       
                        //update biggest score
                        if (pref[i].score[1] > pref[i].score[0]) {
                                pref[i].score[0] = pref[i].score[1];
@@ -379,6 +408,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
                        }
                        
                }
+               
+               return 1;
 
        }
        catch(exception& e) {
index dd5b3da8035cf1528c07a2964f17b9b1aa051cab..3d05617d50ad0a9dccb05da2d21bc872e8ca842f 100644 (file)
@@ -29,11 +29,7 @@ class Bellerophon : public Chimera {
                ~Bellerophon() {};
                
                int getChimeras();
-               void print(ostream&, ostream&);
-               
-               void setCons(string){};
-               void setQuantiles(string) {};
-               
+               int print(ostream&, ostream&);
                
        private:
                Dist* distCalculator;
@@ -43,7 +39,7 @@ class Bellerophon : public Chimera {
                string fastafile;
                int iters;
                
-               void generatePreferences(vector<SeqMap>, vector<SeqMap>, int);
+               int generatePreferences(vector<SeqMap>, vector<SeqMap>, int);
                int createSparseMatrix(int, int, SparseMatrix*, vector<Sequence>);
 };
 
index 1601f32873ed6c8eefe41608ceda199a6fa5b5f5..033cd52e9e323e1707f603f8c20aaf22f50d4ecc 100644 (file)
@@ -199,6 +199,8 @@ int BinSeqCommand::execute(){
                                
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
+                       if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str());         } return 0; }   
+                       
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){
                                
                                error = process(list);  
@@ -230,7 +232,8 @@ int BinSeqCommand::execute(){
                        list = input->getListVector();
                }
                
-               
+               if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str());         } return 0; }   
+
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -255,6 +258,8 @@ int BinSeqCommand::execute(){
                        delete list;  
                }
                
+               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();    }
index 6b76918044201a7438413c0f695f83c141d5638f..d174cdd7ddced16a34aeea406ae6397fca26496f 100644 (file)
@@ -219,7 +219,8 @@ int BootSharedCommand::execute(){
                globaldata->gTreemap = tmap;
                        
                while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-               
+                       if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
+       
                        if(allLines == 1 || labels.count(order->getLabel()) == 1){                      
                                
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
@@ -255,6 +256,9 @@ int BootSharedCommand::execute(){
                        order = input->getSharedOrderVector();
                }
                
+               
+               if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
+
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -268,6 +272,8 @@ int BootSharedCommand::execute(){
                        }
                }
                
+               if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
+
                //run last line if you need to
                if (needToRun == true)  {
                                if (order != NULL) {    delete order;   }
@@ -280,6 +286,8 @@ int BootSharedCommand::execute(){
 
                }
                
+               if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } globaldata->Groups.clear(); return 0;        } 
+
                //reset groups parameter
                globaldata->Groups.clear();  
                
@@ -360,6 +368,8 @@ int BootSharedCommand::createTree(ostream* out, Tree* t){
 
                //assemble tree
                t->assembleTree();
+               
+               if (m->control_pressed) { return 1; }
        
                //print newick file
                t->print(*out);
@@ -454,6 +464,8 @@ int BootSharedCommand::process(SharedOrderVector* order) {
                                                //creates tree from similarity matrix and write out file
                                                createTree(out[i], tempTree);
                                                
+                                               if (m->control_pressed) {   delete tempTree; return 1; }
+                                               
                                                //save trees for consensus command.
                                                trees[i].push_back(tempTree);
                                        }
index 00a30e5b6c0db1f58cb90b3c564703b7d3d77f6d..3aad3f6b48780505cb5f88c733b28027e28968b1 100644 (file)
--- a/ccode.cpp
+++ b/ccode.cpp
@@ -35,7 +35,7 @@ void Ccode::printHeader(ostream& out) {
        out << "For full window mapping info refer to " << mapInfo << endl << endl;
 }
 //***************************************************************************************************************
-void Ccode::print(ostream& out, ostream& outAcc) {
+int Ccode::print(ostream& out, ostream& outAcc) {
        try {
                
                ofstream out2;
@@ -116,7 +116,7 @@ void Ccode::print(ostream& out, ostream& outAcc) {
                //free memory
                for (int i = 0; i < closest.size(); i++) {  delete closest[i].seq;  }
 
-               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "Ccode", "print");
@@ -154,6 +154,8 @@ int Ccode::getChimeras(Sequence* query) {
                //find closest matches to query
                closest = findClosest(query, numWanted);
                
+               if (m->control_pressed) {  return 0;  }
+               
                //initialize spotMap
                for (int i = 0; i < query->getAligned().length(); i++) {        spotMap[i] = i;         }
        
@@ -176,7 +178,10 @@ int Ccode::getChimeras(Sequence* query) {
                        
                        createFilter(temp, 0.5);
                
-                       for (int i = 0; i < temp.size(); i++) { runFilter(temp[i]);  }
+                       for (int i = 0; i < temp.size(); i++) { 
+                               if (m->control_pressed) {  return 0;  }
+                               runFilter(temp[i]);  
+                       }
                        
                        //update spotMap
                        map<int, int> newMap;
@@ -194,30 +199,32 @@ int Ccode::getChimeras(Sequence* query) {
 
                //trim sequences - this follows ccodes remove_extra_gaps 
                trimSequences(query);
-               
+               if (m->control_pressed) {  return 0;  }
                
                //windows are equivalent to words - ccode paper recommends windows are between 5% and 20% on alignment length().  
                //Our default will be 10% and we will warn if user tries to use a window above or below these recommendations
                windows = findWindows();  
-               
+               if (m->control_pressed) {  return 0;  }
 
                //remove sequences that are more than 20% different and less than 0.5% different - may want to allow user to specify this later 
                removeBadReferenceSeqs(closest);
-               
+               if (m->control_pressed) {  return 0;  }
                
                //find the averages for each querys references
                getAverageRef(closest);  //fills sumRef, averageRef, sumSquaredRef and refCombo.
                getAverageQuery(closest, query);  //fills sumQuery, averageQuery, sumSquaredQuery.
-                                       
+               if (m->control_pressed) {  return 0;  }                 
                
                //find the averages for each querys references 
                findVarianceRef();  //fills varRef and sdRef also sets minimum error rate to 0.001 to avoid divide by 0.
-                       
+               if (m->control_pressed) {  return 0;  } 
                        
                //find the averages for the query 
                findVarianceQuery();  //fills varQuery and sdQuery also sets minimum error rate to 0.001 to avoid divide by 0.
+               if (m->control_pressed) {  return 0;  }
                                        
                determineChimeras();  //fills anova, isChimericConfidence, isChimericTStudent and isChimericANOVA. 
+               if (m->control_pressed) {  return 0;  }
                
                return 0;
        }
diff --git a/ccode.h b/ccode.h
index 5d05cd6a85a06b622e011c28e16bd30959503e6b..afc77cce5d9c003bc94ad16f970819a8f5c4680e 100644 (file)
--- a/ccode.h
+++ b/ccode.h
@@ -28,7 +28,7 @@ class Ccode : public Chimera {
                ~Ccode();
                
                int getChimeras(Sequence* query);
-               void print(ostream&, ostream&);
+               int print(ostream&, ostream&);
                void printHeader(ostream&);             
        private:
        
index 820b475ef32575a1d690d568b73ce4936a8f603b..7eeca96316511531532232d56519e1900cd7a9c6 100644 (file)
@@ -28,6 +28,8 @@ string Chimera::createFilter(vector<Sequence*> seqs, float t) {
                //for each sequence
                for (int i = 0; i < seqs.size(); i++) {
                
+                       if (m->control_pressed) { return filterString; }
+               
                        string seqAligned = seqs[i]->getAligned();
                
                        for (int j = 0; j < seqAligned.length(); j++) {
@@ -44,6 +46,9 @@ string Chimera::createFilter(vector<Sequence*> seqs, float t) {
                //zero out spot where all sequences have blanks
                int numColRemoved = 0;
                for(int i = 0;i < seqs[0]->getAligned().length(); i++){
+               
+                       if (m->control_pressed) { return filterString; }
+                       
                        if(gaps[i] == seqs.size())      {       filterString[i] = '0';  numColRemoved++;  }
                        
                        else if (((a[i] < threshold) && (t[i] < threshold) && (g[i] < threshold) && (c[i] < threshold))) {      filterString[i] = '0';  numColRemoved++;  }
@@ -100,6 +105,8 @@ vector<Sequence*> Chimera::readSeqs(string file) {
                //read in seqs and store in vector
                while(!in.eof()){
                        
+                       if (m->control_pressed) { return container; }
+                       
                        Sequence* current = new Sequence(in);  gobble(in);
                        
                        if (count == 0) {  length = current->getAligned().length();  count++;  } //gets first seqs length
index f6a5180975b134d7c5928dca4343e0a1f62074da..ef62b5357981272c93cd2c9869c5b507f0c1daaa 100644 (file)
--- a/chimera.h
+++ b/chimera.h
@@ -117,7 +117,7 @@ class Chimera {
                
                virtual void setCons(string){};
                virtual void setQuantiles(string){};
-               virtual void doPrep(){};
+               virtual int doPrep(){ return 0; }
                virtual vector<Sequence*> readSeqs(string);
                virtual vector< vector<float> > readQuantiles();
                virtual void setMask(string);
@@ -127,7 +127,7 @@ class Chimera {
                virtual void printHeader(ostream&){};
                virtual int getChimeras(Sequence*){ return 0; }
                virtual int getChimeras(){ return 0; }
-               virtual void print(ostream&, ostream&){};       
+               virtual int print(ostream&, ostream&){ return 0; }
                
                
        protected:
index 3e6dacdee85dbb75fb9b6535f259eead8a4f2509..790d3ebe01100c1d615be9d189e73d6fa03f28ef 100644 (file)
@@ -24,7 +24,7 @@ ChimeraCheckRDP::~ChimeraCheckRDP() {
        }
 }      
 //***************************************************************************************************************
-void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) {
+int ChimeraCheckRDP::print(ostream& out, ostream& outAcc) {
        try {
                
                m->mothurOut("Processing: " + querySeq->getName()); m->mothurOutEndLine();
@@ -48,6 +48,8 @@ void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) {
                                makeSVGpic(IS);  //zeros out negative results
                        }
                }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ChimeraCheckRDP", "print");
@@ -55,7 +57,7 @@ void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) {
        }
 }
 //***************************************************************************************************************
-void ChimeraCheckRDP::doPrep() {
+int ChimeraCheckRDP::doPrep() {
        try {
                templateDB = new AlignmentDB(templateFileName, "kmer", kmerSize, 0.0,0.0,0.0,0.0);
                m->mothurOutEndLine();
@@ -65,6 +67,8 @@ void ChimeraCheckRDP::doPrep() {
                if (name != "") { 
                        readName(name);  //fills name map with names of seqs the user wants to have .svg for.  
                }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ChimeraCheckRDP", "doPrep");
index 0ba851a9d6906b48a44b66d311882e0a88c8c400..f54faab045bf65f0c71797dd64ce5e25c045d0ca 100644 (file)
@@ -29,8 +29,8 @@ class ChimeraCheckRDP : public Chimera {
                ~ChimeraCheckRDP();
                
                int getChimeras(Sequence*);
-               void print(ostream&, ostream&);
-               void doPrep();
+               int print(ostream&, ostream&);
+               int doPrep();
                
        private:
                
index 86d6d50ed4295da62d957868386036d838a222be..69ce031a50c37caed255347378979e3b94d37b62 100644 (file)
@@ -318,6 +318,8 @@ int ChimeraSeqsCommand::execute(){
                if (method == "bellerophon") {//run bellerophon separately since you need to read entire fastafile to run it
                        chimera->getChimeras();
                        
+                       if (m->control_pressed) { delete chimera;       return 0;       }
+                       
                        ofstream out;
                        openOutputFile(outputFileName, out);
                        
@@ -328,6 +330,8 @@ int ChimeraSeqsCommand::execute(){
                        out.close();
                        out2.close(); 
                        
+                       if (m->control_pressed) { remove(accnosFileName.c_str()); remove(outputFileName.c_str()); delete chimera;       return 0;       }
+                       
                        //delete accnos file if its blank 
                        if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
                        
@@ -343,6 +347,8 @@ int ChimeraSeqsCommand::execute(){
                //reads template
                chimera->setTemplateFile(templatefile);
                
+               if (m->control_pressed) { delete chimera;       return 0;       }
+               
                if  (method != "chimeracheck") {   
                        if (chimera->getUnaligned()) { 
                                m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine(); 
@@ -354,6 +360,8 @@ int ChimeraSeqsCommand::execute(){
                //some methods need to do prep work before processing the chimeras
                chimera->doPrep(); 
                
+               if (m->control_pressed) { delete chimera;       return 0;       }
+               
                templateSeqsLength = chimera->getLength();
                
                ofstream outHeader;
@@ -376,6 +384,15 @@ int ChimeraSeqsCommand::execute(){
                                
                                driver(lines[0], outputFileName, fastafile, accnosFileName);
                                
+                               if (m->control_pressed) { 
+                                       remove(outputFileName.c_str()); 
+                                       remove(tempHeader.c_str()); 
+                                       remove(accnosFileName.c_str());
+                                       for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
+                                       delete chimera;
+                                       return 0;
+                               }
+                               
                                //delete accnos file if its blank 
                                if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
                                                                
@@ -435,6 +452,14 @@ int ChimeraSeqsCommand::execute(){
                                                remove(nonBlankAccnosFiles[h].c_str());
                                        }
                                }else{ hasAccnos = false;  }
+                               
+                               if (m->control_pressed) { 
+                                       remove(outputFileName.c_str()); 
+                                       remove(accnosFileName.c_str());
+                                       for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
+                                       delete chimera;
+                                       return 0;
+                               }
 
                        }
 
@@ -447,6 +472,15 @@ int ChimeraSeqsCommand::execute(){
                        
                        driver(lines[0], outputFileName, fastafile, accnosFileName);
                        
+                       if (m->control_pressed) { 
+                                       remove(outputFileName.c_str()); 
+                                       remove(tempHeader.c_str()); 
+                                       remove(accnosFileName.c_str());
+                                       for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
+                                       delete chimera;
+                                       return 0;
+                       }
+                       
                        //delete accnos file if its blank 
                        if (isBlank(accnosFileName)) {  remove(accnosFileName.c_str());  hasAccnos = false; }
                #endif
@@ -471,7 +505,7 @@ int ChimeraSeqsCommand::execute(){
                if (hasAccnos) {  m->mothurOut(accnosFileName); m->mothurOutEndLine();  }
                m->mothurOutEndLine();
 
-
+               for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
                
                m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
                
@@ -499,6 +533,8 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena
                
                for(int i=0;i<line->numSeqs;i++){
                
+                       if (m->control_pressed) {       return 1;       }
+               
                        Sequence* candidateSeq = new Sequence(inFASTA);  gobble(inFASTA);
                                
                        if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
@@ -508,6 +544,8 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena
                                }else{
                                        //find chimeras
                                        chimera->getChimeras(candidateSeq);
+                                       
+                                       if (m->control_pressed) {       delete candidateSeq; return 1;  }
                
                                        //print results
                                        chimera->print(out, out2);
@@ -525,7 +563,7 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena
                out2.close();
                inFASTA.close();
                                
-               return 1;
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ChimeraSeqsCommand", "driver");
@@ -535,7 +573,7 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena
 
 /**************************************************************************************************/
 
-void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, string accnos) {
+int ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, string accnos) {
        try {
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                int process = 0;
@@ -559,6 +597,8 @@ void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename,
                        int temp = processIDS[i];
                        wait(&temp);
                }
+               
+               return 0;
 #endif         
        }
        catch(exception& e) {
index 56477a11c5249b88ded4acd2c87ac547e8bc9754..040d2dde543b9311762640680d1a8ba874e3fcf5 100644 (file)
@@ -36,7 +36,7 @@ private:
        vector<linePair*> lines;
        
        int driver(linePair*, string, string, string);
-       void createProcesses(string, string, string);
+       int createProcesses(string, string, string);
        void appendOutputFiles(string, string); 
 
        bool abort;
index f8651079c8da037e6aeb119d494a350ae410597a..57ed7130916b0e1d810b470fa0552dc5556a1143 100644 (file)
@@ -16,7 +16,7 @@ ChimeraSlayer::ChimeraSlayer(string mode, bool r, string f) : searchMethod(mode)
        decalc = new DeCalculator();    
 }
 //***************************************************************************************************************
-void ChimeraSlayer::doPrep() {
+int ChimeraSlayer::doPrep() {
        try {
        
                string  kmerDBNameLeft;
@@ -33,6 +33,9 @@ void ChimeraSlayer::doPrep() {
                        if(!kmerFileTestLeft){  
                        
                                for (int i = 0; i < templateSeqs.size(); i++) {
+                                       
+                                       if (m->control_pressed) { return 0; } 
+                                       
                                        string leftFrag = templateSeqs[i]->getUnaligned();
                                        leftFrag = leftFrag.substr(0, int(leftFrag.length() * 0.33));
                                        
@@ -57,6 +60,8 @@ void ChimeraSlayer::doPrep() {
                        if(!kmerFileTestRight){ 
                        
                                for (int i = 0; i < templateSeqs.size(); i++) {
+                                       if (m->control_pressed) { return 0; } 
+                                       
                                        string rightFrag = templateSeqs[i]->getUnaligned();
                                        rightFrag = rightFrag.substr(int(rightFrag.length() * 0.66));
                                        
@@ -82,6 +87,8 @@ void ChimeraSlayer::doPrep() {
                
                vector<Sequence*> tempQuerySeqs;
                while(!in.eof()){
+                       if (m->control_pressed) { for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  } return 0; } 
+               
                        Sequence* s = new Sequence(in);
                        gobble(in);
                        
@@ -96,10 +103,15 @@ void ChimeraSlayer::doPrep() {
                                
                for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
                
+               if (m->control_pressed) {  return 0; } 
+
+               
                //run filter on template
-               for (int i = 0; i < templateSeqs.size(); i++) {  runFilter(templateSeqs[i]);  }
+               for (int i = 0; i < templateSeqs.size(); i++) {  if (m->control_pressed) {  return 0; }  runFilter(templateSeqs[i]);  }
                
                m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to filter.");    m->mothurOutEndLine();
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -118,7 +130,7 @@ void ChimeraSlayer::printHeader(ostream& out) {
        out << "Name\tLeftParent\tRightParent\tDivQLAQRB\tPerIDQLAQRB\tBootStrapA\tDivQLBQRA\tPerIDQLBQRA\tBootStrapB\tFlag\tLeftWindow\tRightWindow\n";
 }
 //***************************************************************************************************************
-void ChimeraSlayer::print(ostream& out, ostream& outAcc) {
+int ChimeraSlayer::print(ostream& out, ostream& outAcc) {
        try {
                if (chimeraFlags == "yes") {
                        string chimeraFlag = "no";
@@ -138,6 +150,8 @@ void ChimeraSlayer::print(ostream& out, ostream& outAcc) {
                        out << endl;
                }else {  out << querySeq->getName() << "\tno" << endl;  }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "ChimeraSlayer", "print");
@@ -158,7 +172,10 @@ int ChimeraSlayer::getChimeras(Sequence* query) {
                maligner = new Maligner(templateSeqs, numWanted, match, misMatch, divR, minSim, minCov, searchMethod, databaseLeft, databaseRight);
                slayer = new Slayer(window, increment, minSim, divR, iters, minSNP);
                
+               if (m->control_pressed) {  return 0;  }
+               
                string chimeraFlag = maligner->getResults(query, decalc);
+               if (m->control_pressed) {  return 0;  }
                vector<results> Results = maligner->getOutput();
                                
                //found in testing realigning only made things worse
@@ -233,8 +250,11 @@ int ChimeraSlayer::getChimeras(Sequence* query) {
                                spotMap = decalc->getMaskMap();
                        }
                        
+                       if (m->control_pressed) {  for (int k = 0; k < seqs.size(); k++) {  delete seqs[k].seq;   }  return 0;  }
+                       
                        //send to slayer
                        chimeraFlags = slayer->getResults(query, seqsForSlayer);
+                       if (m->control_pressed) {  return 0;  }
                        chimeraResults = slayer->getOutput();
                        
                        //free memory
index 14a22beed74f0d0fe6dbea9e5d255117d3187008..58e1656e6b995ae97d879863c0f2becc092ef9d1 100644 (file)
@@ -27,9 +27,9 @@ class ChimeraSlayer : public Chimera {
                ~ChimeraSlayer();
                
                int getChimeras(Sequence*);
-               void print(ostream&, ostream&);
+               int print(ostream&, ostream&);
                void printHeader(ostream&);
-               void doPrep();
+               int doPrep();
                
        private:
                Sequence* querySeq;
index 7a9a5e9b6f7b54d1218064cc03f7d5c94cb4d31d..ba854e98b40403c8d963fb65c9c4bd6178950947 100644 (file)
@@ -246,7 +246,9 @@ int ClassifySeqsCommand::execute(){
                        m->mothurOutEndLine();
                        classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters);   
                }
-
+               
+               if (m->control_pressed) { delete classify; return 0; }
+               
                vector<string> outputNames;
                                
                for (int s = 0; s < fastaFileNames.size(); s++) {
@@ -343,7 +345,9 @@ int ClassifySeqsCommand::execute(){
 #endif 
                        //make taxonomy tree from new taxonomy file 
                        PhyloTree taxaBrowser;
-               
+                       
+                       if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } delete classify; return 0; }
+                       
                        ifstream in;
                        openInputFile(tempTaxonomyFile, in);
                
@@ -352,6 +356,8 @@ int ClassifySeqsCommand::execute(){
                        while(!in.eof()){
                                in >> name >> taxon; gobble(in);
                                
+                               if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } remove(tempTaxonomyFile.c_str()); delete classify; return 0; }
+                               
                                if (namefile != "") {
                                        itNames = nameMap.find(name);
                
@@ -367,11 +373,16 @@ int ClassifySeqsCommand::execute(){
                        in.close();
        
                        taxaBrowser.assignHeirarchyIDs(0);
+                       
+                       if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } remove(tempTaxonomyFile.c_str()); delete classify; return 0; }
 
                        taxaBrowser.binUnclassified();
                        
                        remove(tempTaxonomyFile.c_str());
                        
+                       if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } delete classify; return 0; }
+
+                       
                        //print summary file
                        ofstream outTaxTree;
                        openOutputFile(taxSummary, outTaxTree);
@@ -389,8 +400,10 @@ int ClassifySeqsCommand::execute(){
                        //get maxLevel from phylotree so you know how many 'unclassified's to add
                        int maxLevel = taxaBrowser.getMaxLevel();
                        
-                       //read taxfile - this reading and rewriting is done to preserve the confidence sscores.
+                       //read taxfile - this reading and rewriting is done to preserve the confidence scores.
                        while (!inTax.eof()) {
+                               if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } remove(unclass.c_str()); delete classify; return 0; }
+
                                inTax >> name >> taxon; gobble(inTax);
                                
                                string newTax = addUnclassifieds(taxon, maxLevel);
@@ -526,11 +539,14 @@ int ClassifySeqsCommand::driver(linePair* line, string taxFName, string tempTFNa
                string taxonomy;
 
                for(int i=0;i<line->numSeqs;i++){
+                       if (m->control_pressed) { return 0; }
                        
                        Sequence* candidateSeq = new Sequence(inFASTA);
                        
                        if (candidateSeq->getName() != "") {
                                taxonomy = classify->getTaxonomy(candidateSeq);
+                               
+                               if (m->control_pressed) { delete candidateSeq; return 0; }
 
                                if (taxonomy != "bad seq") {
                                        //output confidence scores or not
index 9bf2c9a88c49f49f27d8a641aabc4d9f8d2ab3fe..cf8ba10e8e43054304c42892cbfb9c2014a8da1f 100644 (file)
@@ -234,8 +234,8 @@ int CollectCommand::execute(){
                        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];    }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
                                delete input;  globaldata->ginput = NULL;
                                delete read;
                                delete order; globaldata->gorder = NULL;
@@ -246,25 +246,26 @@ int CollectCommand::execute(){
 
 
                        while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+                       
+                               if (m->control_pressed) { 
+                                       for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                                       delete input;  globaldata->ginput = NULL;
+                                       delete read;
+                                       delete order; globaldata->gorder = NULL;
+                                       delete validCalculator;
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
+
                                
                                if(allLines == 1 || labels.count(order->getLabel()) == 1){
-                                       
+                               
+                                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        cCurve = new Collect(order, cDisplays);
-                                       int error = cCurve->getCurve(freq);
+                                       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());
                                        
@@ -277,22 +278,12 @@ int CollectCommand::execute(){
                                        delete order;
                                        order = (input->getOrderVector(lastLabel));
                                        
+                                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        cCurve = new Collect(order, cDisplays);
-                                       int error = cCurve->getCurve(freq);
+                                       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());
                                        
@@ -306,6 +297,17 @@ int CollectCommand::execute(){
                                order = (input->getOrderVector());
                        }
                        
+                       
+                       if (m->control_pressed) { 
+                                       for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                                       delete input;  globaldata->ginput = NULL;
+                                       delete read;
+                                       delete validCalculator;
+                                       globaldata->Groups.clear();
+                                       return 0;
+                       }
+                               
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -327,12 +329,12 @@ int CollectCommand::execute(){
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                
                                cCurve = new Collect(order, cDisplays);
-                               int error = cCurve->getCurve(freq);
+                               cCurve->getCurve(freq);
                                delete cCurve;
                                
-                               if (error == 1) {
-                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  
+                               if (m->control_pressed) { 
                                        for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
                                        delete input;  globaldata->ginput = NULL;
                                        delete read;
                                        delete order; globaldata->gorder = NULL;
@@ -351,6 +353,8 @@ int CollectCommand::execute(){
                        delete validCalculator;
                }
                
+               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();    }
index 201709ea83ff099f9afe97b2e3af69bdb4fbe1ce..28e58b19f1cf61d83383f3e28905bf3846a2d3ba 100644 (file)
@@ -261,26 +261,22 @@ int CollectSharedCommand::execute(){
                util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
 
                while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
-                       if(allLines == 1 || labels.count(order->getLabel()) == 1){
-                               
-                               //create collectors curve
-                               cCurve = new Collect(order, cDisplays);
-                               int error = cCurve->getSharedCurve(freq);
-                               delete cCurve;
-                               
-                               if (error == 1) {
+                       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;
+                                       delete order; 
                                        globaldata->Groups.clear();
                                        return 0;
-                               }
+                       }
+
+                       if(allLines == 1 || labels.count(order->getLabel()) == 1){
                        
                                m->mothurOut(order->getLabel()); m->mothurOutEndLine();
+                               //create collectors curve
+                               cCurve = new Collect(order, cDisplays);
+                               cCurve->getSharedCurve(freq);
+                               delete cCurve;
+                       
                                processedLabels.insert(order->getLabel());
                                userLabels.erase(order->getLabel());
                        }
@@ -292,24 +288,12 @@ int CollectSharedCommand::execute(){
                                delete order;
                                order = input->getSharedOrderVector(lastLabel);
                                
+                               m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                //create collectors curve
                                cCurve = new Collect(order, cDisplays);
-                               int error = cCurve->getSharedCurve(freq);
+                               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());
                                userLabels.erase(order->getLabel());
                                
@@ -325,6 +309,13 @@ int CollectSharedCommand::execute(){
                        order = input->getSharedOrderVector();
                }
                
+               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];    }
+                                       globaldata->Groups.clear();
+                                       return 0;
+               }
+               
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -342,24 +333,20 @@ int CollectSharedCommand::execute(){
                if (needToRun == true)  {
                        if (order != NULL) {  delete order;  }
                        order = input->getSharedOrderVector(lastLabel);
-
+                       
+                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                        cCurve = new Collect(order, cDisplays);
-                       int error = cCurve->getSharedCurve(freq);
+                       cCurve->getSharedCurve(freq);
                        delete cCurve;
                        
-                       if (error == 1) {
+                       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;
+                               delete order; 
                                globaldata->Groups.clear();
                                return 0;
                        }
 
-                       
-                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                        delete order;
                }
                
index dc278017c906dcfeb9f7967bc99f767df7007011..37cd39578c953e3d843c4cd0892b1be992511a88 100644 (file)
@@ -62,7 +62,9 @@ int ConcensusCommand::execute(){
                }
                
                //get the possible pairings
-               getSets();              
+               getSets();      
+               
+               if (m->control_pressed) { return 0; }
                
                //open file for pairing not included in the tree
                notIncluded = filename + ".cons.pairs";
@@ -82,8 +84,12 @@ int ConcensusCommand::execute(){
                
                buildConcensusTree(treeSet);
                
+               if (m->control_pressed) { delete consensusTree; return 0; }
+               
                consensusTree->assembleTree();
                
+               if (m->control_pressed) { delete consensusTree; return 0; }
+               
                //output species in order
                out2 << "Species in Order: " << endl << endl;
                for (int i = 0; i < treeSet.size(); i++) {  out2 << i+1 << ".  " << treeSet[i] << endl; }
@@ -91,8 +97,13 @@ int ConcensusCommand::execute(){
                //output sets included
                out2 << endl << "Sets included in the consensus tree:" << endl << endl;
                
+               if (m->control_pressed) { delete consensusTree; return 0; }
+               
                vector<string> temp;
                for (it2 = nodePairsInTree.begin(); it2 != nodePairsInTree.end(); it2++) {
+               
+                       if (m->control_pressed) { delete consensusTree; return 0; }
+                       
                        //only output pairs not leaves
                        if (it2->first.size() > 1) { 
                                temp.clear();
@@ -118,6 +129,9 @@ int ConcensusCommand::execute(){
                //output sets not included
                out2 << endl << "Sets NOT included in the consensus tree:" << endl << endl;
                for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
+               
+                       if (m->control_pressed) { delete consensusTree; return 0; }
+                       
                        temp.clear();
                        //initialize temp to all "."
                        temp.resize(treeSet.size(), ".");
@@ -159,6 +173,8 @@ int ConcensusCommand::buildConcensusTree(vector<string> nodeSet) {
                vector<string> leftChildSet;
                vector<string> rightChildSet;
                
+               if (m->control_pressed) { return 1; }
+               
                //if you are at a leaf
                if (nodeSet.size() == 1) {
                        //return the vector index of the leaf you are at
@@ -186,7 +202,7 @@ int ConcensusCommand::buildConcensusTree(vector<string> nodeSet) {
 }
 
 //**********************************************************************************************************************
-void ConcensusCommand::getSets() {
+int ConcensusCommand::getSets() {
        try {
                vector<string> temp;
                treeSet.clear();
@@ -196,6 +212,9 @@ void ConcensusCommand::getSets() {
                        
                        //for each non-leaf node get descendant info.
                        for (int j = numLeaves; j < numNodes; j++) {
+                               
+                               if (m->control_pressed) { return 1; }
+                               
                                temp.clear();
                                //go through pcounts and pull out descendants
                                for (it = t[i]->tree[j].pcount.begin(); it != t[i]->tree[j].pcount.end(); it++) {
@@ -219,6 +238,8 @@ void ConcensusCommand::getSets() {
                //you want the leaves in there but with insignifigant sightings value so it is added last
                //for each leaf node get descendant info.
                for (int j = 0; j < numLeaves; j++) {
+               
+                       if (m->control_pressed) { return 1; }
                        
                        //only need the first one since leaves have no descendants but themselves
                        it = t[0]->tree[j].pcount.begin(); 
@@ -239,6 +260,7 @@ void ConcensusCommand::getSets() {
                
                //set initial rating on pairs to sightings + subgroup sightings
                while (nodePairsCopy.size() != 0) {
+                       if (m->control_pressed) { return 1; }
                
                        vector<string> small = getSmallest(nodePairsCopy);
                        
@@ -249,6 +271,7 @@ void ConcensusCommand::getSets() {
                        nodePairsCopy.erase(small);
                }
                
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ConcensusCommand", "getSets");
index 145bea5bdaf24410229cb42e889e7f02cacdd9c8..7a7960708c9b5d17d69355caaf8cfd8be089e76d 100644 (file)
@@ -44,7 +44,7 @@ private:
        ofstream out, out2;
        int numNodes, numLeaves, count;  //count is the next available spot in the tree vector
                                                                                
-       void getSets();
+       int getSets();
        int getSubgroupRating(vector<string>);
        vector<string> getSmallest(map< vector<string>, int>);
        vector<string> getNextAvailableSet(vector<string>, vector<string>&);  
index d4c4eb5e8b21e492df18d62af4226b6e8836a110..857bcf2e09c5e20f1f6a03cc95be674898411e6e 100644 (file)
@@ -402,6 +402,8 @@ vector< vector<quanMember> > DeCalculator::getQuantiles(vector<Sequence*> seqs,
                                
                                Sequence* subject = new Sequence(seqs[j]->getName(), seqs[j]->getAligned());
                                
+                               if (m->control_pressed) { delete query; delete subject; return quan; }
+                               
                                map<int, int> trim;
                                map<int, int>::iterator it;
                                
index fcfd320e0b6be3aa3572b661a579311c9dead5bf..663a6bf81d0fbbda91052e6cc0433df8e2d7fb4a 100644 (file)
@@ -110,9 +110,13 @@ int DeconvoluteCommand::execute() {
                if(oldNameMapFName == "")       {       fastamap.readFastaFile(inFastaName);                                    }
                else                                            {       fastamap.readFastaFile(inFastaName, oldNameMapFName);   }
                
+               if (m->control_pressed) { return 0; }
+               
                fastamap.printCondensedFasta(outFastaFile);
                fastamap.printNamesFile(outNameFile);
                
+               if (m->control_pressed) { remove(outFastaFile.c_str()); remove(outNameFile.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                m->mothurOut(outFastaFile); m->mothurOutEndLine();      
index 13f56eb90a422d43e821a9fa378f582691468cb8..f05cb768e0c433daf1a976827b9371333e37acb7 100644 (file)
@@ -208,9 +208,12 @@ int DistanceCommand::execute(){
                ifstream inFASTA;
                driver(0, numSeqs, outputFile, cutoff);
 #endif
+               if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; }
                
                if (output == "square") {  convertMatrix(outputFile); }
                
+               if (m->control_pressed) { delete distCalculator; remove(outputFile.c_str()); return 0; }
+               
                delete distCalculator;
                
                m->mothurOutEndLine();
@@ -282,6 +285,9 @@ int DistanceCommand::driver(int startLine, int endLine, string dFileName, float
                                outFile << name << '\t';        
                        }
                        for(int j=0;j<i;j++){
+                               
+                               if (m->control_pressed) { outFile.close(); return 0;  }
+                               
                                distCalculator->calcDist(alignDB.get(i), alignDB.get(j));
                                double dist = distCalculator->getDist();
                                
@@ -316,7 +322,7 @@ int DistanceCommand::driver(int startLine, int endLine, string dFileName, float
        }
 }
 /**************************************************************************************************/
-void DistanceCommand::convertMatrix(string outputFile) {
+int DistanceCommand::convertMatrix(string outputFile) {
        try{
 
                //sort file by first column so the distances for each row are together
@@ -358,6 +364,8 @@ void DistanceCommand::convertMatrix(string outputFile) {
                //openInputFile(outfile, in);
                
                while(!in.eof()) {
+                       if (m->control_pressed) { in.close(); remove(outfile.c_str()); out.close(); return 0; }
+                       
                        in >> first >> second >> dist; gobble(in);
                                
                        if (first != currentRow) {
@@ -393,6 +401,8 @@ void DistanceCommand::convertMatrix(string outputFile) {
                
                remove(outfile.c_str());
                
+               return 1;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "DistanceCommand", "convertMatrix");
index dedcc79da45f6f60d3beb264c157202557847af4..61fc49ea89b37e064c7d6446421efcf12251301a 100644 (file)
@@ -46,7 +46,7 @@ private:
        //void appendFiles(string, string);
        void createProcesses(string);
        int driver(/*Dist*, SequenceDB, */int, int, string, float);
-       void convertMatrix(string);
+       int convertMatrix(string);
 
 };
 
index 9db8872abfdab387ed6a71398e570442fee6022d..4947e0500611bdf1f43bfad25374ef21369f30c8 100644 (file)
@@ -46,13 +46,23 @@ vector<vector<double> > DLibshuff::evaluateAll(){
 
 double DLibshuff::dCalculate(int x, int y){
        
+       double sum = 0;
+       
        minX = getMinX(x);
+       
+       if (m->control_pressed) { return sum; }
+       
        minXY = getMinXY(x, y);
        
+       if (m->control_pressed) { return sum; }
+       
        vector<int> nx = calcN(minX);
+       
+       if (m->control_pressed) { return sum; }
+       
        vector<int> nxy = calcN(minXY);
-
-       double sum = 0;
+       
+       if (m->control_pressed) { return sum; }
 
        for(int i=0;i<numDXs;i++){
                float h = (nx[i] - nxy[i]) / (float) groupSizes[x];
index 5e9ac5f36372a5bdbd4da64d1a87d3bac57b5954..3bdc484ac64a0a1140feee90e299696c2eb292c3 100644 (file)
@@ -54,7 +54,9 @@ bool InteractEngine::getInput(){
                        mout->mothurOutEndLine();
                        
                        input = getCommand();   
-                       mout->mothurOutEndLine();               
+                       mout->mothurOutEndLine();       
+                       
+                       if (mout->control_pressed) { input = "quit()"; }
                        
                        //allow user to omit the () on the quit command
                        if (input == "quit") { input = "quit()"; }
@@ -65,12 +67,12 @@ bool InteractEngine::getInput(){
                        options = parser.getOptionString();
                        
                        if (commandName != "") {
-                       
+                               mout->executing = true;
                                //executes valid command
                                Command* command = cFactory->getCommand(commandName, options);
                                quitCommandCalled = command->execute();
                                mout->control_pressed = 0;
-                               
+                               mout->executing = false;
                        }else {
                                mout->mothurOut("Your input contains errors. Please try again."); 
                                mout->mothurOutEndLine();
@@ -171,6 +173,7 @@ bool BatchEngine::getInput(){
                                mout->mothurOut("mothur > " + input);
                                mout->mothurOutEndLine();
                                
+                               if (mout->control_pressed) { input = "quit()"; }
                                
                                //allow user to omit the () on the quit command
                                if (input == "quit") { input = "quit()"; }
@@ -180,11 +183,12 @@ bool BatchEngine::getInput(){
                                options = parser.getOptionString();
                                                                                
                                if (commandName != "") {
-
+                                       mout->executing = true;
                                        //executes valid command
                                        Command* command = cFactory->getCommand(commandName, options);
                                        quitCommandCalled = command->execute();
                                        mout->control_pressed = 0;
+                                       mout->executing = false;
                                }else {         
                                        mout->mothurOut("Invalid."); 
                                        mout->mothurOutEndLine();
@@ -251,6 +255,7 @@ bool ScriptEngine::getInput(){
                        mout->mothurOut("mothur > " + input);
                        mout->mothurOutEndLine();
 
+                       if (mout->control_pressed) { input = "quit()"; }
                                
                        //allow user to omit the () on the quit command
                        if (input == "quit") { input = "quit()"; }
@@ -260,11 +265,12 @@ bool ScriptEngine::getInput(){
                        options = parser.getOptionString();
                                                                                
                        if (commandName != "") {
-
+                               mout->executing = true;
                                //executes valid command
                                Command* command = cFactory->getCommand(commandName, options);
                                quitCommandCalled = command->execute();
                                mout->control_pressed = 0;
+                               mout->executing = false;
                        }else {         
                                mout->mothurOut("Invalid."); 
                                mout->mothurOutEndLine();
index 2831ecbff9e2c2427ca551b0e08967ff738f8e7a..36b072121b044490332a8926f0f3f287bf816fab 100644 (file)
@@ -21,6 +21,8 @@ void FastaMap::readFastaFile(string inFileName) {
                string temp;
 
                while(!in.eof()){
+                       if (m->control_pressed) { break; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -59,6 +61,8 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin
        map<string,string> oldNameMap;
        string name, list;
        while(!oldNameFile.eof()){
+               if (m->control_pressed) { break; }
+               
                oldNameFile >> name >> list;
                oldNameMap[name] = list;
                gobble(oldNameFile);
@@ -69,6 +73,8 @@ void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prin
        openInputFile(inFastaFile, inFASTA);
        string sequence;
        while(!inFASTA.eof()){
+               if (m->control_pressed) { break; }
+               
                Sequence currSeq(inFASTA);
                name = currSeq.getName();
                
@@ -145,6 +151,7 @@ void FastaMap::printNamesFile(string outFileName){ //prints data
                
                // two column file created with groupname and them list of identical sequence names
                for (map<string,group>::iterator it = data.begin(); it != data.end(); it++) {
+                       if (m->control_pressed) { break; }
                        outFile << it->second.groupname << '\t' << it->second.names << endl;
                }
                outFile.close();
@@ -163,6 +170,7 @@ void FastaMap::printCondensedFasta(string outFileName){ //prints data
                openOutputFile(outFileName, out);
                //creates a fasta file
                for (map<string,group>::iterator it = data.begin(); it != data.end(); it++) {
+                       if (m->control_pressed) { break; }
                        out << ">" << it->second.groupname << endl;
                        out << it->first << endl;
                }
index 91d1181f3770b5010fcabd7e5c78e61b18186904..2fd172117fa71a06ab9cfb7b36792c0683a62698 100644 (file)
@@ -185,6 +185,9 @@ int FilterSeqsCommand::execute() {
                                openInputFile(fastafileNames[i], in);
                                
                                while(!in.eof()){       //read through and create the filter...
+                               
+                                       if (m->control_pressed) { in.close(); return 0; }
+                                       
                                        Sequence seq(in);
                                        if (seq.getName() != "") {
                                                if(trump != '*'){       F.doTrump(seq); }
@@ -224,6 +227,8 @@ int FilterSeqsCommand::execute() {
                        
                        
                        while(!in.eof()){
+                               if (m->control_pressed) { in.close(); outFASTA.close(); for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }  return 0; }
+                               
                                Sequence seq(in);
                                if (seq.getName() != "") {
                                        string align = seq.getAligned();
@@ -249,6 +254,9 @@ int FilterSeqsCommand::execute() {
                        if(filter[i] == '1'){   filteredLength++;       }
                }
                
+               if (m->control_pressed) {  for(int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }  return 0; }
+
+               
                m->mothurOutEndLine();
                m->mothurOut("Length of filtered alignment: " + toString(filteredLength)); m->mothurOutEndLine();
                m->mothurOut("Number of columns removed: " + toString((alignmentLength-filteredLength))); m->mothurOutEndLine();
index e13ead55b4743304d90b062f3cda01208149e350..64b85317d1303658627f4ed6cfde1f99b51d3677 100644 (file)
@@ -16,7 +16,7 @@ FormatColumnMatrix::FormatColumnMatrix(string df) : filename(df){
 }
 /***********************************************************************/
 
-void FormatColumnMatrix::read(NameAssignment* nameMap){
+int FormatColumnMatrix::read(NameAssignment* nameMap){
        try {           
 
                string firstName, secondName;
@@ -39,6 +39,8 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){
        
                while(fileHandle && lt == 1){  //let's assume it's a triangular matrix...
                
+                       if (m->control_pressed) { out.close(); remove(tempOutFile.c_str()); fileHandle.close();  delete reading; return 0; }
+               
                        fileHandle >> firstName >> secondName >> distance;      // get the row and column names and distance
        
                        map<string,int>::iterator itA = nameMap->find(firstName);
@@ -88,6 +90,7 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){
                        system(command.c_str());
                #endif
                
+               if (m->control_pressed) { remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
 
                //output to new file distance for each row and save positions in file where new row begins
                ifstream in;
@@ -111,6 +114,9 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){
                for(int k = 0; k < firstString.length(); k++)  {   in.putback(firstString[k]);  }
                
                while(!in.eof()) {
+                       
+                       if (m->control_pressed) { in.close(); out.close(); remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
+                       
                        in >> first >> second >> dist; gobble(in);
                        
                        if (first != currentRow) {
@@ -153,12 +159,19 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){
                in.close();
                out.close();
                
+               if (m->control_pressed) {  remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str());  delete reading; return 0; }
                
                remove(tempOutFile.c_str());
                remove(outfile.c_str());
                
                reading->finish();
+               
+               delete reading;
                list->setLabel("0");
+               
+               if (m->control_pressed) {  remove(distFile.c_str());  return 0; }
+
+               return 1;
 
        }
        catch(exception& e) {
index c713867bf2d95206ef0424763396cb734dd68578..0fe96ed237d58ccccef2bca45c5a9fcf7d6f358b 100644 (file)
@@ -18,7 +18,7 @@ class FormatColumnMatrix : public FormatMatrix {
 public:
        FormatColumnMatrix(string);
        ~FormatColumnMatrix();
-       void read(NameAssignment*);
+       int read(NameAssignment*);
        
 private:
        ifstream fileHandle;
index 30e427668bbcca5a9db73b1858097f3c0e0b4379..7e7a99c1dbcf4bf495ad7b1a7c7caec49bef3e90 100644 (file)
@@ -60,7 +60,7 @@ public:
        FormatMatrix(){ m = MothurOut::getInstance(); }
        virtual ~FormatMatrix() {}
        
-       virtual void read(NameAssignment*){};
+       virtual int read(NameAssignment*){ return 1; }
        
        void setCutoff(float c)                 {       cutoff = c;                     }
        ListVector* getListVector()             {       return list;            }
index aaf540aed0d800d111e1a8a7703520640a28d240..206df7edfbd915f00947c46d6de07f44fc021c38 100644 (file)
@@ -16,7 +16,7 @@ FormatPhylipMatrix::FormatPhylipMatrix(string df) : filename(df) {
 }
 /***********************************************************************/
 //not using nameMap
-void FormatPhylipMatrix::read(NameAssignment* nameMap){
+int FormatPhylipMatrix::read(NameAssignment* nameMap){
        try {
         
                        float distance;
@@ -63,11 +63,15 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                 
                                //convert to square column matrix
                                for(int i=1;i<nseqs;i++){
+                               
                                        fileHandle >> name;
                                        
                                        list->set(i, name);
                                        
                                        for(int j=0;j<i;j++){
+                                       
+                                               if (m->control_pressed) { outTemp.close(); remove(tempFile.c_str()); fileHandle.close();  delete reading; return 0; }
+                                                                                       
                                                fileHandle >> distance;
                                                
                                                if (distance == -1) { distance = 1000000; }
@@ -95,6 +99,7 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                        system(command.c_str());
                                #endif
                                
+                               if (m->control_pressed) { remove(tempFile.c_str()); remove(outfile.c_str());  delete reading; return 0; }
 
                                //output to new file distance for each row and save positions in file where new row begins
                                ifstream in;
@@ -118,6 +123,8 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                for(int k = 0; k < firstString.length(); k++)  {   in.putback(firstString[k]);  }
                                
                                while(!in.eof()) {
+                                       if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); remove(distFile.c_str()); remove(outfile.c_str());  delete reading; return 0; }
+
                                        in >> first >> second >> dist; gobble(in);
                                        
                                        if (first != currentRow) {
@@ -160,6 +167,9 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                
                                remove(tempFile.c_str());
                                remove(outfile.c_str());
+                               
+                               if (m->control_pressed) {  remove(distFile.c_str());   delete reading; return 0; }
+
                        }
                        else{ //square matrix convert directly to formatted row file
                                int index = nseqs;
@@ -173,6 +183,8 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                        list->set(i, name);
                                        
                                        for(int j=0;j<nseqs;j++){
+                                               if (m->control_pressed) {  fileHandle.close(); out.close(); remove(distFile.c_str());   delete reading; return 0; }
+                                               
                                                fileHandle >> distance;
                                        
                                                if (distance == -1) { distance = 1000000; }
@@ -202,11 +214,16 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                        }
                        reading->finish();
                        delete reading;
-                       
-                       list->setLabel("0");
                        fileHandle.close();
                        out.close();
                        
+                       if (m->control_pressed) { remove(distFile.c_str());  return 0; }
+                       
+                       list->setLabel("0");
+                       
+                       return 1;
+                       
+                       
        }
        catch(exception& e) {
                m->errorOut(e, "FormatPhylipMatrix", "read");
index 9ca14bb782f1c6d4eb2a69890762a421c3384055..b920d088cba0673f9c597ad870307084de551afd 100644 (file)
@@ -19,7 +19,7 @@ class FormatPhylipMatrix : public FormatMatrix {
 public:
        FormatPhylipMatrix(string);
        ~FormatPhylipMatrix();
-       void read(NameAssignment*);
+       int read(NameAssignment*);
 private:
        ifstream fileHandle;
        string filename;
index 0255d07f00bbcfef3a9c62658149ec39fd6fc5bf..72866491648e1fb02f681c1ca5842fdbba8e58a2 100644 (file)
@@ -56,10 +56,12 @@ FullMatrix::FullMatrix(ifstream& filehandle) {
                }
                
                //read rest of matrix
-               if (square == true) { readSquareMatrix(filehandle); }
-               else { readLTMatrix(filehandle); }
+               if (square == true) {  readSquareMatrix(filehandle); }
+               else {  readLTMatrix(filehandle); }
                
-               sortGroups(0, numSeqs-1);       
+               filehandle.close();
+               
+               if (!m->control_pressed) { sortGroups(0, numSeqs-1); }  
                                
        }
        catch(exception& e) {
@@ -68,7 +70,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) {
        }
 }
 /**************************************************************************/
-void FullMatrix::readSquareMatrix(ifstream& filehandle) {
+int FullMatrix::readSquareMatrix(ifstream& filehandle) {
        try {
        
                Progress* reading;
@@ -77,7 +79,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
                int count = 0;
                
                string group, name;
-               
+       
                for(int i=1;i<numSeqs;i++){
                        filehandle >> name;             
                        
@@ -88,14 +90,21 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
                        if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); }
                                
                        for(int j=0;j<numSeqs;j++){
+                               if (m->control_pressed) { delete reading;  return 0; }
+                               
                                filehandle >> matrix[i][j];
                                
                                count++;
                                reading->update(count);
                        }
                }
+               
+               if (m->control_pressed) { delete reading;  return 0; }
+               
                reading->finish();
                delete reading;
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "FullMatrix", "readSquareMatrix");
@@ -103,7 +112,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
        }
 } 
 /**************************************************************************/
-void FullMatrix::readLTMatrix(ifstream& filehandle) {
+int FullMatrix::readLTMatrix(ifstream& filehandle) {
        try {
                Progress* reading;
                reading = new Progress("Reading matrix:     ", numSeqs * (numSeqs - 1) / 2);
@@ -123,15 +132,22 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) {
                        if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                                
                        for(int j=0;j<i;j++){
+                               if (m->control_pressed) { delete reading;  return 0; }
+                               
                                filehandle >> distance;
+               
                                matrix[i][j] = distance;  matrix[j][i] = distance;
                                count++;
                                reading->update(count);
                        }
                }
-
+               
+               if (m->control_pressed) { delete reading;  return 0; }
+               
                reading->finish();
                delete reading;
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "FullMatrix", "readLTMatrix");
index 15fee6e04a97416f3ad734c4f81fe75a6eb598ec..e2c0e31b5fa8e4ed81ced8ba88b61fc4620adbf3 100644 (file)
@@ -39,8 +39,8 @@ public:
        
 private:
        vector< vector<float> > matrix;  //a 2D distance matrix of all the sequences and their distances to eachother.
-       void readSquareMatrix(ifstream&);  
-       void readLTMatrix(ifstream&);
+       int readSquareMatrix(ifstream&);  
+       int readLTMatrix(ifstream&);
        vector<Names> index; // row in vector, sequence group.  need to know this so when we sort it can be updated.
        vector<int> sizes;
        vector<string> groups;
index b645517f938928c44eb5faa5871e4171c40fb800..817331f8ce06a531c447896707951b2e6ffb7b9d 100644 (file)
@@ -102,10 +102,14 @@ int GetgroupCommand::execute(){
                        in >> inputData;
                }
                
+               if (m->control_pressed) { in.close();  out.close(); remove(outputFile.c_str());   return 0; }
+
                if (in.eof() != true) { in >> nextLabel; }
                
                //read the rest of the groups info in
                while ((nextLabel == holdLabel) && (in.eof() != true)) {
+                       if (m->control_pressed) { in.close();  out.close(); remove(outputFile.c_str());   return 0; }
+                       
                        in >> groupN >> num;
                        count++;
                        
@@ -124,6 +128,8 @@ int GetgroupCommand::execute(){
                in.close();
                out.close();
                
+               if (m->control_pressed) {  remove(outputFile.c_str());   return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(outputFile); m->mothurOutEndLine();        
index d306250f5b82b48cd6b353c4af0619907e2b9086..1c08eb1fab8905674700bdc440a93ebd38b88a4f 100644 (file)
@@ -64,6 +64,9 @@ int GetlabelCommand::execute(){
                int numBins = 0;
                int count = -1;
                while(in.good()) {
+                       
+                       if (m->control_pressed) { in.close();  return 0; }
+                       
                        if(count > numBins)
                                count = 0;
                        if(count == 0) {
index 6053f474224368a5b7f786f24237b2c8645ea1e0..7757122776136ce25edf778709db6c4102a37b9a 100644 (file)
@@ -126,12 +126,30 @@ int GetListCountCommand::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) { 
+                       delete read;
+                       delete input;
+                       delete list;
+                       globaldata->gListVector = NULL;  
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                       return 0; 
+               }
+               
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){
                        
                                process(list);
+                               
+                               if (m->control_pressed) { 
+                                       delete read;
+                                       delete input;
+                                       delete list;
+                                       globaldata->gListVector = NULL;  
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       return 0; 
+                               }
                                                        
                                processedLabels.insert(list->getLabel());
                                userLabels.erase(list->getLabel());
@@ -144,6 +162,15 @@ int GetListCountCommand::execute(){
                                list = input->getListVector(lastLabel);
                                
                                process(list);
+                               
+                               if (m->control_pressed) { 
+                                       delete read;
+                                       delete input;
+                                       delete list;
+                                       globaldata->gListVector = NULL;  
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       return 0; 
+                               }
                                                                                                        
                                processedLabels.insert(list->getLabel());
                                userLabels.erase(list->getLabel());
@@ -177,11 +204,22 @@ int GetListCountCommand::execute(){
                        if (list != NULL) {             delete list;    }
                        list = input->getListVector(lastLabel);
                                
-                       process(list);                  
+                       process(list);  
+                       
+                       if (m->control_pressed) { 
+                                       delete read;
+                                       delete input;
+                                       delete list;
+                                       globaldata->gListVector = NULL;  
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       return 0; 
+                       }
+                       
                        delete list;  
                }
                
                delete read;
+               delete input;
                globaldata->gListVector = NULL;
                
                m->mothurOutEndLine();
@@ -211,6 +249,8 @@ void GetListCountCommand::process(ListVector* list) {
                
                //for each bin in the list vector
                for (int i = 0; i < list->getNumBins(); i++) {
+                       if (m->control_pressed) { break; }
+                       
                        binnames = list->get(i);
                        out << i+1 << '\t' << binnames << endl;
                }
index 46a04077b839ec7538f641336b9254961693eb0d..e9373a93cbf81ae6bcd84bdd063e01947994de6e 100644 (file)
@@ -244,6 +244,8 @@ int GetOTURepCommand::execute(){
                        }else{  nameMap = NULL;         }
                        
                        readMatrix->read(nameMap);
+                       
+                       if (m->control_pressed) { delete readMatrix; delete groupMap; return 0; }
 
                        //get matrix
                        if (globaldata->gListVector != NULL) {  delete globaldata->gListVector;  }
@@ -257,11 +259,14 @@ int GetOTURepCommand::execute(){
                        // via the index of a sequence in the distance matrix
                        seqVec = vector<SeqMap>(globaldata->gListVector->size()); 
                        for (MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++) {
+                               if (m->control_pressed) { delete readMatrix; delete groupMap; return 0; }
                                seqVec[currentCell->row][currentCell->column] = currentCell->dist;
                        }
                        
                        delete matrix;
                        delete readMatrix;
+                       
+                       if (m->control_pressed) {  delete groupMap; return 0; }
                }else {
                        //process file and set up indexes
                        if (format == "column") { formatMatrix = new FormatColumnMatrix(distFile); }    
@@ -276,6 +281,8 @@ int GetOTURepCommand::execute(){
                        }else{  nameMap = NULL;         }
                        
                        formatMatrix->read(nameMap);
+                       
+                       if (m->control_pressed) { delete formatMatrix; delete groupMap; return 0; }
 
                        //get matrix
                        if (globaldata->gListVector != NULL) {  delete globaldata->gListVector;  }
@@ -291,8 +298,11 @@ int GetOTURepCommand::execute(){
                        
                        //openfile for getMap to use
                        openInputFile(distFile, inRow);
+                       
+                       if (m->control_pressed) { inRow.close(); remove(distFile.c_str()); delete groupMap; return 0; }
                }
                
+               
                //globaldata->gListVector bin 0 = first name read in distance matrix, globaldata->gListVector bin 1 = second name read in distance matrix
                if (globaldata->gListVector != NULL) {
                        vector<string> names;
@@ -314,6 +324,11 @@ int GetOTURepCommand::execute(){
                
                //read fastafile
                fasta->readFastaFile(fastafile);
+               
+               if (m->control_pressed) { 
+                       if (large) {  inRow.close(); remove(distFile.c_str());  }
+                       delete groupMap; delete fasta; return 0; 
+               }
                                
                //if user gave a namesfile then use it
                if (namefile != "") {   readNamesFile();        }
@@ -332,6 +347,11 @@ int GetOTURepCommand::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) { 
+                       if (large) {  inRow.close(); remove(distFile.c_str());  }
+                       delete groupMap; delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; 
+               }
        
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
@@ -340,6 +360,13 @@ int GetOTURepCommand::execute(){
                                        error = process(list);
                                        if (error == 1) { return 0; } //there is an error in hte input files, abort command
                                        
+                                       if (m->control_pressed) { 
+                                               if (large) {  inRow.close(); remove(distFile.c_str());  }
+                                               if (groupfile != "") {  delete groupMap;  globaldata->gGroupmap = NULL; }
+                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                               delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; 
+                                       }
+                                       
                                        processedLabels.insert(list->getLabel());
                                        userLabels.erase(list->getLabel());
                        }
@@ -353,6 +380,13 @@ int GetOTURepCommand::execute(){
                                        error = process(list);
                                        if (error == 1) { return 0; } //there is an error in hte input files, abort command
                                        
+                                       if (m->control_pressed) { 
+                                               if (large) {  inRow.close(); remove(distFile.c_str());  }
+                                               if (groupfile != "") {  delete groupMap;  globaldata->gGroupmap = NULL; }
+                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                               delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; 
+                                       }
+                                       
                                        processedLabels.insert(list->getLabel());
                                        userLabels.erase(list->getLabel());
                                        
@@ -386,6 +420,13 @@ int GetOTURepCommand::execute(){
                        error = process(list);
                        delete list;
                        if (error == 1) { return 0; } //there is an error in hte input files, abort command
+                       
+                       if (m->control_pressed) { 
+                                       if (large) {  inRow.close(); remove(distFile.c_str());  }
+                                       if (groupfile != "") {  delete groupMap;  globaldata->gGroupmap = NULL; }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       delete fasta; delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; 
+                       }
                }
                
                //close and remove formatted matrix file
@@ -402,6 +443,8 @@ int GetOTURepCommand::execute(){
                        delete groupMap;  globaldata->gGroupmap = NULL;
                }
                
+               if (m->control_pressed) {  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();    }
@@ -501,6 +544,7 @@ string GetOTURepCommand::findRep(int bin, string& group, ListVector* thisList, i
                        SeqMap::iterator it;
                        SeqMap currMap;
                        for (size_t i=0; i < seqIndex.size(); i++) {
+                               if (m->control_pressed) {  return  "control"; }
                        
                                if (!large) {   currMap = seqVec[seqIndex[i]];  }
                                else            {       currMap = getMap(seqIndex[i]);  }
@@ -526,6 +570,7 @@ string GetOTURepCommand::findRep(int bin, string& group, ListVector* thisList, i
                        float min = 10000;
                        int minIndex;
                        for (size_t i=0; i < max_dist.size(); i++) {
+                               if (m->control_pressed) {  return  "control"; }
                                if (max_dist[i] < min) {
                                        min = max_dist[i];
                                        minIndex = i;
@@ -570,8 +615,13 @@ int GetOTURepCommand::process(ListVector* processList) {
                for (int i = 0; i < processList->size(); i++) {
                        string groups;
                        int binsize;
+                       
+                       if (m->control_pressed) { out.close();  newNamesOutput.close(); return 0; }
+                       
                        nameRep = findRep(i, groups, processList, binsize);
                        
+                       if (m->control_pressed) { out.close();  newNamesOutput.close(); return 0; }
+                       
                        //output to new names file
                        newNamesOutput << nameRep << '\t' << processList->get(i) << endl;
 
index 5a192c5066d6f23921e356ed7a2785abbd967631..6b68c32cad7673b950eeb8acfe6423b160630130 100644 (file)
@@ -99,9 +99,7 @@ void GetRAbundCommand::help(){
 
 //**********************************************************************************************************************
 
-GetRAbundCommand::~GetRAbundCommand(){
-       if (abort == false) {  globaldata->gListVector = NULL; }
-}
+GetRAbundCommand::~GetRAbundCommand(){}
 
 //**********************************************************************************************************************
 
@@ -122,6 +120,8 @@ int GetRAbundCommand::execute(){
                set<string> processedLabels;
                set<string> userLabels = labels;
                
+               if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete list; globaldata->gListVector = NULL;  return 0; }
+               
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){
@@ -129,6 +129,9 @@ int GetRAbundCommand::execute(){
                                        rabund = new RAbundVector();                            
                                        *rabund = (list->getRAbundVector());
                                        
+                                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
+
+                                       
                                        if(sorted)      {   rabund->print(out);                         }
                                        else            {       rabund->nonSortedPrint(out);    }
                                        
@@ -148,6 +151,8 @@ int GetRAbundCommand::execute(){
                                        rabund = new RAbundVector();
                                        *rabund = (list->getRAbundVector());
                                        
+                                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
+                                       
                                        if(sorted)      {   rabund->print(out);                         }
                                        else            {       rabund->nonSortedPrint(out);    }
 
@@ -188,6 +193,8 @@ int GetRAbundCommand::execute(){
                        rabund = new RAbundVector();
                        *rabund = (list->getRAbundVector());
                        
+                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete list; delete rabund; globaldata->gListVector = NULL;  return 0; }
+                       
                        if(sorted)      {   rabund->print(out);                         }
                        else            {       rabund->nonSortedPrint(out);    }
 
@@ -202,6 +209,9 @@ int GetRAbundCommand::execute(){
 
                
                out.close(); 
+               delete read; delete input;
+               globaldata->gListVector = NULL; 
+               
                return 0;               
        }
 
index d9197fe7724b32ca0f6789032a7ea98246bc69a5..9260a5c0fea40ce63bf77ed4f20a12f437b9a08a 100644 (file)
@@ -115,6 +115,9 @@ int GetSAbundCommand::execute(){
                set<string> processedLabels;
                set<string> userLabels = labels;
                
+               if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL;  return 0; }
+
+               
                while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
                        if(allLines == 1 || labels.count(order->getLabel()) == 1){
@@ -123,6 +126,8 @@ int GetSAbundCommand::execute(){
                                        *sabund = (order->getSAbundVector());
                                        sabund->print(out);
                                        delete sabund;
+                                       
+                                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL;  return 0; }
 
                                        processedLabels.insert(order->getLabel());
                                        userLabels.erase(order->getLabel());
@@ -139,6 +144,8 @@ int GetSAbundCommand::execute(){
                                        *sabund = (order->getSAbundVector());
                                        sabund->print(out);
                                        delete sabund;
+                                       
+                                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL;  return 0; }
 
                                        processedLabels.insert(order->getLabel());
                                        userLabels.erase(order->getLabel());
@@ -177,9 +184,13 @@ int GetSAbundCommand::execute(){
                        *sabund = (order->getSAbundVector());
                        sabund->print(out);
                        delete sabund;
+                       
+                       if (m->control_pressed) {  out.close(); remove(filename.c_str()); delete read; delete input; delete order; globaldata->gorder = NULL;  return 0; }
+                       
                        delete order;
                }
                globaldata->gorder = NULL;
+               delete read; delete input;
 
                out.close();
                
index ec0539093be68f0581b12f24170f07f726b1ee29..7535e65ed39065f3a5788c07a6a2e0580f576aaa 100644 (file)
@@ -160,6 +160,8 @@ int GetSeqsCommand::execute(){
                //get names you want to keep
                readAccnos();
                
+               if (m->control_pressed) { return 0; }
+               
                //read through the correct file and output lines you want to keep
                if (fastafile != "")            {               readFasta();    }
                else if (namefile != "")        {               readName();             }
@@ -167,6 +169,8 @@ int GetSeqsCommand::execute(){
                else if (alignfile != "")       {               readAlign();    }
                else if (listfile != "")        {               readList();             }
                
+               if (m->control_pressed) { return 0; }
+               
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -184,7 +188,7 @@ int GetSeqsCommand::execute(){
 }
 
 //**********************************************************************************************************************
-void GetSeqsCommand::readFasta(){
+int GetSeqsCommand::readFasta(){
        try {
                if (outputDir == "") { outputDir += hasPath(fastafile); }
                string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "pick" +  getExtension(fastafile);
@@ -199,6 +203,9 @@ void GetSeqsCommand::readFasta(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -221,6 +228,8 @@ void GetSeqsCommand::readFasta(){
                        m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -229,7 +238,7 @@ void GetSeqsCommand::readFasta(){
        }
 }
 //**********************************************************************************************************************
-void GetSeqsCommand::readList(){
+int GetSeqsCommand::readList(){
        try {
                if (outputDir == "") { outputDir += hasPath(listfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + "pick" +  getExtension(listfile);
@@ -242,6 +251,9 @@ void GetSeqsCommand::readList(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+                       
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+
                        //read in list vector
                        ListVector list(in);
                        
@@ -286,6 +298,8 @@ void GetSeqsCommand::readList(){
                        m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -294,7 +308,7 @@ void GetSeqsCommand::readList(){
        }
 }
 //**********************************************************************************************************************
-void GetSeqsCommand::readName(){
+int GetSeqsCommand::readName(){
        try {
                if (outputDir == "") { outputDir += hasPath(namefile); }
                string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" +  getExtension(namefile);
@@ -310,6 +324,8 @@ void GetSeqsCommand::readName(){
                
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
 
                        in >> firstCol;                         
                        in >> secondCol;                        
@@ -370,6 +386,8 @@ void GetSeqsCommand::readName(){
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "GetSeqsCommand", "readName");
@@ -378,7 +396,7 @@ void GetSeqsCommand::readName(){
 }
 
 //**********************************************************************************************************************
-void GetSeqsCommand::readGroup(){
+int GetSeqsCommand::readGroup(){
        try {
                if (outputDir == "") { outputDir += hasPath(groupfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile);
@@ -394,6 +412,9 @@ void GetSeqsCommand::readGroup(){
                
                while(!in.eof()){
 
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+
+
                        in >> name;                             //read from first column
                        in >> group;                    //read from second column
                        
@@ -415,6 +436,8 @@ void GetSeqsCommand::readGroup(){
                        m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -425,7 +448,7 @@ void GetSeqsCommand::readGroup(){
 
 //**********************************************************************************************************************
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
-void GetSeqsCommand::readAlign(){
+int GetSeqsCommand::readAlign(){
        try {
                if (outputDir == "") { outputDir += hasPath(alignfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report";
@@ -447,6 +470,9 @@ void GetSeqsCommand::readAlign(){
                out << endl;
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+
 
                        in >> name;                             //read from first column
                        
@@ -483,6 +509,8 @@ void GetSeqsCommand::readAlign(){
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "GetSeqsCommand", "readAlign");
@@ -491,7 +519,7 @@ void GetSeqsCommand::readAlign(){
 }
 //**********************************************************************************************************************
 
-void GetSeqsCommand::readAccnos(){
+int GetSeqsCommand::readAccnos(){
        try {
                
                ifstream in;
@@ -505,7 +533,9 @@ void GetSeqsCommand::readAccnos(){
                        
                        gobble(in);
                }
-               in.close();             
+               in.close();     
+               
+               return 0;
 
        }
        catch(exception& e) {
index 809109c486de9f00b39091b863da8a23dfc95a96..b574afe38734a789fa39985090012cff358d2e95 100644 (file)
@@ -27,12 +27,12 @@ class GetSeqsCommand : public Command {
                string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir;
                bool abort;
                
-               void readFasta();
-               void readName();
-               void readGroup();
-               void readAlign();
-               void readAccnos();
-               void readList();
+               int readFasta();
+               int readName();
+               int readGroup();
+               int readAlign();
+               int readAccnos();
+               int readList();
                
 };
 
index 2e553d96db111a7a0828af855eb7251081014131..7f8755645ce6664c5a299073e0ae1cbc6e875025 100644 (file)
@@ -168,6 +168,8 @@ int GetSharedOTUCommand::execute(){
                int error = groupMap->readMap();
                if (error == 1) { delete groupMap; return 0; }
                
+               if (m->control_pressed) { delete groupMap; return 0; }
+               
                globaldata->gGroupmap = groupMap;
                
                if (Groups.size() == 0) {
@@ -189,6 +191,8 @@ int GetSharedOTUCommand::execute(){
                        openInputFile(fastafile, inFasta);
                        
                        while(!inFasta.eof()) {
+                               if (m->control_pressed) { inFasta.close(); delete groupMap; return 0; }
+                               
                                Sequence seq(inFasta); gobble(inFasta);
                                if (seq.getName() != "") {  seqs.push_back(seq);   }
                        }
@@ -208,6 +212,12 @@ int GetSharedOTUCommand::execute(){
                //as long as you are not at the end of the file or done wih the lines you want
                while((!in.eof()) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
+                       if (m->control_pressed) { 
+                               if (lastlist != NULL) {         delete lastlist;        }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }  
+                               delete groupMap; return 0;
+                       }
+                       
                        list = new ListVector(in);
                        
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){                       
@@ -267,6 +277,7 @@ int GetSharedOTUCommand::execute(){
                
                if (lastlist != NULL) {         delete lastlist;        }
                
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); }  delete groupMap; return 0; } 
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -283,7 +294,7 @@ int GetSharedOTUCommand::execute(){
        }
 }
 /***********************************************************/
-void GetSharedOTUCommand::process(ListVector* shared) {
+int GetSharedOTUCommand::process(ListVector* shared) {
        try {
                
                map<string, string> fastaMap;
@@ -304,6 +315,7 @@ void GetSharedOTUCommand::process(ListVector* shared) {
                                
                //go through each bin, find out if shared
                for (int i = 0; i < shared->getNumBins(); i++) {
+                       if (m->control_pressed) { outNames.close(); remove(outputFileNames.c_str()); return 0; }
                        
                        bool uniqueOTU = true;
                        
@@ -405,6 +417,8 @@ void GetSharedOTUCommand::process(ListVector* shared) {
                        outputNames.push_back(outputFileFasta);
                        
                        for (int k = 0; k < seqs.size(); k++) {
+                               if (m->control_pressed) { outFasta.close(); return 0; }
+                       
                                //if this is a sequence we want, output it
                                it = fastaMap.find(seqs[k].getName());
                                if (it != fastaMap.end()) {
@@ -421,7 +435,8 @@ void GetSharedOTUCommand::process(ListVector* shared) {
                        
                        outFasta.close();
                }
-
+               
+               return 0;
                
        }
        catch(exception& e) {
index c12cc13ab074abcd78b259ce9fff9606ecc3509d..30a5cd2468ab7ec8bb741729f4cb390e8a8f7c1d 100644 (file)
@@ -41,7 +41,7 @@ class GetSharedOTUCommand : public Command {
                vector<Sequence> seqs;
                vector<string> outputNames;
                
-               void process(ListVector*);
+               int process(ListVector*);
                
 };
 //**********************************************************************************************************************
index 8d0662f9c404cb05d4cfed74596a33284d5235d9..939cdb9040e67c62416f76cda30b86dbead73654 100644 (file)
@@ -30,6 +30,8 @@ int GroupMap::readMap() {
                        fileHandle >> seqName;                  //read from first column
                        fileHandle >> seqGroup;                 //read from second column
                        
+                       if (m->control_pressed) {  fileHandle.close();  return 1; }
+                       
                        setNamesOfGroups(seqGroup);
                        
                        it = groupmap.find(seqName);
index 7da10a271125fadf7e4833ea37e68ce24cfcd16f..07deaa5991c94627fa2e02a88e3b10b2729e290e 100644 (file)
@@ -502,7 +502,7 @@ vector<seqDist> HCluster::getSeqsAN(){
 }
 
 /***********************************************************************/
-void HCluster::combineFile() {
+int HCluster::combineFile() {
        try {
                //int bufferSize = 64000;  //512k - this should be a variable that the user can set to optimize code to their hardware
                //char* inputBuffer;
@@ -552,6 +552,8 @@ void HCluster::combineFile() {
                           
                           in >> first >> second >> dist; gobble(in);
                           
+                          if (m->control_pressed) { in.close(); out.close(); remove(tempDistFile.c_str()); return 0; }
+                          
                           //while there are still values in mergedMin that are smaller than the distance read from file
                           while (count < mergedMin.size())  {
                           
@@ -623,8 +625,8 @@ void HCluster::combineFile() {
                mergedMin.clear();
                        
                //rename tempfile to distfile
-               int renameOK = remove(distfile.c_str());
-               int ok = rename(tempDistFile.c_str(), distfile.c_str());
+               remove(distfile.c_str());
+               rename(tempDistFile.c_str(), distfile.c_str());
 //cout << "remove = "<< renameOK << " rename = " << ok << endl;        
 
                //merge clustered rows averaging the distances
@@ -648,6 +650,8 @@ void HCluster::combineFile() {
 
                //sort merged values
                sort(mergedMin.begin(), mergedMin.end(), compareSequenceDistance);      
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "HCluster", "combineFile");
@@ -731,7 +735,7 @@ seqDist HCluster::getNextDist(char* buffer, int& index, int size){
        }
 }
 /***********************************************************************/
-void HCluster::processFile() {
+int HCluster::processFile() {
        try {
                string firstName, secondName;
                float distance;
@@ -745,6 +749,7 @@ void HCluster::processFile() {
        
                //get entry
                while (!in.eof()) {
+                       if (m->control_pressed) { in.close(); out.close(); remove(outTemp.c_str()); return 0; }
                        
                        in >> firstName >> secondName >> distance;    gobble(in);               
                        
@@ -766,6 +771,8 @@ void HCluster::processFile() {
                
                remove(distfile.c_str());
                rename(outTemp.c_str(), distfile.c_str());
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "HCluster", "processFile");
index 5005ec6c55c9edc608a1ecbf73e65affea0a88a2..78406505a1665dfa7eb95e7a8c0733ee0a7e7f5e 100644 (file)
@@ -38,8 +38,8 @@ protected:
        void updateMap();
        vector<seqDist> getSeqsFNNN();
        vector<seqDist> getSeqsAN();
-       void combineFile();
-       void processFile();
+       int combineFile();
+       int processFile();
        //seqDist getNextDist(char*, int&, int);
                
        RAbundVector* rabund;
index e6875b6af18d71bb0f78341f2a04bfc2c002886d..d9a14d9b5979636dba434733a132d35c25de8568 100644 (file)
@@ -192,6 +192,16 @@ int HClusterCommand::execute(){
                        read = new ReadCluster(distfile, cutoff);       
                        read->setFormat(format);
                        read->read(globaldata->nameMap);
+                       
+                       if (m->control_pressed) {  
+                               delete read; 
+                               sabundFile.close();
+                               rabundFile.close();
+                               listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0;  
+                       }
+                       
                        distfile = read->getOutputFile();
                
                        list = read->getListVector();
@@ -199,7 +209,15 @@ int HClusterCommand::execute(){
                }else {
                        list = new ListVector(globaldata->nameMap->getListVector());
                }
-       
+               
+               if (m->control_pressed) {  
+                       sabundFile.close();
+                       rabundFile.close();
+                       listFile.close();
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                       return 0;  
+               }
+
                m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); m->mothurOutEndLine();
                estart = time(NULL);
        
@@ -221,15 +239,44 @@ int HClusterCommand::execute(){
                cluster = new HCluster(rabund, list, method, distfile, globaldata->nameMap, cutoff);
                vector<seqDist> seqs; seqs.resize(1); // to start loop
                
+               if (m->control_pressed) {  
+                               delete cluster;
+                               sabundFile.close();
+                               rabundFile.close();
+                               listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0;  
+               }
+
+               
                while (seqs.size() != 0){
                
                        seqs = cluster->getSeqs();
-                               
-                       for (int i = 0; i < seqs.size(); i++) {  //-1 means skip me
+                       
+                       if (m->control_pressed) {  
+                               delete cluster;
+                               sabundFile.close();
+                               rabundFile.close();
+                               listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0;  
+                       }
 
+                       for (int i = 0; i < seqs.size(); i++) {  //-1 means skip me
+                               
                                if (seqs[i].seq1 != seqs[i].seq2) {
                                        cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
                                        
+                                       if (m->control_pressed) {  
+                                               delete cluster;
+                                               sabundFile.close();
+                                               rabundFile.close();
+                                               listFile.close();
+                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                               return 0;  
+                                       }
+
+                                       
                                        float rndDist = roundDist(seqs[i].dist, precision);
                                        
                                        if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){
@@ -247,6 +294,15 @@ int HClusterCommand::execute(){
                        }
                }
 
+               if (m->control_pressed) {  
+                       delete cluster;
+                       sabundFile.close();
+                       rabundFile.close();
+                       listFile.close();
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                       return 0;  
+               }
+                                       
                if(previousDist <= 0.0000){
                        printData("unique");
                }
@@ -270,6 +326,12 @@ int HClusterCommand::execute(){
                listFile.close();
                delete cluster;
                
+               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();    }
index d05c700dd9dddfd9482ba6016c12f155e38362a9..3dca535b8600e38f29cf87160ab5a487282280d5 100644 (file)
@@ -44,6 +44,8 @@ string HeatMap::getPic(RAbundVector* rabund) {
                for(int i=0;i<rabund->size();i++){
                        float relAbund = rabund->get(i) / (float)rabund->getNumSeqs();
                        
+                       if (m->control_pressed) { return "control"; }
+                       
                        if (rabund->get(i) != 0) { //don't want log value of 0.
                                if (scaler == "log10") {
                                        scaleRelAbund[i] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund))) + "0000";  
@@ -78,6 +80,7 @@ string HeatMap::getPic(RAbundVector* rabund) {
                
                y = 70;
                for (int i = 0; i < scaleRelAbund.size(); i++) {
+                       if (m->control_pressed) { outsvg.close(); return "control"; }
                        
                        outsvg << "<rect fill=\"#" + scaleRelAbund[i] + "\" stroke=\"#" + scaleRelAbund[i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
                        y += 5;
@@ -118,6 +121,7 @@ string HeatMap::getPic(vector<SharedRAbundVector*> lookup) {
                for(int i=0;i<lookup.size();i++){
                        scaleRelAbund[i].assign(lookup[i]->size(), "");
                        for(int j=0;j<lookup[i]->size();j++){
+                               if (m->control_pressed) {  return "control"; }
                                float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs();
                                
                                if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
@@ -160,6 +164,7 @@ string HeatMap::getPic(vector<SharedRAbundVector*> lookup) {
                y = 70;
                for (int i = 0; i < scaleRelAbund[0].size(); i++) {
                        for (int j = 0; j < scaleRelAbund.size(); j++) {
+                               if (m->control_pressed) { outsvg.close(); return "control"; }
                                
                                outsvg << "<rect fill=\"#" + scaleRelAbund[j][i] + "\" stroke=\"#" + scaleRelAbund[j][i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
                                x += 300;
index a91ef9db9d93b6ad7e65a4705bbe7ad789884a45..5d7e1d635fd4e56893edcacfad7eaca6960f86d1 100644 (file)
@@ -74,10 +74,6 @@ HeatMapCommand::HeatMapCommand(string option) {
                 
                        scale = validParameter.validFile(parameters, "scale", false);                           if (scale == "not found") { scale = "log10"; }
                        
-                       if (abort == false) {
-                               heatmap = new HeatMap(sorted, scale, outputDir);
-                               format = globaldata->getFormat();
-                       }
                }
 
        }
@@ -115,10 +111,6 @@ void HeatMapCommand::help(){
 //**********************************************************************************************************************
 
 HeatMapCommand::~HeatMapCommand(){
-       if (abort == false) {
-               delete read;
-               delete heatmap;
-       }
 }
 
 //**********************************************************************************************************************
@@ -127,27 +119,25 @@ int HeatMapCommand::execute(){
        try {
        
                if (abort == true) { return 0; }
+               
+               heatmap = new HeatMap(sorted, scale, outputDir);
+               format = globaldata->getFormat();
 
                string lastLabel;
-       
+               
+               read = new ReadOTUFile(globaldata->inputFileName);      
+               read->read(&*globaldata); 
+               input = globaldata->ginput;
+               
                if (format == "sharedfile") {
                        //you have groups
-                       read = new ReadOTUFile(globaldata->inputFileName);      
-                       read->read(&*globaldata); 
-                       
-                       input = globaldata->ginput;
                        lookup = input->getSharedRAbundVectors();
                        lastLabel = lookup[0]->getLabel();
        
                }else if ((format == "list") || (format == "rabund") || (format == "sabund")) {
                        //you are using just a list file and have only one group
-                       read = new ReadOTUFile(globaldata->inputFileName);      
-                       read->read(&*globaldata); 
-               
                        rabund = globaldata->rabund;
                        lastLabel = rabund->getLabel();
-                       input = globaldata->ginput;     
-
                }
                
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
@@ -158,6 +148,12 @@ int HeatMapCommand::execute(){
                
                        //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) {
+                                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+                                       for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  remove(outputNames[i].c_str());  } }
+                                       globaldata->Groups.clear(); 
+                                       delete read; delete heatmap; return 0;
+                               }
                
                                if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
        
@@ -192,6 +188,13 @@ int HeatMapCommand::execute(){
                                lookup = input->getSharedRAbundVectors();                               
                        }
                        
+                       
+                       if (m->control_pressed) {
+                               for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  remove(outputNames[i].c_str());  } }
+                               globaldata->Groups.clear(); 
+                               delete read; delete heatmap; return 0;
+                       }
+
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -215,14 +218,16 @@ int HeatMapCommand::execute(){
                                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
                        }
                
-                       
-                       
                        //reset groups parameter
                        globaldata->Groups.clear();  
                        
                }else{
        
                        while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+                               if (m->control_pressed) {   
+                                       for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  remove(outputNames[i].c_str());  } }
+                                       delete rabund;  delete read; delete heatmap; return 0;  
+                               }
 
                                if(allLines == 1 || labels.count(rabund->getLabel()) == 1){                     
        
@@ -256,6 +261,11 @@ int HeatMapCommand::execute(){
                                rabund = input->getRAbundVector();
                        }
                        
+                       if (m->control_pressed) {
+                               for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  remove(outputNames[i].c_str());  } }
+                               delete read; delete heatmap; return 0;
+                       }
+
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -285,10 +295,18 @@ int HeatMapCommand::execute(){
                globaldata->rabund = NULL;
                delete input; globaldata->ginput = NULL;
                
+               if (m->control_pressed) {
+                       for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  remove(outputNames[i].c_str());  } }
+                       delete read; delete heatmap; 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();    }
                m->mothurOutEndLine();
+               
+               delete read;
+               delete heatmap;
 
                return 0;
        }
index 9a1255037c4312291238b613d39929c7b50549b5..4fb3e37365fdba3dbec421a5c7495314803a6755 100644 (file)
@@ -32,9 +32,11 @@ vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Cal
                vector<string> outputNames;
                                
                //make file for each calculator selected
-               for (int m = 0; m < calcs.size(); m++) {
-                       
-                       string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[m]->getName() + ".heatmap.sim.svg";
+               for (int k = 0; k < calcs.size(); k++) {
+               
+                       if (m->control_pressed) { return outputNames; }
+               
+                       string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[k]->getName() + ".heatmap.sim.svg";
                        openOutputFile(filenamesvg, outsvg);
                        outputNames.push_back(filenamesvg);
                        
@@ -60,12 +62,14 @@ vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Cal
                        //get sim for each comparison and save them so you can find the relative similairity
                        for(int i = 0; i < (lookup.size()-1); i++){
                                for(int j = (i+1); j < lookup.size(); j++){
-                                       
+                                               
+                                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                                               
                                                vector<SharedRAbundVector*> subset;
                                                subset.push_back(lookup[i]);  subset.push_back(lookup[j]); 
                                        
                                                //get similairity between groups
-                                               data = calcs[m]->getValues(subset);
+                                               data = calcs[k]->getValues(subset);
                                                sims.push_back(data[0]);
                                        
                                                //save biggest similairity to set relative sim
@@ -133,6 +137,8 @@ string HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups)
                //get sim for each comparison and save them so you can find the relative similairity
                for(int i = 0; i < (dists.size()-1); i++){
                        for(int j = (i+1); j < dists.size(); j++){
+                       
+                               if (m->control_pressed) { outsvg.close(); return filenamesvg; }
                                
                                float sim = 1.0 - dists[i][j];
                                sims.push_back(sim);
index 1b4b9d79010b22391ed29e148c8b3f9137ac1b3f..dc67a8d4374ae90aebf182ce80d5474b17431f95 100644 (file)
@@ -240,6 +240,8 @@ int HeatMapSimCommand::execute(){
                delete heatmap;
                delete validCalculator;
                
+               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();    }
@@ -273,9 +275,13 @@ int HeatMapSimCommand::runCommandShared() {
                set<string> processedLabels;
                set<string> userLabels = labels;
                
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  globaldata->Groups.clear(); return 0; }
+               
                //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) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } globaldata->Groups.clear(); return 0; }
+
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
        
                                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
@@ -311,7 +317,10 @@ int HeatMapSimCommand::runCommandShared() {
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                        lookup = input->getSharedRAbundVectors();                               
                }
+               
                        
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear();  return 0; }
+
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -325,6 +334,8 @@ int HeatMapSimCommand::runCommandShared() {
                        }
                }
                
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL;  globaldata->Groups.clear(); return 0; }
+               
                //run last label if you need to
                if (needToRun == true)  {
                        for (int i = 0; i < lookup.size(); i++) {  if (lookup[i] != NULL) { delete lookup[i]; } } 
@@ -337,6 +348,7 @@ int HeatMapSimCommand::runCommandShared() {
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                }
                
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL;  globaldata->Groups.clear(); return 0; }
                        
                //reset groups parameter
                globaldata->Groups.clear();  
@@ -407,7 +419,9 @@ int HeatMapSimCommand::runCommandDist() {
                                        in >> name;             
                                        names.push_back(name);
                                        
-                                       for(int j=0;j<numSeqs;j++) {  in >> matrix[i][j];  }
+                                       if (m->control_pressed) { return 0; }
+                                       
+                                       for(int j=0;j<numSeqs;j++) { in >> matrix[i][j];  }
                                        gobble(in);
                                }
                        }else { 
@@ -416,6 +430,8 @@ int HeatMapSimCommand::runCommandDist() {
                                        in >> name;     
                                        names.push_back(name);  
                                        
+                                       if (m->control_pressed) { return 0; }
+                                       
                                        for(int j=0;j<i;j++){
                                                in >> dist;
                                                matrix[i][j] = dist;  matrix[j][i] = dist;
@@ -448,6 +464,8 @@ int HeatMapSimCommand::runCommandDist() {
                        while (!in.eof()) {
                                in >> first >> second >> dist; gobble(in);
                                
+                               if (m->control_pressed) { return 0; }
+                               
                                map<string, int>::iterator itA = nameMap->find(first);
                                map<string, int>::iterator itB = nameMap->find(second);
                                
diff --git a/knn.cpp b/knn.cpp
index c11626a082ac9003785fd937e87b922e3bf8025a..93a7aa33faa6e2e1d9cb43c0505464056cbb1f08 100644 (file)
--- a/knn.cpp
+++ b/knn.cpp
@@ -20,6 +20,8 @@ string Knn::getTaxonomy(Sequence* seq) {
                //use database to find closest seq
 
                vector<int> closest = database->findClosestSequences(seq, num);
+               
+               if (m->control_pressed) { return tax; }
 
                vector<string> closestNames;
                for (int i = 0; i < closest.size(); i++) {
@@ -59,6 +61,7 @@ string Knn::findCommonTaxonomy(vector<string> closest)  {
                int smallest = 100;
                
                for (int i = 0; i < closest.size(); i++) {
+                       if (m->control_pressed) { return "control"; }
                
                        string tax = taxonomy[closest[i]];  //we know its there since we checked in getTaxonomy
                
@@ -73,6 +76,7 @@ string Knn::findCommonTaxonomy(vector<string> closest)  {
                //start at the highest level all the closest seqs have
                string common = "";
                for (int i = (smallest-1); i >= 0; i--) {
+                       if (m->control_pressed) { return "control"; }
 
                        string thistax = taxons[0][i];
                        int num = 0;
index 93db3be8f6142875fdf158519005b994dd8ca2db..219b0bf5fcb7149ff20ee7d65563ec1932147bf0 100644 (file)
@@ -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,7 +211,7 @@ int LibShuffCommand::execute(){
 
 //**********************************************************************************************************************
 
-void LibShuffCommand::printCoverageFile() {
+int LibShuffCommand::printCoverageFile() {
        try {
 
                ofstream outCov;
@@ -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,7 +307,7 @@ void LibShuffCommand::printCoverageFile() {
 
 //**********************************************************************************************************************
 
-void LibShuffCommand::printSummaryFile() {
+int LibShuffCommand::printSummaryFile() {
        try {
 
                ofstream outSum;
@@ -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");
index 5155cbd7982eada5dc20480067a5c34e051d30dc..1c8fbc4da656bf5c4240c1be8cb4a7843b3ac72c 100644 (file)
@@ -29,8 +29,8 @@ private:
        vector<string> groupNames;
        
        void setGroups();
-       void printCoverageFile();
-       void printSummaryFile();
+       int printCoverageFile();
+       int printSummaryFile();
 
        GlobalData* globaldata;
        FullMatrix* matrix;
index f3710c9e4d0aabd728c0714d0f8b7d41c0b73c24..d23949f497e65b262e3067d74d566d4665124412 100644 (file)
@@ -151,6 +151,8 @@ int ListSeqsCommand::execute(){
                else if (alignfile != "")       {       inputFileName = alignfile;      readAlign();    }
                else if (listfile != "")        {       inputFileName = listfile;       readList();             }
                
+               if (m->control_pressed) { return 0; }
+               
                //sort in alphabetical order
                sort(names.begin(), names.end());
                
@@ -163,10 +165,15 @@ int ListSeqsCommand::execute(){
                
                //output to .accnos file
                for (int i = 0; i < names.size(); i++) {
+                       
+                       if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; }
+                       
                        out << names[i] << endl;
                }
                out.close();
                
+               if (m->control_pressed) { remove(outputFileName.c_str()); return 0; }
+
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(outputFileName); m->mothurOutEndLine();    
@@ -182,7 +189,7 @@ int ListSeqsCommand::execute(){
 }
 
 //**********************************************************************************************************************
-void ListSeqsCommand::readFasta(){
+int ListSeqsCommand::readFasta(){
        try {
                
                ifstream in;
@@ -190,6 +197,9 @@ void ListSeqsCommand::readFasta(){
                string name;
                
                while(!in.eof()){
+                       
+                       if (m->control_pressed) { in.close(); return 0; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -197,7 +207,9 @@ void ListSeqsCommand::readFasta(){
                        
                        gobble(in);
                }
-               in.close();             
+               in.close();     
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -206,7 +218,7 @@ void ListSeqsCommand::readFasta(){
        }
 }
 //**********************************************************************************************************************
-void ListSeqsCommand::readList(){
+int ListSeqsCommand::readList(){
        try {
                ifstream in;
                openInputFile(listfile, in);
@@ -219,6 +231,8 @@ void ListSeqsCommand::readList(){
                        for (int i = 0; i < list.getNumBins(); i++) {
                                string binnames = list.get(i);
                                
+                               if (m->control_pressed) { in.close(); return 0; }
+                               
                                while (binnames.find_first_of(',') != -1) { 
                                        string name = binnames.substr(0,binnames.find_first_of(','));
                                        binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
@@ -230,6 +244,8 @@ void ListSeqsCommand::readList(){
                }
                in.close();     
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "ListSeqsCommand", "readList");
@@ -238,7 +254,7 @@ void ListSeqsCommand::readList(){
 }
 
 //**********************************************************************************************************************
-void ListSeqsCommand::readName(){
+int ListSeqsCommand::readName(){
        try {
                
                ifstream in;
@@ -246,6 +262,8 @@ void ListSeqsCommand::readName(){
                string name, firstCol, secondCol;
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); return 0; }
 
                        in >> firstCol;                         
                        in >> secondCol;                        
@@ -263,6 +281,7 @@ void ListSeqsCommand::readName(){
                        gobble(in);
                }
                in.close();
+               return 0;
                
        }
        catch(exception& e) {
@@ -272,7 +291,7 @@ void ListSeqsCommand::readName(){
 }
 
 //**********************************************************************************************************************
-void ListSeqsCommand::readGroup(){
+int ListSeqsCommand::readGroup(){
        try {
        
                ifstream in;
@@ -280,7 +299,9 @@ void ListSeqsCommand::readGroup(){
                string name, group;
                
                while(!in.eof()){
-
+                       
+                       if (m->control_pressed) { in.close(); return 0; }
+                       
                        in >> name;                             //read from first column
                        in >> group;                    //read from second column
                        
@@ -289,6 +310,7 @@ void ListSeqsCommand::readGroup(){
                        gobble(in);
                }
                in.close();
+               return 0;
 
        }
        catch(exception& e) {
@@ -299,7 +321,7 @@ void ListSeqsCommand::readGroup(){
 
 //**********************************************************************************************************************
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
-void ListSeqsCommand::readAlign(){
+int ListSeqsCommand::readAlign(){
        try {
        
                ifstream in;
@@ -314,6 +336,8 @@ void ListSeqsCommand::readAlign(){
                
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); return 0; }
 
                        in >> name;                             //read from first column
                        
@@ -328,6 +352,8 @@ void ListSeqsCommand::readAlign(){
                        gobble(in);
                }
                in.close();
+               
+               return 0;
 
                
        }
index 04d9e1da99ae079bd9b10d2ba3e30d5b0ba2f01c..391ec9a46b9f09671f79fbc0f895730338570d4c 100644 (file)
@@ -26,11 +26,11 @@ class ListSeqsCommand : public Command {
                string fastafile, namefile, groupfile, alignfile, inputFileName, outputDir, listfile;
                bool abort;
                
-               void readFasta();
-               void readName();
-               void readGroup();
-               void readAlign();
-               void readList();
+               int readFasta();
+               int readName();
+               int readGroup();
+               int readAlign();
+               int readList();
                
 };
 
index 76689e9f11bf1ab3547ef9a33053830a7b436d14..f06884fcad747a84e8c3d8ae673a5eabf839f2ec 100644 (file)
@@ -34,6 +34,8 @@ string Maligner::getResults(Sequence* q, DeCalculator* decalc) {
                        refSeqs = getKmerSeqs(query, numWanted); //fills indexes
                }else { m->mothurOut("not valid search."); exit(1);  } //should never get here
                
+               if (m->control_pressed) { return chimera;  }
+               
                refSeqs = minCoverageFilter(refSeqs);
 
                if (refSeqs.size() < 2)  { 
@@ -46,7 +48,8 @@ string Maligner::getResults(Sequence* q, DeCalculator* decalc) {
 
                //fills outputResults
                chimera = chimeraMaligner(chimeraPenalty, decalc);
-       
+               
+               if (m->control_pressed) { return chimera;  }
                                
                //free memory
                delete query;
@@ -77,10 +80,14 @@ string Maligner::chimeraMaligner(int chimeraPenalty, DeCalculator* decalc) {
 
                vector< vector<score_struct> > matrix = buildScoreMatrix(query->getAligned().length(), refSeqs.size()); //builds and initializes
                
+               if (m->control_pressed) { return chimera;  }
+               
                fillScoreMatrix(matrix, refSeqs, chimeraPenalty);
        
                vector<score_struct> path = extractHighestPath(matrix);
                
+               if (m->control_pressed) { return chimera;  }
+               
                vector<trace_struct> trace = mapTraceRegionsToAlignment(path, refSeqs);
        
                if (trace.size() > 1) {         chimera = "yes";        }
@@ -95,6 +102,8 @@ string Maligner::chimeraMaligner(int chimeraPenalty, DeCalculator* decalc) {
        
                percentIdenticalQueryChimera = computePercentID(queryInRange, chimeraSeq);
                
+               if (m->control_pressed) { return chimera;  }
+               
                //save output results
                for (int i = 0; i < trace.size(); i++) {
                        int regionStart = trace[i].col;
index 078f411d669426daed4dcc1f09f65810644350ad..390f47f9fac6f255ce6e30fec4c7b2264e25cdad 100644 (file)
@@ -193,10 +193,14 @@ int MatrixOutputCommand::execute(){
                if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); return 0;}
                
                numGroups = lookup.size();
+               
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } globaldata->Groups.clear(); return 0;  }
                                
                //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) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+               
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
                                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
                                process(lookup);
@@ -228,6 +232,8 @@ int MatrixOutputCommand::execute(){
                        lookup = input->getSharedRAbundVectors();
                }
                
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -241,6 +247,8 @@ int MatrixOutputCommand::execute(){
                        }
                }
                
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+
                //run last label if you need to
                if (needToRun == true)  {
                        for (int i = 0; i < lookup.size(); i++) {  if (lookup[i] != NULL) {  delete lookup[i]; }  } 
@@ -251,7 +259,8 @@ int MatrixOutputCommand::execute(){
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                }
                
-                               
+               if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0;  }
+               
                //reset groups parameter
                globaldata->Groups.clear();  
                
@@ -301,7 +310,7 @@ void MatrixOutputCommand::printSims(ostream& out) {
        }
 }
 /***********************************************************/
-void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
+int MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
        try {
        
                                EstOutput data;
@@ -313,9 +322,9 @@ void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                                        //initialize simMatrix
                                        simMatrix.clear();
                                        simMatrix.resize(numGroups);
-                                       for (int m = 0; m < simMatrix.size(); m++)      {
+                                       for (int p = 0; p < simMatrix.size(); p++)      {
                                                for (int j = 0; j < simMatrix.size(); j++)      {
-                                                       simMatrix[m].push_back(0.0);
+                                                       simMatrix[p].push_back(0.0);
                                                }
                                        }
                                
@@ -324,6 +333,8 @@ void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                                                        if (k != l) { //we dont need to similiarity of a groups to itself
                                                                //get estimated similarity between 2 groups
                                                                
+                                                               if (m->control_pressed) { return 0; }
+                                                               
                                                                subset.clear(); //clear out old pair of sharedrabunds
                                                                //add new pair of sharedrabunds
                                                                subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
@@ -345,7 +356,7 @@ void MatrixOutputCommand::process(vector<SharedRAbundVector*> thisLookup){
                                        
                                }
 
-       
+                               return 0;
                
        }
        catch(exception& e) {
index 521104c395382d5ce15c61f99510c830ae054f7a..537f7916299d36c7f628a9e7e6974821746f3b12 100644 (file)
@@ -33,7 +33,7 @@ public:
        
 private:
        void printSims(ostream&);
-       void process(vector<SharedRAbundVector*>);
+       int process(vector<SharedRAbundVector*>);
        
        GlobalData* globaldata;
        ReadOTUFile* read;
index 7e17b051305014e2aa58831fddfabaad63f319d4..a076281035ff08fdb2ba0af591dce24f726cd636 100644 (file)
@@ -97,6 +97,8 @@ int MergeFileCommand::execute(){
                        openInputFile(fileNames[i], inputFile);
                        
                        while(!inputFile.eof()){        
+                               if (m->control_pressed) { inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0;  }
+                       
                                c = inputFile.get(); 
                                //-1 is eof char
                                if (int(c) != -1) { outputFile << c; }   
@@ -107,6 +109,8 @@ int MergeFileCommand::execute(){
                
                outputFile.close();
                
+               if (m->control_pressed) { remove(outputFileName.c_str()); return 0;  }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(outputFileName); m->mothurOutEndLine();    
index bf0b82b3973edce4353325d3364010bdadd20c54..6d5acb2386ad0ccd836ee41d2d8f5b24c5e4048e 100644 (file)
@@ -164,6 +164,8 @@ int MGClusterCommand::execute(){
                list = new ListVector(nameMap->getListVector());
                RAbundVector* rabund = new RAbundVector(list->getRAbundVector());
                
+               if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; return 0; }
+               
                start = time(NULL);
                oldList = *list;
                
@@ -176,6 +178,12 @@ int MGClusterCommand::execute(){
                openOutputFile(fileroot+ tag + ".rabund",  rabundFile);
                openOutputFile(fileroot+ tag + ".sabund",  sabundFile);
                
+               if (m->control_pressed) { 
+                       delete nameMap; delete read; delete list; delete rabund; 
+                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                       return 0; 
+               }
+               
                if (!hclusterWanted) {
                        //get distmatrix and overlap
                        SparseMatrix* distMatrix = read->getDistMatrix();
@@ -188,10 +196,23 @@ int MGClusterCommand::execute(){
                        else if(method == "average"){   cluster = new AverageLinkage(rabund, list, distMatrix, cutoff, method); }
                        cluster->setMapWanted(true);
                        
+                       if (m->control_pressed) { 
+                               delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster;
+                               listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                               return 0; 
+                       }
+                       
                        //cluster using cluster classes
                        while (distMatrix->getSmallDist() < cutoff && distMatrix->getNNodes() > 0){
                                
                                cluster->update(cutoff);
+                               
+                               if (m->control_pressed) { 
+                                       delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster;
+                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                       return 0; 
+                               }
+                               
                                float dist = distMatrix->getSmallDist();
                                float rndDist = roundDist(dist, precision);
                                
@@ -203,6 +224,13 @@ int MGClusterCommand::execute(){
                                        if (merge) {
                                                map<string, int> seq2Bin = cluster->getSeqtoBin();
                                                ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+                                               
+                                               if (m->control_pressed) { 
+                                                       delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp;
+                                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                                       return 0; 
+                                               }
+                                               
                                                temp->setLabel(toString(rndPreviousDist,  precisionLength-1));
                                                printData(temp);
                                                delete temp;
@@ -225,6 +253,13 @@ int MGClusterCommand::execute(){
                                if (merge) {
                                        map<string, int> seq2Bin = cluster->getSeqtoBin();
                                        ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+                                       
+                                       if (m->control_pressed) { 
+                                                       delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp;
+                                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                                       return 0; 
+                                       }
+                                       
                                        temp->setLabel(toString(rndPreviousDist,  precisionLength-1));
                                        printData(temp);
                                        delete temp;
@@ -247,6 +282,12 @@ int MGClusterCommand::execute(){
                
                        //sort the distance and overlap files
                        sortHclusterFiles(distFile, overlapFile);
+                       
+                       if (m->control_pressed) { 
+                               delete nameMap;  delete list; delete rabund; 
+                               listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                               return 0; 
+                       }
                
                        //create cluster
                        hcluster = new HCluster(rabund, list, method, distFile, nameMap, cutoff);
@@ -255,16 +296,38 @@ int MGClusterCommand::execute(){
                        vector<seqDist> seqs; seqs.resize(1); // to start loop
                        //ifstream inHcluster;
                        //openInputFile(distFile, inHcluster);
+                       
+                       if (m->control_pressed) { 
+                               delete nameMap;  delete list; delete rabund; delete hcluster;
+                               listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                               return 0; 
+                       }
 
                        while (seqs.size() != 0){
                
                                seqs = hcluster->getSeqs();
                                
+                               if (m->control_pressed) { 
+                                       delete nameMap;  delete list; delete rabund; delete hcluster;
+                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                       remove(distFile.c_str());
+                                       remove(overlapFile.c_str());
+                                       return 0; 
+                               }
+                               
                                for (int i = 0; i < seqs.size(); i++) {  //-1 means skip me
                                        
                                        if (seqs[i].seq1 != seqs[i].seq2) {
                
                                                hcluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
+                                               
+                                               if (m->control_pressed) { 
+                                                       delete nameMap;  delete list; delete rabund; delete hcluster;
+                                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                                       remove(distFile.c_str());
+                                                       remove(overlapFile.c_str());
+                                                       return 0; 
+                                               }
        
                                                float rndDist = roundDist(seqs[i].dist, precision);
                                                                                                
@@ -276,6 +339,15 @@ int MGClusterCommand::execute(){
                                                        if (merge) {
                                                                map<string, int> seq2Bin = hcluster->getSeqtoBin();
                                                                ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+                                                               
+                                                               if (m->control_pressed) { 
+                                                                       delete nameMap;  delete list; delete rabund; delete hcluster; delete temp;
+                                                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                                                       remove(distFile.c_str());
+                                                                       remove(overlapFile.c_str());
+                                                                       return 0; 
+                                                               }
+
                                                                temp->setLabel(toString(rndPreviousDist,  precisionLength-1));
                                                                printData(temp);
                                                                delete temp;
@@ -301,6 +373,15 @@ int MGClusterCommand::execute(){
                                if (merge) {
                                        map<string, int> seq2Bin = hcluster->getSeqtoBin();
                                        ListVector* temp = mergeOPFs(seq2Bin, rndPreviousDist);
+                                       
+                                       if (m->control_pressed) { 
+                                                       delete nameMap; delete list; delete rabund; delete hcluster; delete temp;
+                                                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                                                       remove(distFile.c_str());
+                                                       remove(overlapFile.c_str());
+                                                       return 0; 
+                                       }
+                                       
                                        temp->setLabel(toString(rndPreviousDist,  precisionLength-1));
                                        printData(temp);
                                        delete temp;
@@ -324,6 +405,14 @@ int MGClusterCommand::execute(){
                globaldata->setListFile(fileroot+ tag + ".list");
                globaldata->setFormat("list");
                
+               if (m->control_pressed) { 
+                       delete nameMap; 
+                       listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str());
+                       globaldata->setListFile("");
+                       globaldata->setFormat("");
+                       return 0; 
+               }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                m->mothurOut(fileroot+ tag + ".list"); m->mothurOutEndLine();   
@@ -373,6 +462,10 @@ ListVector* MGClusterCommand::mergeOPFs(map<string, int> binInfo, float dist){
                }else { if (overlapMatrix.size() == 0)  {  done = true;  } } 
                
                while (!done) {
+                       if (m->control_pressed) { 
+                               if (hclusterWanted) {   inOverlap.close();  }           
+                               return newList;
+                       }
                        
                        //get next overlap
                        seqDist overlapNode;
index 7cd77a1c2fd8fec087e740a7340f4a74c19ea801..a3eef76a2766d5ae69c824b0ee4cf4b5e3f14a51 100644 (file)
@@ -24,6 +24,13 @@ void ctrlc_handler ( int sig ) {
        MothurOut* m = MothurOut::getInstance();
     ctrlc_pressed = 1;
        m->control_pressed = ctrlc_pressed;
+       
+       if (m->executing) { //if mid command quit execution, else quit mothur
+               m->mothurOutEndLine(); m->mothurOut("quitting command...");  m->mothurOutEndLine();
+       }else{
+               m->mothurOut("quitting mothur");  m->mothurOutEndLine();
+               exit(1);
+       }
 }
 /***********************************************************************/
 int main(int argc, char *argv[]){
index ac1ec3fd402af357cc956a816df8de6dc27f9e29..d9c8e5ddcbd435980dbc4f70bfbfa31799f74233 100644 (file)
@@ -25,6 +25,7 @@ class MothurOut {
                void mothurOutJustToLog(string);
                void errorOut(exception&, string, string);
                int control_pressed;
+               bool executing;
                
 
        private:
index a8a3531a67e97dd8669bbc24b83d2e930356e98c..05d6443725be6028411573b6ee280220cb52ff0c 100644 (file)
@@ -110,6 +110,8 @@ int OtuHierarchyCommand::execute(){
                //get listvectors that correspond to labels requested, (or use smart distancing to get closest listvector)
                vector<ListVector> lists = getListVectors();
                
+               if (m->control_pressed) { return 0; }
+               
                //determine which is little and which is big, putting little first
                if (lists.size() == 2) {
                        //if big is first swap them
@@ -123,6 +125,9 @@ int OtuHierarchyCommand::execute(){
                //map sequences to bin number in the "little" otu
                map<string, int> littleBins; 
                for (int i = 0; i < lists[0].getNumBins(); i++) {
+               
+                       if (m->control_pressed) {  return 0; }
+                       
                        string names = lists[0].get(i); 
                        
                        //parse bin
@@ -143,6 +148,8 @@ int OtuHierarchyCommand::execute(){
                //go through each bin in "big" otu and output the bins in "little" otu which created it
                for (int i = 0; i < lists[1].getNumBins(); i++) {
                
+                       if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; }
+                       
                        string names = lists[1].get(i);
                        
                        //output column 1
@@ -174,6 +181,8 @@ int OtuHierarchyCommand::execute(){
                
                out.close();
                
+               if (m->control_pressed) { remove(outputFileName.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(outputFileName); m->mothurOutEndLine();    
@@ -216,6 +225,8 @@ vector<ListVector> OtuHierarchyCommand::getListVectors() {
                }
                
                while ((list != NULL) && (userLabels.size() != 0)) {
+               
+                       if (m->control_pressed) {  in.close(); delete list;  return lists; }
                        
                        //is this a listvector that we want?
                        if(labels.count(list->getLabel()) == 1){
@@ -264,7 +275,7 @@ vector<ListVector> OtuHierarchyCommand::getListVectors() {
                        }else { list = NULL; }
                }
                
-                                               
+               if (m->control_pressed) { in.close();  return lists; }                          
                
                //output error messages about any remaining user labels
                set<string>::iterator it;
@@ -279,6 +290,8 @@ vector<ListVector> OtuHierarchyCommand::getListVectors() {
                        }
                }
                
+               if (m->control_pressed) {  in.close(); return lists; }
+               
                //run last label if you need to
                if (needToRun == true)  {
                        if (list != NULL) {     delete list;    }
@@ -295,7 +308,7 @@ vector<ListVector> OtuHierarchyCommand::getListVectors() {
                        }
                }
                
-               
+               in.close();
                return lists;
        }
        catch(exception& e) {
index 4838988346bb962d7ef91d32c483cf2e379f5895..9955a19f677dd96cccf7b9f4171e0f7d28b9deac 100644 (file)
@@ -143,13 +143,27 @@ int ParseListCommand::execute(){
                list = input->getListVector();
                string lastLabel = list->getLabel();
                
+               if (m->control_pressed) { 
+                       delete input; delete list; delete groupMap;
+                       for (i=0; i<groupMap->namesOfGroups.size(); i++) {  (*(filehandles[groupMap->namesOfGroups[i]])).close();  delete filehandles[groupMap->namesOfGroups[i]]; } 
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                       return 0;
+               }
+               
                while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+               
+                       if (m->control_pressed) { 
+                               delete input; delete list; delete groupMap;
+                               for (i=0; i<groupMap->namesOfGroups.size(); i++) {  (*(filehandles[groupMap->namesOfGroups[i]])).close();  delete filehandles[groupMap->namesOfGroups[i]]; } 
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                               return 0;
+                       }
                        
                        if(allLines == 1 || labels.count(list->getLabel()) == 1){
                                        
-                                       parse(list);
                                        m->mothurOut(list->getLabel()); m->mothurOutEndLine();
-                                       
+                                       parse(list);
+                                                                               
                                        processedLabels.insert(list->getLabel());
                                        userLabels.erase(list->getLabel());
                        }
@@ -160,8 +174,8 @@ int ParseListCommand::execute(){
                                        delete list;
                                        list = input->getListVector(lastLabel); //get new list vector to process
                                        
-                                       parse(list);
                                        m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+                                       parse(list);
                                        
                                        processedLabels.insert(list->getLabel());
                                        userLabels.erase(list->getLabel());
@@ -177,6 +191,13 @@ int ParseListCommand::execute(){
                        list = input->getListVector(); //get new list vector to process
                }
                
+               if (m->control_pressed) { 
+                               delete input; delete groupMap;
+                               for (i=0; i<groupMap->namesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close();  delete filehandles[groupMap->namesOfGroups[i]]; } 
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                               return 0;
+               }
+               
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -191,13 +212,20 @@ int ParseListCommand::execute(){
 
                }
                
+               if (m->control_pressed) { 
+                               delete input; delete groupMap;
+                               for (i=0; i<groupMap->namesOfGroups.size(); i++) {  (*(filehandles[groupMap->namesOfGroups[i]])).close();  delete filehandles[groupMap->namesOfGroups[i]]; } 
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                               return 0;
+               }
+               
                //run last label if you need to
                if (needToRun == true)  {
                        if (list != NULL) {     delete list;    }
                        list = input->getListVector(lastLabel); //get new list vector to process
                        
-                       parse(list);            
                        m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+                       parse(list);            
                        
                        delete list;
                }
@@ -207,7 +235,14 @@ int ParseListCommand::execute(){
                        delete it3->second;
                }
                
+               
                delete groupMap;
+               delete input;
+               
+               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();
@@ -222,7 +257,7 @@ int ParseListCommand::execute(){
        }
 }
 /**********************************************************************************************************************/
-void ParseListCommand::parse(ListVector* thisList) {
+int ParseListCommand::parse(ListVector* thisList) {
        try {
        
                map<string, string> groupVector;
@@ -237,6 +272,7 @@ void ParseListCommand::parse(ListVector* thisList) {
 
                
                for (int i = 0; i < thisList->getNumBins(); i++) {
+                       if (m->control_pressed) { return 0; }
                        
                        map<string, string> groupBins;
                        string bin = list->get(i); 
@@ -270,7 +306,8 @@ void ParseListCommand::parse(ListVector* thisList) {
                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
                        (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl;  // label numBins  listvector for that group
                }
-
+               
+               return 0;
 
        }
        catch(exception& e) {
index 8f91017fc6af754030a1940fc818e9d83217e33b..c765bcdd86c34c89b688685969e89d55928809f6 100644 (file)
@@ -25,7 +25,7 @@ public:
        void help();
        
 private:
-       void parse(ListVector*);
+       int parse(ListVector*);
                
        ListVector* list;
        GroupMap* groupMap;
index 16c7748e76a50337df471e414543ac982a19a6b0..0487822764bbf36e11da5bd8faada1bba34a63c4 100644 (file)
@@ -49,6 +49,9 @@ EstOutput Parsimony::getValues(Tree* t) {
                                }
                
                                for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
+                               
+                                       if (m->control_pressed) { return data; }
+                                       
                                        int lc = copyTree->tree[i].getLChild();
                                        int rc = copyTree->tree[i].getRChild();
                        
@@ -97,6 +100,9 @@ EstOutput Parsimony::getValues(Tree* t) {
 //                     map<string,int>::iterator it;
                        
                        for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
+                       
+                               if (m->control_pressed) { return data; }
+                               
                                int lc = copyTree->tree[i].getLChild();
                                int rc = copyTree->tree[i].getRChild();
                        
index 393c0f8930eac7649ba18f0dc7db344ed9ebed56..b87e9c0b1ea0f5e84cbdf87a341c2fc6d393699d 100644 (file)
@@ -131,6 +131,15 @@ int ParsimonyCommand::execute() {
                Progress* reading;
                reading = new Progress("Comparing to random:", iters);
                
+               if (m->control_pressed) { 
+                       delete reading; delete pars; delete util; delete output;
+                       if (randomtree == "") {  outSum.close();  }
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                       globaldata->Groups.clear();
+                       return 0;
+               }
+                       
+               
                //get pscore for users tree
                userData.resize(numComp,0);  //data = AB, AC, BC, ABC.
                randomData.resize(numComp,0);  //data = AB, AC, BC, ABC.
@@ -145,6 +154,15 @@ int ParsimonyCommand::execute() {
                        //get pscores for users trees
                        for (int i = 0; i < T.size(); i++) {
                                userData = pars->getValues(T[i]);  //data = AB, AC, BC, ABC.
+                               
+                               if (m->control_pressed) { 
+                                       delete reading; delete pars; delete util; delete output;
+                                       if (randomtree == "") {  outSum.close();  }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
+
 
                                //output scores for each combination
                                for(int k = 0; k < numComp; k++) {
@@ -165,6 +183,7 @@ int ParsimonyCommand::execute() {
                        
                        //get pscores for random trees
                        for (int j = 0; j < iters; j++) {
+                                                               
                                //create new tree with same num nodes and leaves as users
                                randT = new Tree();
 
@@ -173,6 +192,14 @@ int ParsimonyCommand::execute() {
 
                                //get pscore of random tree
                                randomData = pars->getValues(randT);
+                               
+                               if (m->control_pressed) { 
+                                       delete reading; delete pars; delete util; delete output; delete randT;
+                                       if (randomtree == "") {  outSum.close();  }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
                                        
                                for(int r = 0; r < numComp; r++) {
                                        //add trees pscore to map of scores
@@ -196,14 +223,32 @@ int ParsimonyCommand::execute() {
                }else {
                        //get pscores for random trees
                        for (int j = 0; j < iters; j++) {
+                                                               
                                //create new tree with same num nodes and leaves as users
                                randT = new Tree();
                                //create random relationships between nodes
 
                                randT->assembleRandomTree();
+                               
+                               if (m->control_pressed) { 
+                                       delete reading; delete pars; delete util; delete output; delete randT;
+                                       globaldata->gTreemap = savetmap; 
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
+
 
                                //get pscore of random tree
                                randomData = pars->getValues(randT);
+                               
+                               if (m->control_pressed) { 
+                                       delete reading; delete pars; delete util; delete output; delete randT;
+                                       globaldata->gTreemap = savetmap; 
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                                       globaldata->Groups.clear();
+                                       return 0;
+                               }
                        
                                for(int r = 0; r < numComp; r++) {
                                        //add trees pscore to map of scores
@@ -253,6 +298,15 @@ int ParsimonyCommand::execute() {
                        }
                }
                
+               if (m->control_pressed) { 
+                               delete reading; delete pars; delete util; delete output;
+                               if (randomtree == "") {  outSum.close();  }
+                               else { globaldata->gTreemap = savetmap; }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                               globaldata->Groups.clear();
+                               return 0;
+               }
+               
                //finish progress bar
                reading->finish();
                delete reading;
@@ -271,6 +325,12 @@ int ParsimonyCommand::execute() {
                //reset groups parameter
                globaldata->Groups.clear(); 
                
+               if (m->control_pressed) { 
+                       delete pars; delete util; delete output;
+                       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();    }
@@ -319,7 +379,7 @@ void ParsimonyCommand::printParsimonyFile() {
        }
 }
 /***********************************************************/
-void ParsimonyCommand::printUSummaryFile() {
+int ParsimonyCommand::printUSummaryFile() {
        try {
                //column headers
                outSum << "Tree#" << '\t' << "Groups" << '\t'  <<  "ParsScore" << '\t' << "ParsSig" <<  endl;
@@ -332,6 +392,7 @@ void ParsimonyCommand::printUSummaryFile() {
                //print each line
                for (int i = 0; i< T.size(); i++) {
                        for(int a = 0; a < numComp; a++) {
+                               if (m->control_pressed) {  outSum.close(); return 0; }
                                if (UScoreSig[a][i] > (1/(float)iters)) {
                                        outSum << setprecision(6) << i+1 << '\t' << groupComb[a]  << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl;
                                        cout << setprecision(6) << i+1 << '\t' << groupComb[a]  << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl;
@@ -345,6 +406,7 @@ void ParsimonyCommand::printUSummaryFile() {
                }
                
                outSum.close();
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ParsimonyCommand", "printUSummaryFile");
index 071aea8fa742d5fb3172f4ac7dcf61125ae73b90..6fa1914f31e320517ff89389a34fc3e5a1cd6dc6 100644 (file)
@@ -59,7 +59,7 @@ private:
        vector<string> Groups, outputNames; //holds groups to be used
 
        void printParsimonyFile();  
-       void printUSummaryFile();
+       int printUSummaryFile();
        void getUserInput();
        
 };
index 644473a8baa2b86253118e7b766b0e965fcb80a8..c9fecd58ca08d9103770dd5f0e3afd7f2274c89d 100644 (file)
@@ -97,17 +97,11 @@ int PCACommand::execute(){
                vector<string> names;
                vector<vector<double> > D;
        
-               //fbase = filename;
-               //if(fbase.find_last_of(".")!=string::npos){
-               //      fbase.erase(fbase.find_last_of(".")+1); 
-               //}
-               //else{
-               //      fbase += ".";
-               //}
-               
                fbase = outputDir + getRootName(getSimpleName(filename));
                
                read(filename, names, D);
+               
+               if (m->control_pressed) { return 0; }
        
                double offset = 0.0000;
                vector<double> d;
@@ -116,19 +110,22 @@ int PCACommand::execute(){
                vector<vector<double> > copy_G;
                //int rank = D.size();
                
-               cout << "\nProcessing...\n";
+               m->mothurOut("\nProcessing...\n");
                
                for(int count=0;count<2;count++){
-                       recenter(offset, D, G);   
-                       tred2(G, d, e);
-                       qtli(d, e, G);
+                       recenter(offset, D, G);         if (m->control_pressed) { return 0; }
+                       tred2(G, d, e);                         if (m->control_pressed) { return 0; }
+                       qtli(d, e, G);                          if (m->control_pressed) { return 0; }
                        offset = d[d.size()-1];
                        if(offset > 0.0) break;
                } 
                
+               if (m->control_pressed) { return 0; }
                
                output(fbase, names, G, d);
                
+               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();    }
@@ -164,7 +161,7 @@ void PCACommand::get_comment(istream& f, char begin, char end){
 
 /*********************************************************************************************************************************/
 
-void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
+int PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list, vector<vector<double> >& d){
        try {
                //     int count1=0;
                //     int count2=0;
@@ -181,6 +178,8 @@ void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list
                                f >> name_list[i];
                                //                      cout << i << "\t" << name_list[i] << endl;
                                for(int j=0;j<rank;j++) {
+                                       if (m->control_pressed) { return 0; }
+                                       
                                        f >> d[i][j];
                                        if (d[i][j] == -0.0000)
                                                d[i][j] = 0.0000;
@@ -197,6 +196,7 @@ void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list
                                f >> name_list[i];
                                d[i][i]=0.0000;
                                for(int j=0;j<i;j++){
+                                       if (m->control_pressed) { return 0; }
                                        f >> d[i][j];
                                        if (d[i][j] == -0.0000)
                                                d[i][j] = 0.0000;
@@ -204,6 +204,8 @@ void PCACommand::read_phylip(istream& f, int square_m, vector<string>& name_list
                                }
                        }
                }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "PCACommand", "read_phylip");
index 220e91f162e75b9b5d5f9d75ecfc6e3474e50549..089d1c102f38d66bfa0d83c2120dd3d3f1cd883e 100644 (file)
@@ -30,7 +30,7 @@ private:
        vector<string> outputNames;
        
        void get_comment(istream&, char, char);
-       void read_phylip(istream&, int, vector<string>&, vector<vector<double> >&);
+       int read_phylip(istream&, int, vector<string>&, vector<vector<double> >&);
        void read(string, vector<string>&, vector<vector<double> >&);
        double pythag(double, double);
        void matrix_mult(vector<vector<double> >, vector<vector<double> >, vector<vector<double> >&);
index e3b47d863f3803b4d6d1ae7355a863b540f776c5..410ada9e4ec921fd8f0ba3ddb5aa362fd0390995 100644 (file)
@@ -121,6 +121,8 @@ int PhylotypeCommand::execute(){
                //make it as long as the longest taxonomy in the file 
                TaxEqualizer* taxEqual = new TaxEqualizer(taxonomyFileName, cutoff);
                
+               if (m->control_pressed) { delete taxEqual; return 0; }
+               
                string equalizedTaxFile = taxEqual->getEqualizedTaxFile();
                
                delete taxEqual;
@@ -135,6 +137,8 @@ int PhylotypeCommand::execute(){
                bool done = false;
                if (tree->get(leaves[0]).parent == -1) {  m->mothurOut("Empty Tree"); m->mothurOutEndLine();    done = true;    }
                
+               if (m->control_pressed) { delete tree; return 0; }
+               
                string fileroot = outputDir + getRootName(getSimpleName(taxonomyFileName));
                
                ofstream outList;
@@ -158,6 +162,12 @@ int PhylotypeCommand::execute(){
                        string level = toString(count); 
                        count++;
                        
+                       if (m->control_pressed) { 
+                               outRabund.close(); outSabund.close(); outList.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               delete tree; return 0; 
+                       }
+                       
                        //is this a level the user want output for
                        if(allLines == 1 || labels.count(level) == 1){  
                                
@@ -216,6 +226,11 @@ int PhylotypeCommand::execute(){
                
                delete tree;
                
+               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();    }
index a2c72702cc7f766501f705226fe4441abcf7ed24..6e9e95c9f7eaf20f91ba312b93a52be67c82b828 100644 (file)
@@ -37,7 +37,7 @@ Pintail::~Pintail() {
        }
 }
 //***************************************************************************************************************
-void Pintail::doPrep() {
+int Pintail::doPrep() {
        try {
                
                mergedFilterString = "";
@@ -70,6 +70,7 @@ void Pintail::doPrep() {
                if (consfile == "") { 
                        m->mothurOut("Calculating probability of conservation for your template sequences.  This can take a while...  I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command.  Providing the .freq file will improve speed.    "); cout.flush();
                        probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFileName)); 
+                       if (m->control_pressed) {  return 0;  }
                        m->mothurOut("Done."); m->mothurOutEndLine();
                }else                           {   probabilityProfile = readFreq();    m->mothurOut("Done.");            }
                m->mothurOutEndLine();
@@ -87,6 +88,11 @@ void Pintail::doPrep() {
                        
                        vector<Sequence*> tempQuerySeqs;
                        while(!in.eof()){
+                               if (m->control_pressed) {  
+                                       for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
+                                       return 0; 
+                               }
+                               
                                Sequence* s = new Sequence(in);
                                gobble(in);
                                
@@ -103,12 +109,21 @@ void Pintail::doPrep() {
                            reRead = true;
                                //mask templates
                                for (int i = 0; i < temp.size(); i++) {
+                                       if (m->control_pressed) {  
+                                               for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
+                                               return 0; 
+                                       }
                                        decalc->runMask(temp[i]);
                                }
                        }
 
                        mergedFilterString = createFilter(temp, 0.5);
                        
+                       if (m->control_pressed) {  
+                               for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
+                               return 0; 
+                       }
+                       
                        //reread template seqs
                        for (int i = 0; i < tempQuerySeqs.size(); i++) { delete tempQuerySeqs[i];  }
                }
@@ -124,6 +139,7 @@ void Pintail::doPrep() {
                                reRead = true;
                                //mask templates
                                for (int i = 0; i < templateSeqs.size(); i++) {
+                                       if (m->control_pressed) {  return 0;  }
                                        decalc->runMask(templateSeqs[i]);
                                }
                        }
@@ -131,6 +147,7 @@ void Pintail::doPrep() {
                        if (filter) { 
                                reRead = true;
                                for (int i = 0; i < templateSeqs.size(); i++) {
+                                       if (m->control_pressed) {  return 0;  }
                                        runFilter(templateSeqs[i]);
                                }
                        }
@@ -140,6 +157,7 @@ void Pintail::doPrep() {
                                quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, 0, templateSeqs.size());
                        }else {         createProcessesQuan();          }
                
+                       if (m->control_pressed) {  return 0;  }
                        
                        ofstream out4, out5;
                        string noOutliers, outliers;
@@ -154,11 +172,10 @@ void Pintail::doPrep() {
                                noOutliers = outputDir + getRootName(getSimpleName(templateFileName)) + "pintail.filtered." + getSimpleName(getRootName(fastafile)) + "quan";
                        }
 
-
-
-                                               
                        decalc->removeObviousOutliers(quantilesMembers, templateSeqs.size());
                        
+                       if (m->control_pressed) {  return 0;  }
+                       
                        openOutputFile(noOutliers, out5);                       
                        //adjust quantiles
                        for (int i = 0; i < quantilesMembers.size(); i++) {
@@ -210,6 +227,8 @@ void Pintail::doPrep() {
                //free memory
                for (int i = 0; i < templateLines.size(); i++) { delete templateLines[i];  }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "Pintail", "doPrep");
@@ -217,7 +236,7 @@ void Pintail::doPrep() {
        }
 }
 //***************************************************************************************************************
-void Pintail::print(ostream& out, ostream& outAcc) {
+int Pintail::print(ostream& out, ostream& outAcc) {
        try {
                int index = ceil(deviation);
                
@@ -247,6 +266,7 @@ void Pintail::print(ostream& out, ostream& outAcc) {
                for (int m = 0; m < expectedDistance.size(); m++) {  out << expectedDistance[m] << '\t';  }
                out << endl;
                
+               return 0;
                
        }
        catch(exception& e) {
@@ -265,6 +285,8 @@ int Pintail::getChimeras(Sequence* query) {
                //find pairs has to be done before a mask
                bestfit = findPairs(query);
                
+               if (m->control_pressed) {  return 0; } 
+               
                //if they mask  
                if (seqMask != "") {
                        decalc->runMask(query);
@@ -286,8 +308,12 @@ int Pintail::getChimeras(Sequence* query) {
 
                //find observed distance
                obsDistance = decalc->calcObserved(query, bestfit, windowsForeachQuery, windowSizes);
+               
+               if (m->control_pressed) {  return 0; } 
                                
                Qav = decalc->findQav(windowsForeachQuery, windowSizes, probabilityProfile);
+               
+               if (m->control_pressed) {  return 0; } 
 
                //find alpha                    
                seqCoef = decalc->getCoef(obsDistance, Qav);
@@ -295,9 +321,13 @@ int Pintail::getChimeras(Sequence* query) {
                //calculating expected distance
                expectedDistance = decalc->calcExpected(Qav, seqCoef);
                
+               if (m->control_pressed) {  return 0; } 
+               
                //finding de
                DE = decalc->calcDE(obsDistance, expectedDistance);
                
+               if (m->control_pressed) {  return 0; } 
+               
                //find distance between query and closest match
                it = trimmed.begin();
                deviation = decalc->calcDist(query, bestfit, it->first, it->second); 
index 2364c86c6bab6d779cb13131245d626244777895..59d4feeec7fa3743a059b331db524b0df3fe48cf 100644 (file)
--- a/pintail.h
+++ b/pintail.h
@@ -28,7 +28,7 @@ class Pintail : public Chimera {
                ~Pintail();
                
                int getChimeras(Sequence*);
-               void print(ostream&, ostream&);
+               int print(ostream&, ostream&);
                
                void setCons(string c)          { consfile = c;  }
                void setQuantiles(string q) { quanfile = q;  }
@@ -72,7 +72,7 @@ class Pintail : public Chimera {
                Sequence* findPairs(Sequence*);
                        
                void createProcessesQuan();
-               void doPrep();
+               int doPrep();
                
 };
 
index 66efd469fcf8631d8537b6c7e90ea066ef72c028..215b5bd07981a39b79af57bff95da745b3aa0632 100644 (file)
@@ -117,6 +117,8 @@ int PreClusterCommand::execute(){
                
                //reads fasta file and return number of seqs
                int numSeqs = readFASTA(); //fills alignSeqs and makes all seqs active
+               
+               if (m->control_pressed) { return 0; }
        
                if (numSeqs == 0) { m->mothurOut("Error reading fasta file...please correct."); m->mothurOutEndLine(); return 0;  }
                if (diffs > length) { m->mothurOut("Error: diffs is greater than your sequence length."); m->mothurOutEndLine(); return 0;  }
@@ -139,6 +141,9 @@ int PreClusterCommand::execute(){
                                
                                //try to merge it with all smaller seqs
                                for (int j = i+1; j < numSeqs; j++) {
+                                       
+                                       if (m->control_pressed) { return 0; }
+                                       
                                        if (alignSeqs[j].active) {  //this sequence has not been merged yet
                                                //are you within "diff" bases
                                                int mismatch = calcMisMatches(alignSeqs[i].seq.getAligned(), alignSeqs[j].seq.getAligned());
@@ -166,11 +171,14 @@ int PreClusterCommand::execute(){
                string newFastaFile = fileroot + "precluster" + getExtension(fastafile);
                string newNamesFile = fileroot + "precluster.names";
                
+               if (m->control_pressed) { return 0; }
                
                m->mothurOut("Total number of sequences before precluster was " + toString(alignSeqs.size()) + "."); m->mothurOutEndLine();
                m->mothurOut("pre.cluster removed " + toString(count) + " sequences."); m->mothurOutEndLine(); 
                printData(newFastaFile, newNamesFile);
                
+               if (m->control_pressed) { remove(newFastaFile.c_str()); remove(newNamesFile.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                m->mothurOut(newFastaFile); m->mothurOutEndLine();      
@@ -202,7 +210,9 @@ int PreClusterCommand::readFASTA(){
                length = 0;
                
                while (!inFasta.eof()) {
-       
+                       
+                       if (m->control_pressed) { inFasta.close(); return 0; }
+                       
                        //inNames >> firstCol >> secondCol;
                        //nameString = secondCol;
                        
index 186a86edf2329ed75a5edb30f88a96528f79436d..ff93b348e521009fac30e72bc3e0c34f46327400 100644 (file)
@@ -34,6 +34,8 @@ Progress::Progress(){
 
 Progress::Progress(string job, int end){
        try {
+               m = MothurOut::getInstance();
+               
                m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n");
                cout << setw(20) << left << job << setw(1) << marker;
                m->mothurOutJustToLog(job);
@@ -42,6 +44,7 @@ Progress::Progress(string job, int end){
 
                nTicks = 0;
                finalPos = end;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "Progress", "Progress");
index 6acc24ce9df500338873829216e5c1b3754d7df7..f5e7952688cdbb1dd182ca44df9c152ef46879d9 100644 (file)
@@ -12,7 +12,7 @@
 
 /***********************************************************************/
 
-void Rarefact::getCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getCurve(int increment = 1, int nIters = 1000){
        try {
                RarefactionCurveData* rcd = new RarefactionCurveData();
                for(int i=0;i<displays.size();i++){
@@ -31,6 +31,8 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                
                        for(int i=0;i<numSeqs;i++){
                        
+                               if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0;  }
+                       
                                int binNumber = order->get(i);
                                int abundance = lookup->get(binNumber);
                        
@@ -61,6 +63,7 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                        displays[i]->close();
                }
                delete rcd;
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "Rarefact", "getCurve");
@@ -70,7 +73,7 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
 
 /***********************************************************************/
 
-void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
 try {
                SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
                
@@ -106,6 +109,8 @@ try {
                        vector<SharedRAbundVector*> subset;
                        //send each group one at a time
                        for (int k = 0; k < lookup.size(); k++) { 
+                               if (m->control_pressed) {  delete merge; delete rcd; return 0;  }
+                               
                                subset.clear(); //clears out old pair of sharedrabunds
                                //add in new pair of sharedrabunds
                                subset.push_back(merge); subset.push_back(lookup[k]);
@@ -127,6 +132,7 @@ try {
                }
                
                delete rcd;
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "Rarefact", "getSharedCurve");
index 9e903ea759094dfa0f76453801f63111be92315b..9eab51d12303577405227e9c26cdcf9506e8a857 100644 (file)
@@ -17,8 +17,8 @@ public:
                                         lookup(shared), displays(disp) {  globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); }
 
        ~Rarefact(){};
-       void getCurve(int, int);
-       void getSharedCurve(int, int);
+       int getCurve(int, int);
+       int getSharedCurve(int, int);
        
 private:
        GlobalData* globaldata;
index c98b833ffcb1e70d9d24e9c18f1eec638c75c127..566561e9e695c3f74f7ffb1ce0b1d56ee0e3bc20 100644 (file)
@@ -133,11 +133,15 @@ int RareFactCommand::execute(){
                if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName);  }
                else {  inputFileNames = parseSharedFile(globaldata->getSharedFile());  globaldata->setFormat("rabund");  }
                
+               if (m->control_pressed) { return 0; }
+               
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
                        string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
                        globaldata->inputFileName = inputFileNames[p];
                        
+                       if (m->control_pressed) { return 0; }
+                       
                        if (inputFileNames.size() > 1) {
                                m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
                        }
@@ -185,7 +189,7 @@ int RareFactCommand::execute(){
                        
                        
                        //if the users entered no valid calculators don't execute command
-                       if (rDisplays.size() == 0) { return 0; }
+                       if (rDisplays.size() == 0) { for(int i=0;i<rDisplays.size();i++){       delete rDisplays[i];    } delete validCalculator; return 0; }
                        
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
@@ -198,16 +202,21 @@ int RareFactCommand::execute(){
                        set<string> processedLabels;
                        set<string> userLabels = labels;
                        
+                       if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){  delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; delete order; globaldata->gorder = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+                       
                        //as long as you are not at the end of the file or done wih the lines you want
                        while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                                
+                               if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){  delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; delete order; globaldata->gorder = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
+                               
                                if(allLines == 1 || labels.count(order->getLabel()) == 1){
                                        
+                                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        rCurve = new Rarefact(order, rDisplays);
                                        rCurve->getCurve(freq, nIters);
                                        delete rCurve;
                                        
-                                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        processedLabels.insert(order->getLabel());
                                        userLabels.erase(order->getLabel());
                                }
@@ -218,11 +227,11 @@ int RareFactCommand::execute(){
                                        delete order;
                                        order = (input->getOrderVector(lastLabel));
                                        
+                                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        rCurve = new Rarefact(order, rDisplays);
                                        rCurve->getCurve(freq, nIters);
                                        delete rCurve;
                                        
-                                       m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                        processedLabels.insert(order->getLabel());
                                        userLabels.erase(order->getLabel());
                                        
@@ -236,6 +245,8 @@ int RareFactCommand::execute(){
                                order = (input->getOrderVector());
                        }
                        
+                       if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){  delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }  return 0; }
+
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -249,16 +260,18 @@ int RareFactCommand::execute(){
                                }
                        }
                        
+                       if (m->control_pressed) { for(int i=0;i<rDisplays.size();i++){  delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = NULL;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
                        //run last label if you need to
                        if (needToRun == true)  {
                                if (order != NULL) {    delete order;   }
                                order = (input->getOrderVector(lastLabel));
                                
+                               m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                rCurve = new Rarefact(order, rDisplays);
                                rCurve->getCurve(freq, nIters);
                                delete rCurve;
                                
-                               m->mothurOut(order->getLabel()); m->mothurOutEndLine();
                                delete order;
                        }
                        
@@ -272,7 +285,8 @@ int RareFactCommand::execute(){
                        
                }
                
-               
+               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();    }
index b53e87dceb21cb87ec26e88828479808feddb69a..37b54d1b850dbd9e72ca56fe4e506fa9a78439b4 100644 (file)
@@ -170,6 +170,15 @@ int RareFactSharedCommand::execute(){
                input = globaldata->ginput;
                lookup = input->getSharedRAbundVectors();
                string lastLabel = lookup[0]->getLabel();
+               
+               if (m->control_pressed) { 
+                       globaldata->Groups.clear(); 
+                       for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
+                       return 0;
+               }
+
 
                if (lookup.size() < 2) { 
                        m->mothurOut("I cannot run the command without at least 2 valid groups."); 
@@ -183,14 +192,20 @@ int RareFactSharedCommand::execute(){
        
                //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) { 
+                               globaldata->Groups.clear(); 
+                               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                               for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
+                               return 0;
+                       }
                        
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
-                               
+                               m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
                                rCurve = new Rarefact(lookup, rDisplays);
                                rCurve->getSharedCurve(freq, nIters);
                                delete rCurve;
                        
-                               m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
                                processedLabels.insert(lookup[0]->getLabel());
                                userLabels.erase(lookup[0]->getLabel());
                        }
@@ -221,6 +236,13 @@ int RareFactSharedCommand::execute(){
                        lookup = input->getSharedRAbundVectors();
                }
                
+               if (m->control_pressed) { 
+                               globaldata->Groups.clear(); 
+                               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                               return 0;
+               }
+               
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -234,6 +256,13 @@ int RareFactSharedCommand::execute(){
                        }
                }
                
+               if (m->control_pressed) { 
+                               globaldata->Groups.clear(); 
+                               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                               return 0;
+               }
+               
                //run last label if you need to
                if (needToRun == true)  {
                        for (int i = 0; i < lookup.size(); i++) {  if (lookup[i] != NULL) {     delete lookup[i]; }  } 
@@ -251,6 +280,11 @@ int RareFactSharedCommand::execute(){
                //reset groups parameter
                globaldata->Groups.clear();  
                
+               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();    }
index 616d4f7824c0bc3458d55a3e7eb18aa82751d75d..49e370836bb2c9e2edd59e99d9835de8acfc5582 100644 (file)
@@ -30,12 +30,14 @@ ReadBlast::ReadBlast(string file, float c, float p, int l, bool ms, bool h) : bl
 //assumptions about the blast file: 
 //1. if duplicate lines occur the first line is always best and is chosen
 //2. blast scores are grouped together, ie. a a .... score, a b .... score, a c ....score...
-void ReadBlast::read(NameAssignment* nameMap) {
+int ReadBlast::read(NameAssignment* nameMap) {
        try {
        
                //if the user has not given a names file read names from blastfile
                if (nameMap->size() == 0) { readNames(nameMap);  }
                int nseqs = nameMap->size();
+               
+               if (m->control_pressed) { return 0; }
 
                ifstream fileHandle;
                openInputFile(blastfile, fileHandle);
@@ -60,7 +62,14 @@ void ReadBlast::read(NameAssignment* nameMap) {
                        openOutputFile(overlapFile, outOverlap);
                        openOutputFile(distFile, outDist);
                }
-       
+               
+               if (m->control_pressed) { 
+                       fileHandle.close();
+                       if (!hclusterWanted) {  delete matrix; }
+                       else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str());  }
+                       return 0;
+               }
+               
                Progress* reading = new Progress("Reading blast:     ", nseqs * nseqs);
                
                //this is used to quickly find if we already have a distance for this combo
@@ -104,6 +113,14 @@ void ReadBlast::read(NameAssignment* nameMap) {
                                
                //read file
                while(!fileHandle.eof()){  
+               
+                       if (m->control_pressed) { 
+                               fileHandle.close();
+                               if (!hclusterWanted) {  delete matrix; }
+                               else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str());  }
+                               delete reading;
+                               return 0;
+                       }
                        
                        //read in line from file
                        fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score;
@@ -249,6 +266,14 @@ void ReadBlast::read(NameAssignment* nameMap) {
                thisRowsBlastScores.clear();
                dists.clear();
                
+               if (m->control_pressed) { 
+                               fileHandle.close();
+                               if (!hclusterWanted) {  delete matrix; }
+                               else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str());  }
+                               delete reading;
+                               return 0;
+               }
+               
                if (!hclusterWanted) {
                        sort(overlap.begin(), overlap.end(), compareOverlap);
                }else {
@@ -256,9 +281,19 @@ void ReadBlast::read(NameAssignment* nameMap) {
                        outOverlap.close();
                }
                
+               if (m->control_pressed) { 
+                               fileHandle.close();
+                               if (!hclusterWanted) {  delete matrix; }
+                               else {  remove(overlapFile.c_str());  remove(distFile.c_str());  }
+                               delete reading;
+                               return 0;
+               }
+               
                reading->finish();
                delete reading;
                fileHandle.close();
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ReadBlast", "read");
@@ -266,7 +301,7 @@ void ReadBlast::read(NameAssignment* nameMap) {
        }
 } 
 /*********************************************************************************************/
-void ReadBlast::readNames(NameAssignment* nameMap) {
+int ReadBlast::readNames(NameAssignment* nameMap) {
        try {
                m->mothurOut("Reading names... "); cout.flush();
                
@@ -285,6 +320,7 @@ void ReadBlast::readNames(NameAssignment* nameMap) {
                nameMap->push_back(prevName);
                
                while (!in.eof()) {
+                       if (m->control_pressed) { in.close(); return 0; }
                        
                        //read line
                        in >> name;
@@ -307,9 +343,12 @@ void ReadBlast::readNames(NameAssignment* nameMap) {
                //openOutputFile(outNames, out);
                //nameMap->print(out);
                //out.close();
+               if (m->control_pressed) { return 0; }
                
                m->mothurOut(toString(num) + " names read."); m->mothurOutEndLine();
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "ReadBlast", "readNames");
index 536d1af05db87dce20deaf344bd6410b952a61cb..fd32380c20c1a7145a8c65d07700b54d2d5bc63b 100644 (file)
@@ -25,7 +25,7 @@ public:
        ReadBlast(string, float, float, int, bool, bool); //blastfile, cutoff, penalty, length of overlap, min or max bsr, hclusterWanted
        ~ReadBlast() {}
        
-       void read(NameAssignment*);
+       int read(NameAssignment*);
        SparseMatrix* getDistMatrix()           {       return matrix;          }
        vector<seqDist> getOverlapMatrix()      {       return overlap;         }
        string getOverlapFile()                         {       return overlapFile;     }
@@ -42,7 +42,7 @@ private:
        vector<seqDist> overlap;
        MothurOut* m;
        
-       void readNames(NameAssignment*);
+       int readNames(NameAssignment*);
 };
 
 /*******************************************************************************************/
index 1cf9fc325b0ecdc5d222ded20346f79134f3b6b7..acbebaeece94faf995cd9d1a26112e40185314b8 100644 (file)
@@ -20,13 +20,17 @@ ReadCluster::ReadCluster(string distfile, float c){
 
 /***********************************************************************/
 
-void ReadCluster::read(NameAssignment* nameMap){
+int ReadCluster::read(NameAssignment* nameMap){
        try {
         
                if (format == "phylip") { convertPhylip2Column(nameMap); }
                else { list = new ListVector(nameMap->getListVector());  }
                
+               if (m->control_pressed) { return 0; }
+               
                OutPutFile = sortFile(distFile);
+               
+               return 0;
                        
        }
        catch(exception& e) {
@@ -36,7 +40,7 @@ void ReadCluster::read(NameAssignment* nameMap){
 }
 /***********************************************************************/
 
-void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
+int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
        try {   
                //convert phylip file to column file
                map<int, string> rowToName;
@@ -96,6 +100,9 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                        list->set(i, name);
                                        
                                        for(int j=0;j<i;j++){
+                                       
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                                                
                                                if (distance == -1) { distance = 1000000; }
@@ -110,6 +117,9 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                        if(nameMap->count(name)==0){        m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
                                        
                                        for(int j=0;j<i;j++){
+                                               
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                                                
                                                if (distance == -1) { distance = 1000000; }
@@ -130,6 +140,8 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                if(nameMap == NULL){
                                        list->set(i, name);
                                        for(int j=0;j<nseqs;j++){
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                                        
                                                if (distance == -1) { distance = 1000000; }
@@ -143,6 +155,8 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                        if(nameMap->count(name)==0){        m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
                                        
                                        for(int j=0;j<nseqs;j++){
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                         
                                                if (distance == -1) { distance = 1000000; }
@@ -180,6 +194,8 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                float dist;
                
                while (in2) {
+                       if (m->control_pressed) { in2.close(); out2.close(); remove(tempFile.c_str()); remove(outputFile.c_str()); return 0; }
+                       
                        in2 >> first >> second >> dist;
                        out2 << rowToName[first] << '\t' << rowToName[second] << '\t' << dist << endl;
                        gobble(in2);
@@ -189,6 +205,10 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                
                remove(tempFile.c_str());
                distFile = outputFile;
+               
+               if (m->control_pressed) {  remove(outputFile.c_str());  }
+
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "ReadCluster", "convertPhylip2Column");
index d578a0fe76b025d03431446cf74f426814bc9c46..4574c8071616b47f389527f2fd90a5236326f4cd 100644 (file)
@@ -23,7 +23,7 @@ class ReadCluster {
 public:
        ReadCluster(string, float);
        ~ReadCluster();
-       void read(NameAssignment*);
+       int read(NameAssignment*);
        string getOutputFile() { return OutPutFile; }
        void setFormat(string f) { format = f;  }
        ListVector* getListVector()             {       return list;    }
@@ -36,7 +36,7 @@ private:
        float cutoff;
        MothurOut* m;
        
-       void convertPhylip2Column(NameAssignment*);
+       int convertPhylip2Column(NameAssignment*);
 };
 
 /******************************************************/
index 12a38c22b6ca045a2f5b1aa7e2ffdeb11cee4201..d58b0377cb48d1964b21479ca64278919dbf8cca 100644 (file)
@@ -20,7 +20,7 @@ ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){
 \r
 /***********************************************************************/\r
 \r
-void ReadColumnMatrix::read(NameAssignment* nameMap){\r
+int ReadColumnMatrix::read(NameAssignment* nameMap){\r
        try {           \r
 \r
                string firstName, secondName;\r
@@ -38,8 +38,11 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){
                //need to see if this is a square or a triangular matrix...\r
        \r
                while(fileHandle && lt == 1){  //let's assume it's a triangular matrix...\r
+\r
                \r
                        fileHandle >> firstName >> secondName >> distance;      // get the row and column names and distance\r
+                       \r
+                       if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }\r
        \r
                        map<string,int>::iterator itA = nameMap->find(firstName);\r
                        map<string,int>::iterator itB = nameMap->find(secondName);\r
@@ -97,6 +100,8 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){
 \r
                        while(fileHandle){\r
                                fileHandle >> firstName >> secondName >> distance;\r
+                               \r
+                               if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }\r
                \r
                                map<string,int>::iterator itA = nameMap->find(firstName);\r
                                map<string,int>::iterator itB = nameMap->find(secondName);\r
@@ -119,11 +124,15 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){
                                gobble(fileHandle);\r
                        }\r
                }\r
-\r
+               \r
+               if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }\r
+               \r
                reading->finish();\r
                fileHandle.close();\r
 \r
                list->setLabel("0");\r
+               \r
+               return 1;\r
 \r
        }\r
        catch(exception& e) {\r
index 069632c7267f93e3f95b0f52ba382975f255dbc7..5e718afda866d5c72f907d3d42693792d1972d62 100644 (file)
@@ -18,7 +18,7 @@ class ReadColumnMatrix : public ReadMatrix {
 public:
        ReadColumnMatrix(string);
        ~ReadColumnMatrix();
-       void read(NameAssignment*);
+       int read(NameAssignment*);
 private:
        ifstream fileHandle;
        string distFile;
index c83ed8a9a6031663869176a3dda21923229da03a..60d300f177f1deec1720ceeefec71d73ccd7579b 100644 (file)
@@ -204,13 +204,15 @@ int ReadDistCommand::execute(){
                size_t numDists = 0;
                
                vector<string> outputNames;
-               
+cout << format << endl;                
                if (format == "matrix") {
                        ifstream in;
                        openInputFile(distFileName, in);
                        matrix = new FullMatrix(in); //reads the matrix file
                        in.close();
                        
+                       if (m->control_pressed) { delete groupMap; delete matrix; return 0; }
+                       
                        //if files don't match...
                        if (matrix->getNumSeqs() < groupMap->getNumSeqs()) {  
                                m->mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences.");  m->mothurOutEndLine();                         
@@ -223,6 +225,8 @@ int ReadDistCommand::execute(){
                                openOutputFile(newGroupFile, outGroups);
                                
                                for (int i = 0; i < matrix->getNumSeqs(); i++) {
+                                       if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); remove(newGroupFile.c_str()); return 0; }
+                                       
                                        Names temp = matrix->getRowInfo(i);
                                        outGroups << temp.seqName << '\t' << temp.groupName << endl;
                                }
@@ -238,6 +242,8 @@ int ReadDistCommand::execute(){
                                groupMap = new GroupMap(groupfile);
                                groupMap->readMap();
                                
+                               if (m->control_pressed) { delete groupMap; delete matrix; remove(newGroupFile.c_str()); return 0; }
+       
                                globaldata->gGroupmap = groupMap;
                        }
                        
@@ -248,41 +254,19 @@ int ReadDistCommand::execute(){
                } else {
                        read->read(nameMap);
                        //to prevent memory leak
-
+                       
+                       if (m->control_pressed) {  return 0; }
+               
                        if (globaldata->gListVector != NULL) {  delete globaldata->gListVector;  }
                        globaldata->gListVector = read->getListVector();
 
                        if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix;  }
                        globaldata->gSparseMatrix = read->getMatrix();
                        numDists = globaldata->gSparseMatrix->getNNodes();
-       //cout << "matrix contains " << numDists << " distances." << endl;
-                       
-    /*  int lines = cutoff / (1.0/precision);
-      vector<float> dist_cutoff(lines+1,0);
-                       for (int i = 0; i <= lines;i++) {       
-       dist_cutoff[i] = (i + 0.5) / precision; 
-      } 
-      vector<int> dist_count(lines+1,0);
-      list<PCell>::iterator currentCell;
-      SparseMatrix* smatrix = globaldata->gSparseMatrix;
-               for (currentCell = smatrix->begin(); currentCell != smatrix->end(); currentCell++) {
-                               for (int i = 0; i <= lines;i++) {       
-                                       if (currentCell->dist < dist_cutoff[i]) {
-                                               dist_count[i]++;
-            break;
-          }
-        }
-                       }
-*/
-     // string dist_string = "Dist:";
-    //  string count_string = "Count: ";
-                       //for (int i = 0; i <= lines;i++) {     
-       //dist_string = dist_string.append("\t").append(toString(dist_cutoff[i]));
-      //       count_string = count_string.append("\t").append(toString(dist_count[i]));
-               //      }
-      //m->mothurOut(dist_string); m->mothurOutEndLine(); m->mothurOut(count_string); m->mothurOutEndLine();
                }
                
+               if (m->control_pressed) {  return 0; }
+
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Name: "); m->mothurOutEndLine();
index 2c47832f166ea0df47a7b5f5a8760c73f9ce2dfe..d4edb5b8ad866e10a15ce82ef22d22d418c68e84 100644 (file)
@@ -23,8 +23,8 @@ class ReadMatrix {
 public:
        ReadMatrix(){   D = new SparseMatrix();  m = MothurOut::getInstance();  }
        virtual ~ReadMatrix() {}
-       virtual void read(NameAssignment*){};
-       virtual void read(GlobalData* globaldata){};
+       virtual int read(NameAssignment*){ return 1; }
+       
        void setCutoff(float c)                 {       cutoff = c;             }
        SparseMatrix* getMatrix()               {       return D;               }
        ListVector* getListVector()             {       return list;    }
index 6d7d4d0d7e322fc006a9e5ade0dcddbe453eee44..edda41593deb0fd3ac908ea4ebd333dee8d03edc 100644 (file)
@@ -20,7 +20,7 @@ ReadPhylipMatrix::ReadPhylipMatrix(string distFile){
 
 /***********************************************************************/
 
-void ReadPhylipMatrix::read(NameAssignment* nameMap){
+int ReadPhylipMatrix::read(NameAssignment* nameMap){
         try {
         
                         float distance;
@@ -67,15 +67,22 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
                                 int        index = 0;
                
                                 for(int i=1;i<nseqs;i++){
+                                                                               if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }
+                                                                               
                                         fileHandle >> name;
                                         matrixNames.push_back(name);
+                                               
         
                                         //there's A LOT of repeated code throughout this method...
                                         if(nameMap == NULL){
                                                 list->set(i, name);
                                         
                                                 for(int j=0;j<i;j++){
+                                                                                               
+                                                                                                               if (m->control_pressed) { delete reading; fileHandle.close(); return 0;  }
+                                                                                                               
                                                         fileHandle >> distance;
+                                                                                       
                                                 
                                                         if (distance == -1) { distance = 1000000; }
                                                 
@@ -93,6 +100,8 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
                                 
                                                 for(int j=0;j<i;j++){
                                                         fileHandle >> distance;
+                                                                                                               
+                                                                                                               if (m->control_pressed) { delete reading; fileHandle.close(); return 0;  }
                                 
                                                         if (distance == -1) { distance = 1000000; }
                                                         
@@ -115,12 +124,16 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
                                 for(int i=1;i<nseqs;i++){
                                         fileHandle >> name;                
                                         matrixNames.push_back(name);
+                                                                               
+                                                                               
         
                                         if(nameMap == NULL){
                                                 list->set(i, name);
                                                 for(int j=0;j<nseqs;j++){
                                                         fileHandle >> distance;
-                                        
+                                                                                                               
+                                                                                                               if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }
+                                                                                                               
                                                         if (distance == -1) { distance = 1000000; }
                                                         
                                                         if(distance < cutoff && j < i){
@@ -137,7 +150,9 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
                                 
                                                 for(int j=0;j<nseqs;j++){
                                                         fileHandle >> distance;
-                        
+                                                                                                               
+                                                                                                               if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }
+                                                                                                               
                                                         if (distance == -1) { distance = 1000000; }
                                                         
                                                         if(distance < cutoff && j < i){
@@ -150,6 +165,9 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
                                         }
                                 }
                         }
+                                               
+                                               if (m->control_pressed) {  fileHandle.close();  delete reading; return 0; }
+                                               
                         reading->finish();
                         delete reading;
 
@@ -165,6 +183,8 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
                                         m->mothurOut("missed something\t" + toString(nameMap->size())); m->mothurOutEndLine();
                                 }
                         } */
+                                               
+                                               return 1;
 
                 }
         catch(exception& e) {
index 9277338c81fafed9daa6068fdf4e2a0c84d7682e..3e5e7490c618b3d7dac55fb5bd8f8c1853d0ea93 100644 (file)
@@ -18,7 +18,7 @@ class ReadPhylipMatrix : public ReadMatrix {
 public:
        ReadPhylipMatrix(string);
        ~ReadPhylipMatrix();
-       void read(NameAssignment*);
+       int read(NameAssignment*);
 private:
        ifstream fileHandle;
        string distFile;
index 661a5a92583b7077a8e3b5c987f30c72c6f50a84..3062f6677fa8527b4eb59a9ab979458465bfb777 100644 (file)
@@ -283,6 +283,9 @@ int ReadNewickTree::readTreeString() {
 
 int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) {
        try {
+               
+               if (m->control_pressed) { return -1; } 
+               
                int c = readNodeChar(f);
     
                if(c == '('){
index da66ee1eb0971362e8f19ff62155c26239da5615..60654489ce6a1a848eb0dc9743f43e64b832a639 100644 (file)
@@ -141,6 +141,13 @@ int ReadTreeCommand::execute(){
 
                //assemble users trees
                for (int i = 0; i < T.size(); i++) {
+                       if (m->control_pressed) {  
+                               for (int i = 0; i < T.size(); i++) {  delete T[i];  }
+                               globaldata->gTree.clear();
+                               delete globaldata->gTreemap;
+                               return 0;
+                       }
+                       
                        T[i]->assembleTree();
                }
 
@@ -154,6 +161,13 @@ int ReadTreeCommand::execute(){
                                        count++;
                                }
                                
+                               if (m->control_pressed) {  
+                                       for (int i = 0; i < T.size(); i++) {  delete T[i];  }
+                                       globaldata->gTree.clear();
+                                       delete globaldata->gTreemap;
+                                       return 0;
+                               }
+                               
                                //then you did not find it so report it 
                                if (count == globaldata->Treenames.size()) { 
                                        //if it is in your namefile then don't remove
index c76c7113f237c45df86a91faa523f93163fc6ff8..e8565d05819e72968aee30bf6584b1dcb59cc484 100644 (file)
@@ -168,6 +168,8 @@ int RemoveSeqsCommand::execute(){
                //get names you want to keep
                readAccnos();
                
+               if (m->control_pressed) { return 0; }
+               
                //read through the correct file and output lines you want to keep
                if (fastafile != "")            {               readFasta();    }
                else if (namefile != "")        {               readName();             }
@@ -175,6 +177,8 @@ int RemoveSeqsCommand::execute(){
                else if (alignfile != "")       {               readAlign();    }
                else if (listfile != "")        {               readList();             }
                
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); } return 0; }
+               
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -192,7 +196,7 @@ int RemoveSeqsCommand::execute(){
 }
 
 //**********************************************************************************************************************
-void RemoveSeqsCommand::readFasta(){
+int RemoveSeqsCommand::readFasta(){
        try {
                if (outputDir == "") {  outputDir += hasPath(fastafile);  }
                string outputFileName = getRootName(fastafile) + "pick" + getExtension(fastafile);
@@ -206,6 +210,8 @@ void RemoveSeqsCommand::readFasta(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+                       if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -226,7 +232,9 @@ void RemoveSeqsCommand::readFasta(){
                        m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else { outputNames.push_back(outputFileName); }
-
+               
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "RemoveSeqsCommand", "readFasta");
@@ -234,7 +242,7 @@ void RemoveSeqsCommand::readFasta(){
        }
 }
 //**********************************************************************************************************************
-void RemoveSeqsCommand::readList(){
+int RemoveSeqsCommand::readList(){
        try {
                if (outputDir == "") {  outputDir += hasPath(listfile);  }
                string outputFileName = getRootName(listfile) + "pick" +  getExtension(listfile);
@@ -256,6 +264,7 @@ void RemoveSeqsCommand::readList(){
                        
                        //for each bin
                        for (int i = 0; i < list.getNumBins(); i++) {
+                               if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
                        
                                //parse out names that are in accnos file
                                string binnames = list.get(i);
@@ -291,6 +300,8 @@ void RemoveSeqsCommand::readList(){
                        m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else { outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -299,7 +310,7 @@ void RemoveSeqsCommand::readList(){
        }
 }
 //**********************************************************************************************************************
-void RemoveSeqsCommand::readName(){
+int RemoveSeqsCommand::readName(){
        try {
                if (outputDir == "") {  outputDir += hasPath(namefile);  }
                string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
@@ -319,6 +330,7 @@ void RemoveSeqsCommand::readName(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+                       if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str()); if (dups) { out2.close(); remove(outputFileName2.c_str()); } return 0; }
 
                        in >> firstCol;                         
                        in >> secondCol;                        
@@ -388,6 +400,7 @@ void RemoveSeqsCommand::readName(){
                        remove(outputFileName.c_str()); 
                }else { outputNames.push_back(outputFileName); }
                
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "RemoveSeqsCommand", "readName");
@@ -396,7 +409,7 @@ void RemoveSeqsCommand::readName(){
 }
 
 //**********************************************************************************************************************
-void RemoveSeqsCommand::readGroup(){
+int RemoveSeqsCommand::readGroup(){
        try {
                if (outputDir == "") {  outputDir += hasPath(groupfile);  }
                string outputFileName = getRootName(groupfile) + "pick" + getExtension(groupfile);
@@ -410,7 +423,8 @@ void RemoveSeqsCommand::readGroup(){
                bool wroteSomething = false;
                
                while(!in.eof()){
-
+                       if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
+                       
                        in >> name;                             //read from first column
                        in >> group;                    //read from second column
                        
@@ -429,7 +443,8 @@ void RemoveSeqsCommand::readGroup(){
                        m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else { outputNames.push_back(outputFileName); }
-
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "RemoveSeqsCommand", "readGroup");
@@ -439,7 +454,7 @@ void RemoveSeqsCommand::readGroup(){
 
 //**********************************************************************************************************************
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
-void RemoveSeqsCommand::readAlign(){
+int RemoveSeqsCommand::readAlign(){
        try {
                if (outputDir == "") {  outputDir += hasPath(alignfile);  }
                string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
@@ -460,7 +475,8 @@ void RemoveSeqsCommand::readAlign(){
                out << endl;
                
                while(!in.eof()){
-
+                       if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
+                       
                        in >> name;                             //read from first column
                        
                        //if this name is in the accnos file
@@ -496,6 +512,8 @@ void RemoveSeqsCommand::readAlign(){
                        remove(outputFileName.c_str()); 
                }else { outputNames.push_back(outputFileName); }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "RemoveSeqsCommand", "readAlign");
index ddda08ce9bbfe7f4bc1e6a5aa55e8028667ade37..1f429d92810402f64a1c2d776510719aa7113610 100644 (file)
@@ -27,12 +27,12 @@ class RemoveSeqsCommand : public Command {
                bool abort, dups;
                vector<string> outputNames;
                
-               void readFasta();
-               void readName();
-               void readGroup();
-               void readAlign();
+               int readFasta();
+               int readName();
+               int readGroup();
+               int readAlign();
                void readAccnos();
-               void readList();
+               int readList();
                
 };
 
index 4efcbcce17e7daeb102a3c3c98d4baedbc185093..114750e71e4c5cb127cf4b9407bd1841bb8aa622 100644 (file)
@@ -103,6 +103,8 @@ int ReverseSeqsCommand::execute(){
                openOutputFile(reverseFile, outFASTA);
                
                while(!inFASTA.eof()){
+                       if (m->control_pressed) {  inFASTA.close();  outFASTA.close(); remove(reverseFile.c_str()); return 0; }
+                        
                        Sequence currSeq(inFASTA);  gobble(inFASTA);
                        if (currSeq.getName() != "") {
                                currSeq.reverseComplement();
@@ -112,6 +114,8 @@ int ReverseSeqsCommand::execute(){
                inFASTA.close();
                outFASTA.close();
                
+               if (m->control_pressed) {  remove(reverseFile.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(reverseFile); m->mothurOutEndLine();       
index bb8d1f53714e3d953eb0f6c9c7bd4a829b3cb833..5b3d7d7604c4f0fe5460265fbd611e12dded4629 100644 (file)
@@ -175,6 +175,8 @@ int ScreenSeqsCommand::execute(){
                ofstream badSeqOut;             openOutputFile(badSeqFile, badSeqOut);          
                
                while(!inFASTA.eof()){
+                       if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+                       
                        Sequence currSeq(inFASTA);
                        if (currSeq.getName() != "") {
                                bool goodSeq = 1;               //      innocent until proven guilty
@@ -194,20 +196,32 @@ int ScreenSeqsCommand::execute(){
                                }
                        }
                        gobble(inFASTA);
-               }       
-               if(namefile != "" && groupfile != "")   {       screenNameGroupFile(badSeqNames);       }       // this screens both names and groups
-               else if(namefile != "")                                 {       screenNameGroupFile(badSeqNames);       }
-               else if(groupfile != "")                                {       screenGroupFile(badSeqNames);           }       // this screens just the groups
+               }
+                       
+               if(namefile != "" && groupfile != "")   {       
+                       screenNameGroupFile(badSeqNames);       
+                       if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+               }else if(namefile != "")        {       
+                       screenNameGroupFile(badSeqNames);
+                       if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }  
+               }else if(groupfile != "")                               {       screenGroupFile(badSeqNames);           }       // this screens just the group
+               
+               if (m->control_pressed) { goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
                if(alignreport != "")                                   {       screenAlignReport(badSeqNames);         }
                
                goodSeqOut.close();
                badSeqOut.close();
                inFASTA.close();
                
+               
+               if (m->control_pressed) { remove(goodSeqFile.c_str()); remove(badSeqFile.c_str()); return 0; }
+
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                m->mothurOut(goodSeqFile); m->mothurOutEndLine();       
                m->mothurOut(badSeqFile); m->mothurOutEndLine();        
+               for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
                m->mothurOutEndLine();
 
                
@@ -221,7 +235,7 @@ int ScreenSeqsCommand::execute(){
 
 //***************************************************************************************************************
 
-void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
+int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
 
        ifstream inputNames;
        openInputFile(namefile, inputNames);
@@ -232,10 +246,14 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
        string goodNameFile = outputDir + getRootName(getSimpleName(namefile)) + "good" + getExtension(namefile);
        string badNameFile = outputDir + getRootName(getSimpleName(namefile)) + "bad" + getExtension(namefile);
        
+       outputNames.push_back(goodNameFile);  outputNames.push_back(badNameFile);
+       
        ofstream goodNameOut;   openOutputFile(goodNameFile, goodNameOut);
        ofstream badNameOut;    openOutputFile(badNameFile, badNameOut);                
        
        while(!inputNames.eof()){
+               if (m->control_pressed) { goodNameOut.close(); badNameOut.close(); inputNames.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); return 0; }
+
                inputNames >> seqName >> seqList;
                it = badSeqNames.find(seqName);
                
@@ -278,10 +296,14 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
                string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
                
+               outputNames.push_back(goodGroupFile);  outputNames.push_back(badGroupFile);
+               
                ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
                ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
                
                while(!inputGroups.eof()){
+                       if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str()); remove(badNameFile.c_str()); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
                        inputGroups >> seqName >> group;
 
                        it = badSeqGroups.find(seqName);
@@ -307,11 +329,14 @@ void ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
                        }
                }
        }
+               
+       return 0;
+
 }
 
 //***************************************************************************************************************
 
-void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
+int ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
 
        ifstream inputGroups;
        openInputFile(groupfile, inputGroups);
@@ -321,10 +346,14 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
        string goodGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "good" + getExtension(groupfile);
        string badGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "bad" + getExtension(groupfile);
        
+       outputNames.push_back(goodGroupFile);  outputNames.push_back(badGroupFile);
+       
        ofstream goodGroupOut;  openOutputFile(goodGroupFile, goodGroupOut);
        ofstream badGroupOut;   openOutputFile(badGroupFile, badGroupOut);              
        
        while(!inputGroups.eof()){
+               if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
                inputGroups >> seqName >> group;
                it = badSeqNames.find(seqName);
                
@@ -338,6 +367,8 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
                gobble(inputGroups);
        }
        
+       if (m->control_pressed) { goodGroupOut.close(); badGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); return 0; }
+
        //we were unable to remove some of the bad sequences
        if (badSeqNames.size() != 0) {
                for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
@@ -350,11 +381,16 @@ void ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
        goodGroupOut.close();
        badGroupOut.close();
        
+       if (m->control_pressed) { remove(goodGroupFile.c_str()); remove(badGroupFile.c_str());  }
+
+       
+       return 0;
+       
 }
 
 //***************************************************************************************************************
 
-void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
+int ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        
        ifstream inputAlignReport;
        openInputFile(alignreport, inputAlignReport);
@@ -364,6 +400,8 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        string goodAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "good" + getExtension(alignreport);
        string badAlignReportFile = outputDir + getRootName(getSimpleName(alignreport)) + "bad" + getExtension(alignreport);
        
+       outputNames.push_back(goodAlignReportFile);  outputNames.push_back(badAlignReportFile);
+       
        ofstream goodAlignReportOut;    openOutputFile(goodAlignReportFile, goodAlignReportOut);
        ofstream badAlignReportOut;             openOutputFile(badAlignReportFile, badAlignReportOut);          
 
@@ -375,6 +413,8 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        }
 
        while(!inputAlignReport.eof()){
+               if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
                inputAlignReport >> seqName;
                it = badSeqNames.find(seqName);
                string line;            
@@ -394,6 +434,8 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
                gobble(inputAlignReport);
        }
        
+       if (m->control_pressed) { goodAlignReportOut.close(); badAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+
        //we were unable to remove some of the bad sequences
        if (badSeqNames.size() != 0) {
                for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
@@ -405,6 +447,11 @@ void ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
        inputAlignReport.close();
        goodAlignReportOut.close();
        badAlignReportOut.close();
+                       
+       if (m->control_pressed) {  remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; }
+       
+       return 0;
+
        
 }
 
index 5b44091dbd07d044f0de288490ff0d4633495008..54f4bb153d66b89728a1d10fd073cb14f3957779 100644 (file)
@@ -21,13 +21,14 @@ public:
        void help();
        
 private:
-       void screenNameGroupFile(set<string>);
-       void screenGroupFile(set<string>);
-       void screenAlignReport(set<string>);
+       int screenNameGroupFile(set<string>);
+       int screenGroupFile(set<string>);
+       int screenAlignReport(set<string>);
        
        bool abort;
        string fastafile, namefile, groupfile, alignreport, outputDir;
        int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
+       vector<string> outputNames;
 };
 
 #endif
index e23a0ac6a431ad14cdab21fb0bfa4276f4afd8c6..dc40611711062150b7046e1be665a34c87d87818 100644 (file)
@@ -120,6 +120,7 @@ int AlignCheckCommand::execute(){
 
                
                while(!in.eof()){
+                       if (m->control_pressed) { in.close(); out.close(); remove(outfile.c_str()); return 0; }
                        
                        Sequence seq(in);  gobble(in);
                        if (seq.getName() != "") {
@@ -135,6 +136,8 @@ int AlignCheckCommand::execute(){
                in.close();
                out.close();
                
+               if (m->control_pressed) {  remove(outfile.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(outfile); m->mothurOutEndLine();   
index 49edc36f8e7c3d94d32b7995f08c14e955cd232a..4514e01713b5d1e3e51a6b7c60c4ed4155a0e5ad 100644 (file)
@@ -111,6 +111,8 @@ int SeqSummaryCommand::execute(){
                outSummary << "seqname\tstart\tend\tnbases\tambigs\tpolymer" << endl;                   
 
                while(!inFASTA.eof()){
+                       if (m->control_pressed) { inFASTA.close(); outSummary.close(); remove(summaryFile.c_str()); return 0; }
+                       
                        Sequence current(inFASTA);
                        if (current.getName() != "") {
                                startPosition.push_back(current.getStartPos());
@@ -147,6 +149,8 @@ int SeqSummaryCommand::execute(){
                if (startPosition[0] == -1) {  startPosition[0] = 0;    }
                if (endPosition[0] == -1)       {  endPosition[0] = 0;          }
                
+               if (m->control_pressed) {  outSummary.close(); remove(summaryFile.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer"); m->mothurOutEndLine();
                m->mothurOut("Minimum:\t" + toString(startPosition[0]) + "\t" + toString(endPosition[0]) + "\t" + toString(seqLength[0]) + "\t" + toString(ambigBases[0]) + "\t" + toString(longHomoPolymer[0])); m->mothurOutEndLine();
@@ -160,6 +164,8 @@ int SeqSummaryCommand::execute(){
                
                outSummary.close();
                
+               if (m->control_pressed) {  remove(summaryFile.c_str()); return 0; }
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
                m->mothurOut(summaryFile); m->mothurOutEndLine();       
index f03152bcfa84047813da249e0fedb3673139861c..213fd49588bbf8a9278bc04c14d474bd11ccb278 100644 (file)
@@ -49,6 +49,7 @@ SharedCommand::SharedCommand(string o) : outputDir(o) {
                //clears file before we start to write to it below
                for (int i=0; i<groups.size(); i++) {
                        remove((fileroot + groups[i] + ".rabund").c_str());
+                       outputNames.push_back((fileroot + groups[i] + ".rabund"));
                }
 
        }
@@ -76,6 +77,14 @@ int SharedCommand::execute(){
                string lastLabel = SharedList->getLabel();
                vector<SharedRAbundVector*> lookup; 
                
+               if (m->control_pressed) { 
+                       delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; 
+                       for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
+                       out.close(); remove(filename.c_str()); 
+                       for (int i=0; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
+                       return 1; 
+               }
+                               
                if ((globaldata->Groups.size() == 0) && (SharedList->getNumSeqs() != groupMap->getNumSeqs())) {  //if the user has not specified any groups and their files don't match exit with error
                        m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); 
                        
@@ -88,6 +97,8 @@ int SharedCommand::execute(){
                        for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
                                delete it3->second;
                        }
+                       delete input;
+                       globaldata->ginput = NULL;
                        delete SharedList;
                        globaldata->gSharedList = NULL;
                        
@@ -121,14 +132,30 @@ int SharedCommand::execute(){
                set<string> userLabels = globaldata->labels;    
        
                while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                       if (m->control_pressed) { 
+                               delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; 
+                               for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
+                               out.close(); remove(filename.c_str()); 
+                               for (int i=0; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
+                               return 1; 
+                       }
                
                        if(globaldata->allLines == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
-                       
+                                       
                                        lookup = SharedList->getSharedRAbundVector();
+                                       m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
                                        if (pickedGroups) { //check for otus with no seqs in them
                                                eliminateZeroOTUS(lookup);
                                        }
-                                       m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+                                       
+                                       if (m->control_pressed) { 
+                                               delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; 
+                                               for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+                                               for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
+                                               out.close(); remove(filename.c_str()); 
+                                               for (int i=0; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
+                                               return 1; 
+                                       }
                                        
                                        printSharedData(lookup); //prints info to the .shared file
                                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
@@ -144,10 +171,20 @@ int SharedCommand::execute(){
                                        SharedList = input->getSharedListVector(lastLabel); //get new list vector to process
                                        
                                        lookup = SharedList->getSharedRAbundVector();
+                                       m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
                                        if (pickedGroups) { //check for otus with no seqs in them
                                                eliminateZeroOTUS(lookup);
                                        }
-                                       m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+                                       
+                                       
+                                       if (m->control_pressed) { 
+                                               delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; 
+                                               for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+                                               for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;  }
+                                               out.close(); remove(filename.c_str()); 
+                                               for (int i=0; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
+                                               return 1; 
+                                       }
                                        
                                        printSharedData(lookup); //prints info to the .shared file
                                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
@@ -181,10 +218,18 @@ int SharedCommand::execute(){
                        SharedList = input->getSharedListVector(lastLabel); //get new list vector to process
                                        
                        lookup = SharedList->getSharedRAbundVector();
+                       m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
                        if (pickedGroups) { //check for otus with no seqs in them
                                eliminateZeroOTUS(lookup);
                        }
-                       m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+                       
+                       if (m->control_pressed) { 
+                                       delete input;  globaldata->ginput = NULL; 
+                                       for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {  delete it3->second;   }
+                                       out.close(); remove(filename.c_str()); 
+                                       for (int i=0; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
+                                       return 1; 
+                       }
                        
                        printSharedData(lookup); //prints info to the .shared file
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
@@ -205,7 +250,19 @@ int SharedCommand::execute(){
                globaldata->setListFile("");
                globaldata->setGroupFile("");
                globaldata->setSharedFile(filename);
-
+               
+               if (m->control_pressed) { 
+                               delete input;  globaldata->ginput = NULL; 
+                               remove(filename.c_str()); 
+                               for (int i=0; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
+                               return 1; 
+               }
+               
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+               for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
+               m->mothurOut(filename); m->mothurOutEndLine();
+               m->mothurOutEndLine();
                
                return 0;
        }
@@ -237,7 +294,7 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
        }
 }
 //**********************************************************************************************************************
-void SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
+int SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
        try {
                
                vector<SharedRAbundVector*> newLookup;
@@ -250,6 +307,7 @@ void SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
                
                //for each bin
                for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
+                       if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
                
                        //look at each sharedRabund and make sure they are not all zero
                        bool allZero = true;
@@ -268,7 +326,8 @@ void SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
        
                for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
                thislookup = newLookup;
-       
+               
+               return 0;
  
        }
        catch(exception& e) {
@@ -277,7 +336,7 @@ void SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
        }
 }
 //**********************************************************************************************************************
-void SharedCommand::createMisMatchFile() {
+int SharedCommand::createMisMatchFile() {
        try {
                ofstream outMisMatch;
                string outputMisMatchName = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
@@ -294,6 +353,7 @@ void SharedCommand::createMisMatchFile() {
                        
                        //go through list and if group returns "not found" output it
                        for (int i = 0; i < SharedList->getNumBins(); i++) {
+                               if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; } 
                        
                                string names = SharedList->get(i); 
                                
@@ -332,6 +392,8 @@ void SharedCommand::createMisMatchFile() {
                        
                        //go through listfile and get names
                        for (int i = 0; i < SharedList->getNumBins(); i++) {
+                               if (m->control_pressed) {  return 0; } 
+
                                
                                string names = SharedList->get(i); 
                
@@ -362,6 +424,7 @@ void SharedCommand::createMisMatchFile() {
                        
                        //loop through names in seqNames and if they aren't in namesIn list output them
                        for (int i = 0; i < seqNames.size(); i++) {
+                               if (m->control_pressed) { outMisMatch.close(); remove(outputMisMatchName.c_str()); return 0; } 
                                
                                itMatch = namesInList.find(seqNames[i]);
                                
@@ -372,7 +435,8 @@ void SharedCommand::createMisMatchFile() {
                        }               
                        outMisMatch.close();
                }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "SharedCommand", "createMisMatchFile");
index 3d39b8b7a54ba348966f80d41cf1cea3b9bc9283..399f3d3966bf828ec32cd790dd0d7d14c7e08c25 100644 (file)
@@ -33,16 +33,16 @@ public:
        
 private:
        void printSharedData(vector<SharedRAbundVector*>);
-       void createMisMatchFile();
+       int createMisMatchFile();
        bool isValidGroup(string, vector<string>);
-       void eliminateZeroOTUS(vector<SharedRAbundVector*>&);
+       int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
        
        GlobalData* globaldata;
        ReadOTUFile* read;
        SharedListVector* SharedList;
        InputData* input;
        GroupMap* groupMap;
-       vector<string> groups;
+       vector<string> groups, outputNames;
        ofstream out;
        string filename, fileroot, outputDir;
        bool firsttime, pickedGroups;
index 2d079cd6ac10ae5ed4aeea0454ff3f0e984561e8..5d5a48b864695ce2ed92357006b834efa24195bb 100644 (file)
@@ -20,6 +20,8 @@ string Slayer::getResults(Sequence* query, vector<Sequence*> refSeqs) {
                for (int i = 0; i < refSeqs.size(); i++) {
                
                        for (int j = i+1; j < refSeqs.size(); j++) {
+                       
+                               if (m->control_pressed) { return "no";  }
        
                                //make copies of query and each parent because runBellerophon removes gaps and messes them up
                                Sequence* q = new Sequence(query->getName(), query->getAligned());
@@ -29,12 +31,26 @@ string Slayer::getResults(Sequence* query, vector<Sequence*> refSeqs) {
                                map<int, int> spots;  //map from spot in original sequence to spot in filtered sequence for query and both parents
                                vector<data_struct> divs = runBellerophon(q, leftParent, rightParent, spots);
                                
+                               if (m->control_pressed) { 
+                                       delete q;
+                                       delete leftParent;
+                                       delete rightParent;
+                                       return "no"; 
+                               }
+                               
                                vector<data_struct> selectedDivs;
                                for (int k = 0; k < divs.size(); k++) {
                                
                                        vector<snps> snpsLeft = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winLStart, divs[k].winLEnd);
                                        vector<snps> snpsRight = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winRStart, divs[k].winREnd);
                                        
+                                       if (m->control_pressed) { 
+                                               delete q;
+                                               delete leftParent;
+                                               delete rightParent;
+                                               return "no"; 
+                                       }
+                                       
                                        int numSNPSLeft = snpsLeft.size();
                                        int numSNPSRight = snpsRight.size();
                                        
@@ -54,6 +70,13 @@ string Slayer::getResults(Sequence* query, vector<Sequence*> refSeqs) {
                                                        
                                                        float BS_A, BS_B;
                                                        bootstrapSNPS(snpsLeft, snpsRight, BS_A, BS_B);
+                                                       
+                                                       if (m->control_pressed) { 
+                                                               delete q;
+                                                               delete leftParent;
+                                                               delete rightParent;
+                                                               return "no"; 
+                                                       }
 
                                                        divs[k].bsa = BS_A;
                                                        divs[k].bsb = BS_B;
@@ -136,6 +159,8 @@ vector<data_struct> Slayer::runBellerophon(Sequence* q, Sequence* pA, Sequence*
                
                for (int i = windowSize-1; i <= (length - windowSize); i += windowStep) {
                
+                       if (m->control_pressed) { return data; }
+               
                        int breakpoint = i;
                        int leftLength = breakpoint + 1;
                        int rightLength = length - leftLength;
@@ -262,7 +287,7 @@ vector<snps> Slayer::getSNPS(string parentA, string query, string parentB, int l
        }
 }
 /***********************************************************************/
-void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, float& BSB) {
+int Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, float& BSB) {
        try {
 
                srand((unsigned)time( NULL ));
@@ -276,6 +301,8 @@ void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, fl
                for (int i = 0; i < iters; i++) {
                        //random sampling with replacement.
                
+                       if (m->control_pressed) { return 0;  }
+                       
                        vector<snps> selectedLeft;
 
                        for (int j = 0; j < numLeft; j++) {
@@ -339,6 +366,8 @@ void Slayer::bootstrapSNPS(vector<snps> left, vector<snps> right, float& BSA, fl
                BSA = ((float) count_A / (float) iters) * 100;
                BSB = ((float) count_B / (float) iters) * 100;
 //cout << "bsa = " << BSA << " bsb = " << BSB << endl;
+
+               return 0;
        
        }
        catch(exception& e) {
index d746b47b0cb1170f26e16c4d7589656ab0204808..33ccc3fda70ad9e6dca595eb626c0bb9e5dedc1c 100644 (file)
--- a/slayer.h
+++ b/slayer.h
@@ -83,7 +83,7 @@ class Slayer {
                
                vector<data_struct> runBellerophon(Sequence*, Sequence*, Sequence*, map<int, int>&);
                vector<snps> getSNPS(string, string, string, int, int);
-               void bootstrapSNPS(vector<snps>, vector<snps>, float&, float&);
+               int bootstrapSNPS(vector<snps>, vector<snps>, float&, float&);
                float snpQA(vector<snps>);
                float snpQB(vector<snps>);
                float snpAB(vector<snps>);
index e1ffb0ec0de20ea11345db0b5040ed492e829a0f..92998e66ac1eadb442b5b0afc0cfee33835f902a 100644 (file)
@@ -53,13 +53,24 @@ vector<vector<double> > SLibshuff::evaluateAll(){
 
 double SLibshuff::sCalculate(int x, int y){
        try{
+               double sum = 0.0,t=0.0;
+               
                minX = getMinX(x);
+               
+               if (m->control_pressed) { return sum; }
+               
                minXY = getMinXY(x,y);
+               
+               if (m->control_pressed) { return sum; }
 
                sort(minX.begin(), minX.end());
+               
+               if (m->control_pressed) { return sum; }
+               
                sort(minXY.begin(), minXY.end());
+               
+               if (m->control_pressed) { return sum; }
 
-               double sum = 0.0,t=0.0;
                int ix=0,iy=0;
                while( (ix < groupSizes[x]) && (iy < groupSizes[x]) ) {
                        double h = (ix-iy)/double(groupSizes[x]);
index 12382a48864a87363f5faae62425de574cb5d0e7..5ad1ee6432bf17220e3b8fd2187734ba4a7a098a 100644 (file)
@@ -139,6 +139,8 @@ int SummaryCommand::execute(){
                if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName);  }
                else {  inputFileNames = parseSharedFile(globaldata->getSharedFile());  globaldata->setFormat("rabund");  }
                
+               if (m->control_pressed) { return 0; }
+               
                for (int p = 0; p < inputFileNames.size(); p++) {
                        
                        string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary";
@@ -229,8 +231,12 @@ int SummaryCommand::execute(){
                        set<string> processedLabels;
                        set<string> userLabels = labels;
                        
+                       if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) {      remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0;  }
+                       
                        while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                                
+                               if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) {      remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0;  }
+                               
                                if(allLines == 1 || labels.count(sabund->getLabel()) == 1){                     
                                        
                                        m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
@@ -240,6 +246,9 @@ int SummaryCommand::execute(){
                                        outputFileHandle << sabund->getLabel();
                                        for(int i=0;i<sumCalculators.size();i++){
                                                vector<double> data = sumCalculators[i]->getValues(sabund);
+                                               
+                                               if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) {      remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0;  }
+
                                                outputFileHandle << '\t';
                                                sumCalculators[i]->print(outputFileHandle);
                                        }
@@ -259,6 +268,9 @@ int SummaryCommand::execute(){
                                        outputFileHandle << sabund->getLabel();
                                        for(int i=0;i<sumCalculators.size();i++){
                                                vector<double> data = sumCalculators[i]->getValues(sabund);
+                                               
+                                               if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) {      remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0;  }
+                                               
                                                outputFileHandle << '\t';
                                                sumCalculators[i]->print(outputFileHandle);
                                        }
@@ -274,6 +286,8 @@ int SummaryCommand::execute(){
                                sabund = input->getSAbundVector();
                        }
                        
+                       if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) {      remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read;  delete input; globaldata->ginput = NULL; return 0;  }
+
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -296,6 +310,9 @@ int SummaryCommand::execute(){
                                outputFileHandle << sabund->getLabel();
                                for(int i=0;i<sumCalculators.size();i++){
                                        vector<double> data = sumCalculators[i]->getValues(sabund);
+                                       
+                                       if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) {      remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0;  }
+
                                        outputFileHandle << '\t';
                                        sumCalculators[i]->print(outputFileHandle);
                                }
@@ -305,12 +322,18 @@ int SummaryCommand::execute(){
                        
                        outputFileHandle.close();
                        
+                       if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read;  delete input; globaldata->ginput = NULL; return 0;  }
+
+                       
                        delete input;  globaldata->ginput = NULL;
                        delete read;
                        delete validCalculator;
                        globaldata->sabund = NULL;
+                       for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
                }
                
+               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();    }
index b6b4f522df0b1fc0eeb96d3851d8eda0419a35aa..b8956ecd6b495525d922c296484a433cd97ebdc9 100644 (file)
@@ -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();
@@ -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");
index 8f37eeb9cb1a907c7db1b2c6549ad19bda591a6b..bcd8ab671f2727331179dbe3511d4acd72f72417 100644 (file)
@@ -41,7 +41,7 @@ private:
        vector<SharedRAbundVector*> lookup;
        string outputFileName, format, outAllFileName, outputDir;
        ofstream outputFileHandle, outAll;
-       void process(vector<SharedRAbundVector*>);
+       int process(vector<SharedRAbundVector*>);
 
 };
 
index f3ccfe45852ba8065c454d4bf42a0ad83a75d088..fc36eb643c30c549810ff462671c38ba36e118b8 100644 (file)
@@ -19,42 +19,51 @@ TaxEqualizer::TaxEqualizer(string tfile, int c) : cutoff(c) {
                openInputFile(tfile, inTax);
        
                highestLevel = getHighestLevel(inTax);
-       
-               //if the user has specified a cutoff and it's smaller than the highest level
-               if ((cutoff != -1) && (cutoff < highestLevel)) { 
-                       highestLevel = cutoff;
-               }else if (cutoff > highestLevel) {
-                       m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel));
-                       m->mothurOutEndLine();
-               }
-               
-               inTax.close(); 
-               ifstream in; 
-               openInputFile(tfile, in);
-               
-               ofstream out;
-               equalizedFile = getRootName(tfile) + "equalized.taxonomy";
-               openOutputFile(equalizedFile, out);
                
-               string name, tax;
-               while (in) {
-                       in >> name >> tax;   gobble(in);
+               if (!m->control_pressed) { 
                        
-                       if (containsConfidence) {  removeConfidences(tax);      }
+                       //if the user has specified a cutoff and it's smaller than the highest level
+                       if ((cutoff != -1) && (cutoff < highestLevel)) { 
+                               highestLevel = cutoff;
+                       }else if (cutoff > highestLevel) {
+                               m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel));
+                               m->mothurOutEndLine();
+                       }
                        
-                       //is this a taxonomy that needs to be extended?
-                       if (seqLevels[name] < highestLevel) {
-                               extendTaxonomy(name, tax, highestLevel);
-                       }else if (seqLevels[name] > highestLevel) { //this can happen if the user enters a cutoff
-                               truncateTaxonomy(name, tax, highestLevel);
+                       inTax.close(); 
+                       ifstream in; 
+                       openInputFile(tfile, in);
+                       
+                       ofstream out;
+                       equalizedFile = getRootName(tfile) + "equalized.taxonomy";
+                       openOutputFile(equalizedFile, out);
+                       
+       
+                       string name, tax;
+                       while (in) {
+                       
+                               if (m->control_pressed) {  break; }
+                               
+                               in >> name >> tax;   gobble(in);
+                               
+                               if (containsConfidence) {  removeConfidences(tax);      }
+                               
+                               //is this a taxonomy that needs to be extended?
+                               if (seqLevels[name] < highestLevel) {
+                                       extendTaxonomy(name, tax, highestLevel);
+                               }else if (seqLevels[name] > highestLevel) { //this can happen if the user enters a cutoff
+                                       truncateTaxonomy(name, tax, highestLevel);
+                               }
+                               
+                               out << name << '\t' << tax << endl;
                        }
                        
-                       out << name << '\t' << tax << endl;
-               }
+                       in.close();
+                       out.close();
+                       
+                       if (m->control_pressed) { remove(equalizedFile.c_str());  }
+               }else { inTax.close(); }
                
-               in.close();
-               out.close();
-                                       
        }
        catch(exception& e) {
                m->errorOut(e, "TaxEqualizer", "TaxEqualizer");
index eca53d5527bbdda6dbc97ddc0c9f4e7766e15d25..7da3cef3718502640d61377bccbaae0d8e4213d3 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -166,7 +166,7 @@ void Tree::setIndex(string searchName, int index) {
        }
 }
 /*****************************************************************/
-void Tree::assembleTree() {
+int Tree::assembleTree() {
        try {
        
                //if user has given a names file we want to include that info in the pgroups and pcount info.
@@ -174,9 +174,13 @@ void Tree::assembleTree() {
                
                //build the pGroups in non leaf nodes to be used in the parsimony calcs.
                for (int i = numLeaves; i < numNodes; i++) {
+                       if (m->control_pressed) { return 1; }
+
                        tree[i].pGroups = (mergeGroups(i));
                        tree[i].pcount = (mergeGcounts(i));
                }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "Tree", "assembleTree");
diff --git a/tree.h b/tree.h
index 04d9fb1fd3499cd87b5a8563b6e082fddb3d32dd..23ddf5dd87ed6d901d8db793861e34cb92b43e2d 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -37,7 +37,7 @@ public:
        int findRoot();  //return index of root node
        
        //this function takes the leaf info and populates the non leaf nodes
-       void assembleTree();    
+       int assembleTree();     
        
        vector<Node> tree;              //the first n nodes are the leaves, where n is the number of sequences.
                
index 6ce5ee9dfcb29dfd495bb7dc5f83aec8681eb3d6..c4e58c28b3a7c56892981c7e221b738daa610ccd 100644 (file)
@@ -223,6 +223,7 @@ void TreeGroupCommand::help(){
 //**********************************************************************************************************************
 
 TreeGroupCommand::~TreeGroupCommand(){
+       globaldata->Groups.clear();  
        if (abort == false) {
                
                if (format == "sharedfile") { delete read;  delete input; globaldata->ginput = NULL; }
@@ -257,8 +258,23 @@ int TreeGroupCommand::execute(){
                        //used in tree constructor 
                        globaldata->runParse = false;
                        
+                       //clear globaldatas old tree names if any
+                       globaldata->Treenames.clear();
+               
+                       //fills globaldatas tree names
+                       globaldata->Treenames = globaldata->Groups;
+               
+                       //create treemap class from groupmap for tree class to use
+                       tmap = new TreeMap();
+                       tmap->makeSim(globaldata->gGroupmap);
+                       globaldata->gTreemap = tmap;
+                       
+                       if (m->control_pressed) { return 0; }
+                       
                        //create tree file
                        makeSimsShared();
+                       
+                       if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());  } return 0; }
                }else{
                        //read in dist file
                        filename = globaldata->inputFileName;
@@ -282,6 +298,9 @@ int TreeGroupCommand::execute(){
 
                        //make treemap
                        tmap = new TreeMap();
+                       
+                       if (m->control_pressed) { return 0; }
+                       
                        tmap->makeSim(list);
                        globaldata->gTreemap = tmap;
                        
@@ -296,14 +315,22 @@ int TreeGroupCommand::execute(){
                        //used in tree constructor 
                        globaldata->runParse = false;
                        
+                       if (m->control_pressed) { return 0; }
+                       
                        makeSimsDist();
+                       
+                       if (m->control_pressed) { return 0; }
 
                        //create a new filename
                        outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "tre"; 
                        outputNames.push_back(outputFile);
                                
                        createTree();
+                       
+                       if (m->control_pressed) { return 0; }
+
                        m->mothurOut("Tree complete. "); m->mothurOutEndLine();
+                       
                }
                                
                //reset groups parameter
@@ -323,7 +350,7 @@ int TreeGroupCommand::execute(){
 }
 //**********************************************************************************************************************
 
-void TreeGroupCommand::createTree(){
+int TreeGroupCommand::createTree(){
        try {
                //create tree
                t = new Tree();
@@ -332,7 +359,9 @@ void TreeGroupCommand::createTree(){
                //there are numGroups - 1 merges to do
                for (int i = 0; i < (numGroups - 1); i++) {
                        float largest = -1000.0;
-
+                       
+                       if (m->control_pressed) { delete t; return 1; }
+                       
                        int row, column;
                        //find largest value in sims matrix by searching lower triangle
                        for (int j = 1; j < simMatrix.size(); j++) {
@@ -386,11 +415,17 @@ void TreeGroupCommand::createTree(){
                //assemble tree
                t->assembleTree();
                
+               if (m->control_pressed) { delete t; return 1; }
+               
                //print newick file
                t->createNewickFile(outputFile);
                
                //delete tree
                delete t;
+               
+               if (m->control_pressed) { remove(outputFile.c_str()); outputNames.pop_back(); return 1; }
+               
+               return 0;
        
        }
        catch(exception& e) {
@@ -423,7 +458,7 @@ void TreeGroupCommand::printSims(ostream& out) {
        }
 }
 /***********************************************************/
-void TreeGroupCommand::makeSimsDist() {
+int TreeGroupCommand::makeSimsDist() {
        try {
                numGroups = list->size();
                
@@ -434,9 +469,9 @@ void TreeGroupCommand::makeSimsDist() {
                //initialize simMatrix
                simMatrix.clear();
                simMatrix.resize(numGroups);
-               for (int m = 0; m < simMatrix.size(); m++)      {
+               for (int k = 0; k < simMatrix.size(); k++)      {
                        for (int j = 0; j < simMatrix.size(); j++)      {
-                               simMatrix[m].push_back(0.0);
+                               simMatrix[k].push_back(0.0);
                        }
                }
                
@@ -445,10 +480,13 @@ void TreeGroupCommand::makeSimsDist() {
                for(MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++){
                        //similairity = -(distance-1)
                        simMatrix[currentCell->row][currentCell->column] = -(currentCell->dist -1.0);   
-                       simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);                           
+                       simMatrix[currentCell->column][currentCell->row] = -(currentCell->dist -1.0);   
+                       
+                       if (m->control_pressed) { return 1; }
+                       
                }
 
-
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "TreeGroupCommand", "makeSimsDist");
@@ -457,25 +495,14 @@ void TreeGroupCommand::makeSimsDist() {
 }
 
 /***********************************************************/
-void TreeGroupCommand::makeSimsShared() {
+int TreeGroupCommand::makeSimsShared() {
        try {
-       
-               //clear globaldatas old tree names if any
-               globaldata->Treenames.clear();
-               
-               //fills globaldatas tree names
-               globaldata->Treenames = globaldata->Groups;
-               
-               //create treemap class from groupmap for tree class to use
-               tmap = new TreeMap();
-               tmap->makeSim(globaldata->gGroupmap);
-               globaldata->gTreemap = tmap;
-               
                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) { for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; } return 1; }
                
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
                                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
@@ -508,6 +535,8 @@ void TreeGroupCommand::makeSimsShared() {
                        lookup = input->getSharedRAbundVectors();
                }
                
+               if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; } return 1; }
+
                //output error messages about any remaining user labels
                set<string>::iterator it;
                bool needToRun = false;
@@ -532,6 +561,8 @@ void TreeGroupCommand::makeSimsShared() {
                }
                
                for(int i = 0 ; i < treeCalculators.size(); i++) {  delete treeCalculators[i]; }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "TreeGroupCommand", "makeSimsShared");
@@ -540,7 +571,7 @@ void TreeGroupCommand::makeSimsShared() {
 }
 
 /***********************************************************/
-void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
+int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
        try{
                                EstOutput data;
                                vector<SharedRAbundVector*> subset;
@@ -551,9 +582,9 @@ void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                        //initialize simMatrix
                                        simMatrix.clear();
                                        simMatrix.resize(numGroups);
-                                       for (int m = 0; m < simMatrix.size(); m++)      {
+                                       for (int k = 0; k < simMatrix.size(); k++)      {
                                                for (int j = 0; j < simMatrix.size(); j++)      {
-                                                       simMatrix[m].push_back(0.0);
+                                                       simMatrix[k].push_back(0.0);
                                                }
                                        }
                
@@ -575,16 +606,24 @@ void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                                subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
                                                                
                                                                data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
+                                                               
+                                                               if (m->control_pressed) { return 1; }
+                                                               
                                                                //save values in similarity matrix
                                                                simMatrix[k][l] = data[0];
                                                                simMatrix[l][k] = data[0];
                                                        }
                                                }
                                        }
-                               
+                                       
+                                       if (m->control_pressed) { return 1; }
                                        //creates tree from similarity matrix and write out file
                                        createTree();
+                                       
+                                       if (m->control_pressed) { return 1; }
                                }
+                               
+                               return 0;
 
        }
        catch(exception& e) {
index 899716c6055b0dc12cbe493fc1ff3e5b8170d769..3e8fbb01c4df3c34540a11342a5a960a03788145 100644 (file)
@@ -40,10 +40,10 @@ public:
        void help();
        
 private:
-       void createTree();
+       int createTree();
        void printSims(ostream&);
-       void makeSimsShared();
-       void makeSimsDist();
+       int makeSimsShared();
+       int makeSimsDist();
        
        GlobalData* globaldata;
        ReadOTUFile* read;
@@ -71,7 +71,7 @@ private:
        vector<string>  Estimators, Groups, outputNames; //holds estimators to be used
        
        //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
-       void process(vector<SharedRAbundVector*>);
+       int process(vector<SharedRAbundVector*>);
        
        
 
index 1b5c7cf1416f9a8d4fe68ac3a1c6d7e751eb7d18..3d80f9e8ea23a2cbcf0456b230d69005940d12a9 100644 (file)
@@ -184,8 +184,6 @@ int TrimSeqsCommand::execute(){
        
                if (abort == true) { return 0; }
                
-               vector<string> outputNames;
-               
                numFPrimers = 0;  //this needs to be initialized
                numRPrimers = 0;
                
@@ -217,6 +215,22 @@ int TrimSeqsCommand::execute(){
                bool success;
 
                while(!inFASTA.eof()){
+               
+                       if (m->control_pressed) { 
+                               inFASTA.close(); 
+                               outFASTA.close();
+                               scrapFASTA.close();
+                               outGroups.close();
+                               if(qFileName != "")     {       qFile.close();  }
+                               for(int i=0;i<fastaFileNames.size();i++){
+                                       fastaFileNames[i]->close();
+                                       delete fastaFileNames[i];
+                               }       
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); }
+                               return 0;
+                       }
+
+                       
                        Sequence currSeq(inFASTA);
 
                        string origSeq = currSeq.getUnaligned();
@@ -311,6 +325,11 @@ int TrimSeqsCommand::execute(){
                        inFASTA.close();
                }
                
+               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();    }
@@ -365,6 +384,7 @@ void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec){
                                        
                                        if(allFiles){
                                                outFASTAVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta").c_str(), ios::ate));
+                                               outputNames.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta"));
                                        }
                                }
                        }
index 9b02be9ef5ec0f5a50d0563ab87a7f7d053bdadc..a93eba072eef5f9b6dd62b578331ee862272e76b 100644 (file)
@@ -38,7 +38,7 @@ private:
        
        bool flip, allFiles, qtrim;
        int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength, qThreshold, qAverage;
-       vector<string> forPrimer, revPrimer;
+       vector<string> forPrimer, revPrimer, outputNames;
        map<string, int> barcodes;
        vector<string> groupVector;
 };
index 01f6f98fceb7349fdaf9ccdce53afdf60aaff42c..28bc2ac55f64ebb02185a55d43ba9ea8e6faa03b 100644 (file)
@@ -134,6 +134,12 @@ int UnifracUnweightedCommand::execute() {
                
                //get pscores for users trees
                for (int i = 0; i < T.size(); i++) {
+                       if (m->control_pressed) { 
+                               outSum.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0; 
+                       }
+                       
                        counter = 0;
                        
                        if (random)  {  
@@ -141,6 +147,7 @@ int UnifracUnweightedCommand::execute() {
                                outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".unweighted");
                        }
                        
+                       
                        //get unweighted for users tree
                        rscoreFreq.resize(numComp);  
                        rCumul.resize(numComp);  
@@ -149,6 +156,13 @@ int UnifracUnweightedCommand::execute() {
 
                        userData = unweighted->getValues(T[i]);  //userData[0] = unweightedscore
                        
+                       if (m->control_pressed) { 
+                               if (random) { delete output;  }
+                               outSum.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0; 
+                       }
+                       
                        //output scores for each combination
                        for(int k = 0; k < numComp; k++) {
                                //saves users score
@@ -158,10 +172,17 @@ int UnifracUnweightedCommand::execute() {
                                validScores[userData[k]] = userData[k];
                        }
                        
-                       //get unweighted scores for random trees
+                       //get unweighted scores for random trees - if random is false iters = 0
                        for (int j = 0; j < iters; j++) {
                                //we need a different getValues because when we swap the labels we only want to swap those in each pairwise comparison
                                randomData = unweighted->getValues(T[i], "", "");
+                               
+                               if (m->control_pressed) { 
+                                       if (random) { delete output;  }
+                                       outSum.close();
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0; 
+                               }
                        
                                for(int k = 0; k < numComp; k++) {      
                                        //add trees unweighted score to map of scores
@@ -192,7 +213,15 @@ int UnifracUnweightedCommand::execute() {
                                if (random) {   UWScoreSig[a].push_back(rCumul[a][userData[a]]);        }
                                else            {       UWScoreSig[a].push_back(0.0);                                           }
                        }
-               
+                       
+                       
+                       if (m->control_pressed) { 
+                               if (random) { delete output;  }
+                               outSum.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0; 
+                       }
+                       
                        //print output files
                        printUWSummaryFile(i);
                        if (random)  {  printUnweightedFile();  delete output;  }
@@ -205,10 +234,11 @@ int UnifracUnweightedCommand::execute() {
                        UWScoreSig.clear(); 
                }
                
-               //reset groups parameter
-               globaldata->Groups.clear(); 
+
                outSum.close();
                
+               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();    }
index c6fc46ac0bce0437b2d04315442fcf33e045b4d3..f6f867877620e7e6e69e4e446bdbe8da3815861a 100644 (file)
@@ -23,7 +23,7 @@ class UnifracUnweightedCommand : public Command {
        
        public:
                UnifracUnweightedCommand(string);       
-               ~UnifracUnweightedCommand() { delete unweighted; delete util; }
+               ~UnifracUnweightedCommand() { globaldata->Groups.clear();  if (abort == false) { delete unweighted; delete util; } }
                int execute();
                void help();    
        
index 3c6c037147c3fb0a1a3da670dfaed6b63c2767e7..cd7fec12320e3ee50e415a348df4a5b503e35763 100644 (file)
@@ -128,6 +128,15 @@ int UnifracWeightedCommand::execute() {
                
                //get weighted scores for users trees
                for (int i = 0; i < T.size(); i++) {
+                       
+                       if (m->control_pressed) { 
+                               delete randT;
+                               if (random) { delete reading; }
+                               outSum.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0; 
+                       }
+
                        counter = 0;
                        rScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
                        uScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
@@ -139,6 +148,15 @@ int UnifracWeightedCommand::execute() {
 
                        userData = weighted->getValues(T[i]);  //userData[0] = weightedscore
                        
+                       if (m->control_pressed) { 
+                               delete randT;
+                               if (random) { delete reading; delete output; }
+                               outSum.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0; 
+                       }
+
+                       
                        //save users score
                        for (int s=0; s<numComp; s++) {
                                //add users score to vector of user scores
@@ -158,9 +176,27 @@ int UnifracWeightedCommand::execute() {
                                                 
                                                //create a random tree with same topology as T[i], but different labels
                                                randT->assembleRandomUnifracTree(globaldata->Groups[r], globaldata->Groups[l]);
+                                               
+                                               if (m->control_pressed) { 
+                                                       delete randT;
+                                                       if (random) { delete reading; delete output; }
+                                                       outSum.close();
+                                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                                       return 0; 
+                                               }
+
+
                                                //get wscore of random tree
                                                randomData = weighted->getValues(randT, globaldata->Groups[r], globaldata->Groups[l]);
                                                
+                                               if (m->control_pressed) { 
+                                                       delete randT;
+                                                       if (random) { delete reading; delete output; }
+                                                       outSum.close();
+                                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                                       return 0; 
+                                               }
+                                               
                                                //save scores
                                                rScores[count].push_back(randomData[0]);
                                                count++;
@@ -202,6 +238,15 @@ int UnifracWeightedCommand::execute() {
                        validScores.clear();
                }
                
+               
+               if (m->control_pressed) { 
+                               delete randT;
+                               if (random) { delete reading;  }
+                               outSum.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0; 
+               }
+               
                //finish progress bar
                if (random) {   reading->finish();      delete reading;         }
                
@@ -214,6 +259,11 @@ int UnifracWeightedCommand::execute() {
                
                delete randT;
                
+               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();    }
index 5bf6ee3616fb39f6d9ea4a3b4d048e45962f6c33..2a2a41cf0f6b823e3a781d9dabe53702e04d6f78 100644 (file)
@@ -49,6 +49,7 @@ EstOutput Unweighted::getValues(Tree* t) {
                                groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
                
                                for(int i=0;i<t->getNumNodes();i++){
+                                       if (m->control_pressed) {  return data; }
        
                                        copyIpcount = t->tree[i].pcount;
                                        for (it = copyIpcount.begin(); it != copyIpcount.end();) {
@@ -101,6 +102,8 @@ EstOutput Unweighted::getValues(Tree* t) {
                        copyIpcount.clear();
                                
                        for(int i=0;i<t->getNumNodes();i++){
+                       
+                               if (m->control_pressed) {  return data; }
                                
                                copyIpcount = t->tree[i].pcount;
                                for (it = copyIpcount.begin(); it != copyIpcount.end();) {
@@ -182,10 +185,14 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
                                //swap labels in the groups you want to compare
                                copyTree->assembleRandomUnifracTree(groups[0], groups[1]);
                                
+                               if (m->control_pressed) { delete copyTree; return data; }
+                               
                                //copyTree->createNewickFile("random"+groupA+toString(count));
                                
                                for(int i=0;i<copyTree->getNumNodes();i++){
-                                               
+                                       
+                                       if (m->control_pressed) { delete copyTree; return data; }
+                                       
                                        /**********************************************************************/
                                        //This section adds in all lengths that are non leaf
                                        copyIpcount = copyTree->tree[i].pcount;
@@ -242,8 +249,11 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
                                
                        //swap labels in all the groups you want to compare
                        copyTree->assembleRandomUnifracTree(groups);
+                       
+                       if (m->control_pressed) { delete copyTree; return data; }
 
                        for(int i=0;i<copyTree->getNumNodes();i++){
+                               if (m->control_pressed) { delete copyTree; return data; }
                        
                                copyIpcount = copyTree->tree[i].pcount;
                                for (it = copyIpcount.begin(); it != copyIpcount.end();) {
index 43129f5e2d8713e1608be534915cbe61276d1ea5..638a12fa817e6737d453c25e85b5b50cc66562d8 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -37,6 +37,8 @@ vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
                        string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
                        outputNames.push_back(filenamesvg);
                        openOutputFile(filenamesvg, outsvg);
+                       
+                       if (m->control_pressed) { outsvg.close(); return outputNames; }
 
                        vector<double> data = vCalcs[i]->getValues(sabund);
                        
@@ -83,7 +85,9 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
                                outputNames.push_back(filenamesvg);
                                openOutputFile(filenamesvg, outsvg);
-                       
+                               
+                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                               
                                //in essence you want to run it like a single 
                                if (vCalcs[i]->getName() == "sharedsobs") {
                                        singleCalc = new Sobs();
@@ -134,6 +138,8 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                outputNames.push_back(filenamesvg);
                                openOutputFile(filenamesvg, outsvg);
                                
+                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                               
                                //get estimates for sharedAB
                                vector<double> shared = vCalcs[i]->getValues(subset);
                                
@@ -203,6 +209,8 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                outputNames.push_back(filenamesvg);
                                openOutputFile(filenamesvg, outsvg);
                                
+                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                               
                                if (vCalcs[i]->getName() == "sharedace") {
                                
                                        singleCalc = new Ace(10);
@@ -459,7 +467,8 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                        outputNames.push_back(filenamesvg);
                                        openOutputFile(filenamesvg, outsvg);
 
-                               
+                                       if (m->control_pressed) { outsvg.close(); return outputNames; }
+                                       
                                        //in essence you want to run it like a single 
                                        if (vCalcs[i]->getName() == "sharedsobs") {
                                                singleCalc = new Sobs();
index 57228ad4c789124126d71781357f4328bfd143a5..35c814d2625a4f236667646801e01eb1b6c056bd 100644 (file)
@@ -173,6 +173,7 @@ VennCommand::~VennCommand(){
                delete read;
                delete venn;
                globaldata->sabund = NULL;
+               delete validCalculator;
        }
        
 }
@@ -216,6 +217,14 @@ int VennCommand::execute(){
                        
                        //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) {
+                                       for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
+                                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
+                                       globaldata->Groups.clear(); 
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0;
+                               }
 
                                if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
                                        m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
@@ -228,7 +237,7 @@ int VennCommand::execute(){
                                        }
                                        
                                        vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
-                                       for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } 
+                                       for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); }  }
                                }
                                
                                if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
@@ -246,7 +255,7 @@ int VennCommand::execute(){
                                                for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
                                        }                               
                                        vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
-                                       for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } 
+                                       for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); }  }
                                        
                                        //restore real lastlabel to save below
                                        lookup[0]->setLabel(saveLabel);
@@ -260,6 +269,14 @@ int VennCommand::execute(){
                                lookup = input->getSharedRAbundVectors();
                        }
                        
+                       if (m->control_pressed) {
+                                       for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
+                                       globaldata->Groups.clear(); 
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0;
+                       }
+
+                       
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -287,7 +304,7 @@ int VennCommand::execute(){
                                                for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
                                        }                               
                                        vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
-                                       for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } 
+                                       for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); }  }
 
                                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                        }
@@ -296,15 +313,29 @@ int VennCommand::execute(){
                        //reset groups parameter
                        globaldata->Groups.clear();  
                        
+                       if (m->control_pressed) {
+                                       for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0;
+                       }
+
+                       
                }else{
                
                        while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+                       
+                               if (m->control_pressed) {
+                                       for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
+                                       delete sabund;
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0;
+                               }
                
                                if(allLines == 1 || labels.count(sabund->getLabel()) == 1){                     
        
                                        m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
                                        vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
-                                       for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } 
+                                       for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); }  }
 
                                        
                                        processedLabels.insert(sabund->getLabel());
@@ -319,7 +350,7 @@ int VennCommand::execute(){
                                        
                                        m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
                                        vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
-                                       for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } 
+                                       for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); }  }
 
                                        
                                        processedLabels.insert(sabund->getLabel());
@@ -335,6 +366,12 @@ int VennCommand::execute(){
                                sabund = input->getSAbundVector();
                        }
                        
+                       if (m->control_pressed) {
+                                       for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0;
+                       }
+                       
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
                        bool needToRun = false;
@@ -355,12 +392,17 @@ int VennCommand::execute(){
                                        
                                m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
                                vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
-                               for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } 
+                               for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); }  }
 
                                delete sabund;
                                        
                        }
                        
+                       if (m->control_pressed) {
+                                       for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
+                                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                       return 0;
+                       }
                }
                
                for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
index 9a0d5d26d339aba5618e4811e65427fb61d9e251..a114d2ca0756c6fe671dc135acf0254ad1d5bf92 100644 (file)
@@ -33,6 +33,9 @@ EstOutput Weighted::getValues(Tree* t) {
                                /********************************************************/
                                //calculate a D value for each group combo
                                for(int v=0;v<t->getNumLeaves();v++){
+                               
+                                       if (m->control_pressed) { return data; }
+                                       
                                        int index = v;
                                        double sum = 0.0000;
                
@@ -87,6 +90,9 @@ EstOutput Weighted::getValues(Tree* t) {
                        //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
                        for (int b=0; b<numGroups; b++) { 
                                for (int l = b+1; l < numGroups; l++) {
+                               
+                                       if (m->control_pressed) { return data; }
+                                       
                                        //calculate a u value for each combo
                                        double u;
                                        //does this node have descendants from group b-1
@@ -148,6 +154,8 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) {
                /********************************************************/
                //calculate a D value for the group combo
                for(int v=0;v<t->getNumLeaves();v++){
+                       if (m->control_pressed) { return data; }
+                       
                        int index = v;
                        double sum = 0.0000;
                
@@ -191,6 +199,9 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) {
                
                //calculate u for the group comb 
                for(int i=0;i<t->getNumNodes();i++){
+               
+                       if (m->control_pressed) { return data; }
+                       
                        double u;
                        //does this node have descendants from groupA
                        it = t->tree[i].pcount.find(groupA);