From aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3 Mon Sep 17 00:00:00 2001 From: westcott Date: Wed, 3 Mar 2010 12:33:53 +0000 Subject: [PATCH] added checks for ^C to quit command instead of program --- aligncommand.cpp | 18 ++++--- alignmentdb.cpp | 25 +++++----- bayesian.cpp | 5 ++ bellerophon.cpp | 39 +++++++++++++-- bellerophon.h | 8 +-- binsequencecommand.cpp | 7 ++- bootstrapsharedcommand.cpp | 14 +++++- ccode.cpp | 23 ++++++--- ccode.h | 2 +- chimera.cpp | 7 +++ chimera.h | 4 +- chimeracheckrdp.cpp | 8 ++- chimeracheckrdp.h | 4 +- chimeraseqscommand.cpp | 46 +++++++++++++++-- chimeraseqscommand.h | 2 +- chimeraslayer.cpp | 26 ++++++++-- chimeraslayer.h | 4 +- classifyseqscommand.cpp | 22 +++++++-- collectcommand.cpp | 64 +++++++++++++----------- collectsharedcommand.cpp | 61 +++++++++-------------- consensuscommand.cpp | 27 +++++++++- consensuscommand.h | 2 +- decalc.cpp | 2 + deconvolutecommand.cpp | 4 ++ distancecommand.cpp | 12 ++++- distancecommand.h | 2 +- dlibshuff.cpp | 14 +++++- engine.cpp | 16 ++++-- fastamap.cpp | 8 +++ filterseqscommand.cpp | 8 +++ formatcolumn.cpp | 15 +++++- formatcolumn.h | 2 +- formatmatrix.h | 2 +- formatphylip.cpp | 23 +++++++-- formatphylip.h | 2 +- fullmatrix.cpp | 30 ++++++++--- fullmatrix.h | 4 +- getgroupcommand.cpp | 6 +++ getlabelcommand.cpp | 3 ++ getlistcountcommand.cpp | 44 ++++++++++++++++- getoturepcommand.cpp | 50 +++++++++++++++++++ getrabundcommand.cpp | 16 ++++-- getsabundcommand.cpp | 11 +++++ getseqscommand.cpp | 44 ++++++++++++++--- getseqscommand.h | 12 ++--- getsharedotucommand.cpp | 19 ++++++- getsharedotucommand.h | 2 +- groupmap.cpp | 2 + hcluster.cpp | 15 ++++-- hcluster.h | 4 +- hclustercommand.cpp | 68 +++++++++++++++++++++++-- heatmap.cpp | 5 ++ heatmapcommand.cpp | 58 ++++++++++++++-------- heatmapsim.cpp | 16 ++++-- heatmapsimcommand.cpp | 22 ++++++++- knn.cpp | 4 ++ libshuffcommand.cpp | 40 +++++++++++++-- libshuffcommand.h | 4 +- listseqscommand.cpp | 40 ++++++++++++--- listseqscommand.h | 10 ++-- maligner.cpp | 11 ++++- matrixoutputcommand.cpp | 21 ++++++-- matrixoutputcommand.h | 2 +- mergefilecommand.cpp | 4 ++ mgclustercommand.cpp | 93 +++++++++++++++++++++++++++++++++++ mothur.cpp | 7 +++ mothurout.h | 1 + otuhierarchycommand.cpp | 17 ++++++- parselistscommand.cpp | 49 +++++++++++++++--- parselistscommand.h | 2 +- parsimony.cpp | 6 +++ parsimonycommand.cpp | 64 +++++++++++++++++++++++- parsimonycommand.h | 2 +- pcacommand.cpp | 28 ++++++----- pcacommand.h | 2 +- phylotypecommand.cpp | 15 ++++++ pintail.cpp | 40 +++++++++++++-- pintail.h | 4 +- preclustercommand.cpp | 12 ++++- progress.cpp | 3 ++ rarefact.cpp | 10 +++- rarefact.h | 4 +- rarefactcommand.cpp | 24 +++++++-- rarefactsharedcommand.cpp | 38 +++++++++++++- readblast.cpp | 45 +++++++++++++++-- readblast.h | 4 +- readcluster.cpp | 24 ++++++++- readcluster.h | 4 +- readcolumn.cpp | 13 ++++- readcolumn.h | 2 +- readdistcommand.cpp | 40 +++++---------- readmatrix.hpp | 4 +- readphylip.cpp | 26 ++++++++-- readphylip.h | 2 +- readtree.cpp | 3 ++ readtreecommand.cpp | 14 ++++++ removeseqscommand.cpp | 36 ++++++++++---- removeseqscommand.h | 10 ++-- reversecommand.cpp | 4 ++ screenseqscommand.cpp | 61 ++++++++++++++++++++--- screenseqscommand.h | 7 +-- secondarystructurecommand.cpp | 3 ++ seqsummarycommand.cpp | 6 +++ sharedcommand.cpp | 82 ++++++++++++++++++++++++++---- sharedcommand.h | 6 +-- slayer.cpp | 31 +++++++++++- slayer.h | 2 +- slibshuff.cpp | 13 ++++- summarycommand.cpp | 23 +++++++++ summarysharedcommand.cpp | 51 +++++++++++++++++-- summarysharedcommand.h | 2 +- taxonomyequalizer.cpp | 69 +++++++++++++++----------- tree.cpp | 6 ++- tree.h | 2 +- treegroupscommand.cpp | 87 +++++++++++++++++++++++--------- treegroupscommand.h | 8 +-- trimseqscommand.cpp | 24 ++++++++- trimseqscommand.h | 2 +- unifracunweightedcommand.cpp | 38 ++++++++++++-- unifracunweightedcommand.h | 2 +- unifracweightedcommand.cpp | 50 +++++++++++++++++++ unweighted.cpp | 12 ++++- venn.cpp | 13 ++++- venncommand.cpp | 54 +++++++++++++++++--- weighted.cpp | 11 +++++ 125 files changed, 1965 insertions(+), 447 deletions(-) diff --git a/aligncommand.cpp b/aligncommand.cpp index 94cba4a..257587f 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -213,6 +213,8 @@ int AlignCommand::execute(){ vector 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 diff --git a/alignmentdb.cpp b/alignmentdb.cpp index 59405ef..51fb175 100644 --- a/alignmentdb.cpp +++ b/alignmentdb.cpp @@ -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"); diff --git a/bayesian.cpp b/bayesian.cpp index 42fb023..af1fa27 100644 --- a/bayesian.cpp +++ b/bayesian.cpp @@ -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 kmers, int tax, int numToSelect) { map::iterator itConvert; for (int i = 0; i < iters; i++) { + if (m->control_pressed) { return "control"; } + vector temp; for (int j = 0; j < numToSelect; j++) { diff --git a/bellerophon.cpp b/bellerophon.cpp index 02b2829..2c545fe 100644 --- a/bellerophon.cpp +++ b/bellerophon.cpp @@ -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 left; vector 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 distMapRight; vector 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; icontrol_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 left, vector right, int mid){ +int Bellerophon::generatePreferences(vector left, vector right, int mid){ try { float dme = 0.0; @@ -288,6 +311,8 @@ void Bellerophon::generatePreferences(vector left, vector 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 left, vector 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 left, vector 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 left, vector right, } } + + return 1; } catch(exception& e) { diff --git a/bellerophon.h b/bellerophon.h index dd5b3da..3d05617 100644 --- a/bellerophon.h +++ b/bellerophon.h @@ -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, vector, int); + int generatePreferences(vector, vector, int); int createSparseMatrix(int, int, SparseMatrix*, vector); }; diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 1601f32..033cd52 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -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::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(); } diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index 6b76918..d174cdd 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -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::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); } diff --git a/ccode.cpp b/ccode.cpp index 00a30e5..3aad3f6 100644 --- 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 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 5d05cd6..afc77cc 100644 --- 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: diff --git a/chimera.cpp b/chimera.cpp index 820b475..7eeca96 100644 --- a/chimera.cpp +++ b/chimera.cpp @@ -28,6 +28,8 @@ string Chimera::createFilter(vector 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 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 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 diff --git a/chimera.h b/chimera.h index f6a5180..ef62b53 100644 --- 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 readSeqs(string); virtual vector< vector > 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: diff --git a/chimeracheckrdp.cpp b/chimeracheckrdp.cpp index 3e6dacd..790d3eb 100644 --- a/chimeracheckrdp.cpp +++ b/chimeracheckrdp.cpp @@ -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"); diff --git a/chimeracheckrdp.h b/chimeracheckrdp.h index 0ba851a..f54faab 100644 --- a/chimeracheckrdp.h +++ b/chimeracheckrdp.h @@ -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: diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp index 86d6d50..69ce031 100644 --- a/chimeraseqscommand.cpp +++ b/chimeraseqscommand.cpp @@ -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;inumSeqs;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) { diff --git a/chimeraseqscommand.h b/chimeraseqscommand.h index 56477a1..040d2dd 100644 --- a/chimeraseqscommand.h +++ b/chimeraseqscommand.h @@ -36,7 +36,7 @@ private: vector lines; int driver(linePair*, string, string, string); - void createProcesses(string, string, string); + int createProcesses(string, string, string); void appendOutputFiles(string, string); bool abort; diff --git a/chimeraslayer.cpp b/chimeraslayer.cpp index f865107..57ed713 100644 --- a/chimeraslayer.cpp +++ b/chimeraslayer.cpp @@ -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 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 = 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 diff --git a/chimeraslayer.h b/chimeraslayer.h index 14a22be..58e1656 100644 --- a/chimeraslayer.h +++ b/chimeraslayer.h @@ -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; diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 7a9a5e9..ba854e9 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -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 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;inumSeqs;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 diff --git a/collectcommand.cpp b/collectcommand.cpp index 9bf2c9a..cf8ba10 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -234,8 +234,8 @@ int CollectCommand::execute(){ set userLabels = labels; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iginput = 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;iginput = 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;iginput = 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;iginput = 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;iginput = NULL; + delete read; + delete validCalculator; + globaldata->Groups.clear(); + return 0; + } + //output error messages about any remaining user labels set::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;iginput = 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(); } diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 201709e..28e58b1 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -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;iginput = 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;iginput = 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;iGroups.clear(); + return 0; + } + //output error messages about any remaining user labels set::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;iginput = 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; } diff --git a/consensuscommand.cpp b/consensuscommand.cpp index dc27801..37cd395 100644 --- a/consensuscommand.cpp +++ b/consensuscommand.cpp @@ -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 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 nodeSet) { vector leftChildSet; vector 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 nodeSet) { } //********************************************************************************************************************** -void ConcensusCommand::getSets() { +int ConcensusCommand::getSets() { try { vector 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 small = getSmallest(nodePairsCopy); @@ -249,6 +271,7 @@ void ConcensusCommand::getSets() { nodePairsCopy.erase(small); } + return 0; } catch(exception& e) { m->errorOut(e, "ConcensusCommand", "getSets"); diff --git a/consensuscommand.h b/consensuscommand.h index 145bea5..7a79607 100644 --- a/consensuscommand.h +++ b/consensuscommand.h @@ -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); vector getSmallest(map< vector, int>); vector getNextAvailableSet(vector, vector&); diff --git a/decalc.cpp b/decalc.cpp index d4c4eb5..857bcf2 100644 --- a/decalc.cpp +++ b/decalc.cpp @@ -402,6 +402,8 @@ vector< vector > DeCalculator::getQuantiles(vector seqs, Sequence* subject = new Sequence(seqs[j]->getName(), seqs[j]->getAligned()); + if (m->control_pressed) { delete query; delete subject; return quan; } + map trim; map::iterator it; diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index fcfd320..663a6bf 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -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(); diff --git a/distancecommand.cpp b/distancecommand.cpp index 13f56eb..f05cb76 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -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;jcontrol_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"); diff --git a/distancecommand.h b/distancecommand.h index dedcc79..61fc49e 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -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); }; diff --git a/dlibshuff.cpp b/dlibshuff.cpp index 9db8872..4947e05 100644 --- a/dlibshuff.cpp +++ b/dlibshuff.cpp @@ -46,13 +46,23 @@ vector > 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 nx = calcN(minX); + + if (m->control_pressed) { return sum; } + vector nxy = calcN(minXY); - - double sum = 0; + + if (m->control_pressed) { return sum; } for(int i=0;imothurOutEndLine(); 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(); diff --git a/fastamap.cpp b/fastamap.cpp index 2831ecb..36b0721 100644 --- a/fastamap.cpp +++ b/fastamap.cpp @@ -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 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::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::iterator it = data.begin(); it != data.end(); it++) { + if (m->control_pressed) { break; } out << ">" << it->second.groupname << endl; out << it->first << endl; } diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index 91d1181..2fd1721 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -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(); diff --git a/formatcolumn.cpp b/formatcolumn.cpp index e13ead5..64b8531 100644 --- a/formatcolumn.cpp +++ b/formatcolumn.cpp @@ -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::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) { diff --git a/formatcolumn.h b/formatcolumn.h index c713867..0fe96ed 100644 --- a/formatcolumn.h +++ b/formatcolumn.h @@ -18,7 +18,7 @@ class FormatColumnMatrix : public FormatMatrix { public: FormatColumnMatrix(string); ~FormatColumnMatrix(); - void read(NameAssignment*); + int read(NameAssignment*); private: ifstream fileHandle; diff --git a/formatmatrix.h b/formatmatrix.h index 30e4276..7e7a99c 100644 --- a/formatmatrix.h +++ b/formatmatrix.h @@ -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; } diff --git a/formatphylip.cpp b/formatphylip.cpp index aaf540a..206df7e 100644 --- a/formatphylip.cpp +++ b/formatphylip.cpp @@ -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> name; list->set(i, name); for(int j=0;jcontrol_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;jcontrol_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"); diff --git a/formatphylip.h b/formatphylip.h index 9ca14bb..b920d08 100644 --- a/formatphylip.h +++ b/formatphylip.h @@ -19,7 +19,7 @@ class FormatPhylipMatrix : public FormatMatrix { public: FormatPhylipMatrix(string); ~FormatPhylipMatrix(); - void read(NameAssignment*); + int read(NameAssignment*); private: ifstream fileHandle; string filename; diff --git a/fullmatrix.cpp b/fullmatrix.cpp index 0255d07..7286649 100644 --- a/fullmatrix.cpp +++ b/fullmatrix.cpp @@ -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> 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;jcontrol_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;jcontrol_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"); diff --git a/fullmatrix.h b/fullmatrix.h index 15fee6e..e2c0e31 100644 --- a/fullmatrix.h +++ b/fullmatrix.h @@ -39,8 +39,8 @@ public: private: vector< vector > 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 index; // row in vector, sequence group. need to know this so when we sort it can be updated. vector sizes; vector groups; diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index b645517..817331f 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -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(); diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index d306250..1c08eb1 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -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) { diff --git a/getlistcountcommand.cpp b/getlistcountcommand.cpp index 6053f47..7757122 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -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 processedLabels; set 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; } diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 46a0407..e9373a9 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -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(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 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 processedLabels; set 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; diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 5a192c5..6b68c32 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -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 processedLabels; set 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; } diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index d9197fe..9260a5c 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -115,6 +115,9 @@ int GetSAbundCommand::execute(){ set processedLabels; set 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(); diff --git a/getseqscommand.cpp b/getseqscommand.cpp index ec05390..7535e65 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -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) { diff --git a/getseqscommand.h b/getseqscommand.h index 809109c..b574afe 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -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(); }; diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 2e553d9..7f87556 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -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 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) { diff --git a/getsharedotucommand.h b/getsharedotucommand.h index c12cc13..30a5cd2 100644 --- a/getsharedotucommand.h +++ b/getsharedotucommand.h @@ -41,7 +41,7 @@ class GetSharedOTUCommand : public Command { vector seqs; vector outputNames; - void process(ListVector*); + int process(ListVector*); }; //********************************************************************************************************************** diff --git a/groupmap.cpp b/groupmap.cpp index 8d0662f..939cdb9 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -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); diff --git a/hcluster.cpp b/hcluster.cpp index 7da10a2..07deaa5 100644 --- a/hcluster.cpp +++ b/hcluster.cpp @@ -502,7 +502,7 @@ vector 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"); diff --git a/hcluster.h b/hcluster.h index 5005ec6..7840650 100644 --- a/hcluster.h +++ b/hcluster.h @@ -38,8 +38,8 @@ protected: void updateMap(); vector getSeqsFNNN(); vector getSeqsAN(); - void combineFile(); - void processFile(); + int combineFile(); + int processFile(); //seqDist getNextDist(char*, int&, int); RAbundVector* rabund; diff --git a/hclustercommand.cpp b/hclustercommand.cpp index e6875b6..d9a14d9 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -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 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(); } diff --git a/heatmap.cpp b/heatmap.cpp index d05c700..3dca535 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -44,6 +44,8 @@ string HeatMap::getPic(RAbundVector* rabund) { for(int i=0;isize();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 << "\n"; y += 5; @@ -118,6 +121,7 @@ string HeatMap::getPic(vector lookup) { for(int i=0;isize(), ""); for(int j=0;jsize();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 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 << "\n"; x += 300; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index a91ef9d..5d7e1d6 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -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::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::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; } diff --git a/heatmapsim.cpp b/heatmapsim.cpp index 9a12550..4fb3e37 100644 --- a/heatmapsim.cpp +++ b/heatmapsim.cpp @@ -32,9 +32,11 @@ vector HeatMapSim::getPic(vector lookup, vector 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 HeatMapSim::getPic(vector lookup, vectorcontrol_pressed) { outsvg.close(); return outputNames; } + vector 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 > dists, vector 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); diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index 1b4b9d7..dc67a8d 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -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 processedLabels; set 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::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> matrix[i][j]; } + if (m->control_pressed) { return 0; } + + for(int j=0;j> 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> 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::iterator itA = nameMap->find(first); map::iterator itB = nameMap->find(second); diff --git a/knn.cpp b/knn.cpp index c11626a..93a7aa3 100644 --- a/knn.cpp +++ b/knn.cpp @@ -20,6 +20,8 @@ string Knn::getTaxonomy(Sequence* seq) { //use database to find closest seq vector closest = database->findClosestSequences(seq, num); + + if (m->control_pressed) { return tax; } vector closestNames; for (int i = 0; i < closest.size(); i++) { @@ -59,6 +61,7 @@ string Knn::findCommonTaxonomy(vector 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 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; diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index 93db3be..219b0bf 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -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;icontrol_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; } + Progress* reading = new Progress(); for(int i=0;icontrol_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;pcontrol_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;kcontrol_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;icontrol_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;icontrol_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;icontrol_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"); diff --git a/libshuffcommand.h b/libshuffcommand.h index 5155cbd..1c8fbc4 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -29,8 +29,8 @@ private: vector groupNames; void setGroups(); - void printCoverageFile(); - void printSummaryFile(); + int printCoverageFile(); + int printSummaryFile(); GlobalData* globaldata; FullMatrix* matrix; diff --git a/listseqscommand.cpp b/listseqscommand.cpp index f3710c9..d23949f 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -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; } diff --git a/listseqscommand.h b/listseqscommand.h index 04d9e1d..391ec9a 100644 --- a/listseqscommand.h +++ b/listseqscommand.h @@ -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(); }; diff --git a/maligner.cpp b/maligner.cpp index 76689e9..f06884f 100644 --- a/maligner.cpp +++ b/maligner.cpp @@ -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 > matrix = buildScoreMatrix(query->getAligned().length(), refSeqs.size()); //builds and initializes + if (m->control_pressed) { return chimera; } + fillScoreMatrix(matrix, refSeqs, chimeraPenalty); vector path = extractHighestPath(matrix); + if (m->control_pressed) { return chimera; } + vector 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; diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index 078f411..390f47f 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -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::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 thisLookup){ +int MatrixOutputCommand::process(vector thisLookup){ try { EstOutput data; @@ -313,9 +322,9 @@ void MatrixOutputCommand::process(vector 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 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 thisLookup){ } - + return 0; } catch(exception& e) { diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index 521104c..537f791 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -33,7 +33,7 @@ public: private: void printSims(ostream&); - void process(vector); + int process(vector); GlobalData* globaldata; ReadOTUFile* read; diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index 7e17b05..a076281 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -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(); diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index bf0b82b..6d5acb2 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -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 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 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 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 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 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 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; diff --git a/mothur.cpp b/mothur.cpp index 7cd77a1..a3eef76 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -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[]){ diff --git a/mothurout.h b/mothurout.h index ac1ec3f..d9c8e5d 100644 --- a/mothurout.h +++ b/mothurout.h @@ -25,6 +25,7 @@ class MothurOut { void mothurOutJustToLog(string); void errorOut(exception&, string, string); int control_pressed; + bool executing; private: diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index a8a3531..05d6443 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -110,6 +110,8 @@ int OtuHierarchyCommand::execute(){ //get listvectors that correspond to labels requested, (or use smart distancing to get closest listvector) vector 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 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 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 OtuHierarchyCommand::getListVectors() { }else { list = NULL; } } - + if (m->control_pressed) { in.close(); return lists; } //output error messages about any remaining user labels set::iterator it; @@ -279,6 +290,8 @@ vector 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 OtuHierarchyCommand::getListVectors() { } } - + in.close(); return lists; } catch(exception& e) { diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 4838988..9955a19 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -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; inamesOfGroups.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; inamesOfGroups.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; inamesOfGroups.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::iterator it; bool needToRun = false; @@ -191,13 +212,20 @@ int ParseListCommand::execute(){ } + if (m->control_pressed) { + delete input; delete groupMap; + for (i=0; inamesOfGroups.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 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 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) { diff --git a/parselistscommand.h b/parselistscommand.h index 8f91017..c765bcd 100644 --- a/parselistscommand.h +++ b/parselistscommand.h @@ -25,7 +25,7 @@ public: void help(); private: - void parse(ListVector*); + int parse(ListVector*); ListVector* list; GroupMap* groupMap; diff --git a/parsimony.cpp b/parsimony.cpp index 16c7748..0487822 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -49,6 +49,9 @@ EstOutput Parsimony::getValues(Tree* t) { } for(int i=copyTree->getNumLeaves();igetNumNodes();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::iterator it; for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ + + if (m->control_pressed) { return data; } + int lc = copyTree->tree[i].getLChild(); int rc = copyTree->tree[i].getRChild(); diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index 393c0f8..b87e9c0 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -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"); diff --git a/parsimonycommand.h b/parsimonycommand.h index 071aea8..6fa1914 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -59,7 +59,7 @@ private: vector Groups, outputNames; //holds groups to be used void printParsimonyFile(); - void printUSummaryFile(); + int printUSummaryFile(); void getUserInput(); }; diff --git a/pcacommand.cpp b/pcacommand.cpp index 644473a..c9fecd5 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -97,17 +97,11 @@ int PCACommand::execute(){ vector names; vector > 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 d; @@ -116,19 +110,22 @@ int PCACommand::execute(){ vector > 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& name_list, vector >& d){ +int PCACommand::read_phylip(istream& f, int square_m, vector& name_list, vector >& d){ try { // int count1=0; // int count2=0; @@ -181,6 +178,8 @@ void PCACommand::read_phylip(istream& f, int square_m, vector& name_list f >> name_list[i]; // cout << i << "\t" << name_list[i] << endl; for(int j=0;jcontrol_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& name_list f >> name_list[i]; d[i][i]=0.0000; for(int j=0;jcontrol_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& name_list } } } + + return 0; } catch(exception& e) { m->errorOut(e, "PCACommand", "read_phylip"); diff --git a/pcacommand.h b/pcacommand.h index 220e91f..089d1c1 100644 --- a/pcacommand.h +++ b/pcacommand.h @@ -30,7 +30,7 @@ private: vector outputNames; void get_comment(istream&, char, char); - void read_phylip(istream&, int, vector&, vector >&); + int read_phylip(istream&, int, vector&, vector >&); void read(string, vector&, vector >&); double pythag(double, double); void matrix_mult(vector >, vector >, vector >&); diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index e3b47d8..410ada9 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -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(); } diff --git a/pintail.cpp b/pintail.cpp index a2c7270..6e9e95c 100644 --- a/pintail.cpp +++ b/pintail.cpp @@ -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 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); diff --git a/pintail.h b/pintail.h index 2364c86..59d4fee 100644 --- 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(); }; diff --git a/preclustercommand.cpp b/preclustercommand.cpp index 66efd46..215b5bd 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -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; diff --git a/progress.cpp b/progress.cpp index 186a86e..ff93b34 100644 --- a/progress.cpp +++ b/progress.cpp @@ -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"); diff --git a/rarefact.cpp b/rarefact.cpp index 6acc24c..f5e7952 100644 --- a/rarefact.cpp +++ b/rarefact.cpp @@ -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;icontrol_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 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"); diff --git a/rarefact.h b/rarefact.h index 9e903ea..9eab51d 100644 --- a/rarefact.h +++ b/rarefact.h @@ -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; diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index c98b833..566561e 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -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;iinputFileName); read->read(&*globaldata); @@ -198,16 +202,21 @@ int RareFactCommand::execute(){ set processedLabels; set userLabels = labels; + if (m->control_pressed) { for(int i=0;iginput = 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;iginput = 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;iginput = 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::iterator it; bool needToRun = false; @@ -249,16 +260,18 @@ int RareFactCommand::execute(){ } } + if (m->control_pressed) { for(int i=0;iginput = 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(); } diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index b53e87d..37b54d1 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -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;imothurOut("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;igetLabel()) == 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::iterator it; bool needToRun = false; @@ -234,6 +256,13 @@ int RareFactSharedCommand::execute(){ } } + if (m->control_pressed) { + globaldata->Groups.clear(); + for(int i=0;iGroups.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(); } diff --git a/readblast.cpp b/readblast.cpp index 616d4f7..49e3708 100644 --- a/readblast.cpp +++ b/readblast.cpp @@ -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"); diff --git a/readblast.h b/readblast.h index 536d1af..fd32380 100644 --- a/readblast.h +++ b/readblast.h @@ -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 getOverlapMatrix() { return overlap; } string getOverlapFile() { return overlapFile; } @@ -42,7 +42,7 @@ private: vector overlap; MothurOut* m; - void readNames(NameAssignment*); + int readNames(NameAssignment*); }; /*******************************************************************************************/ diff --git a/readcluster.cpp b/readcluster.cpp index 1cf9fc3..acbebae 100644 --- a/readcluster.cpp +++ b/readcluster.cpp @@ -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 rowToName; @@ -96,6 +100,9 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ list->set(i, name); for(int j=0;jcontrol_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;jcontrol_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;jcontrol_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;jcontrol_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"); diff --git a/readcluster.h b/readcluster.h index d578a0f..4574c80 100644 --- a/readcluster.h +++ b/readcluster.h @@ -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*); }; /******************************************************/ diff --git a/readcolumn.cpp b/readcolumn.cpp index 12a38c2..d58b037 100644 --- a/readcolumn.cpp +++ b/readcolumn.cpp @@ -20,7 +20,7 @@ ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){ /***********************************************************************/ -void ReadColumnMatrix::read(NameAssignment* nameMap){ +int ReadColumnMatrix::read(NameAssignment* nameMap){ try { string firstName, secondName; @@ -38,8 +38,11 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ //need to see if this is a square or a triangular matrix... while(fileHandle && lt == 1){ //let's assume it's a triangular matrix... + fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance + + if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } map::iterator itA = nameMap->find(firstName); map::iterator itB = nameMap->find(secondName); @@ -97,6 +100,8 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ while(fileHandle){ fileHandle >> firstName >> secondName >> distance; + + if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } map::iterator itA = nameMap->find(firstName); map::iterator itB = nameMap->find(secondName); @@ -119,11 +124,15 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ gobble(fileHandle); } } - + + if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } + reading->finish(); fileHandle.close(); list->setLabel("0"); + + return 1; } catch(exception& e) { diff --git a/readcolumn.h b/readcolumn.h index 069632c..5e718af 100644 --- a/readcolumn.h +++ b/readcolumn.h @@ -18,7 +18,7 @@ class ReadColumnMatrix : public ReadMatrix { public: ReadColumnMatrix(string); ~ReadColumnMatrix(); - void read(NameAssignment*); + int read(NameAssignment*); private: ifstream fileHandle; string distFile; diff --git a/readdistcommand.cpp b/readdistcommand.cpp index c83ed8a..60d300f 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -204,13 +204,15 @@ int ReadDistCommand::execute(){ size_t numDists = 0; vector 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 dist_cutoff(lines+1,0); - for (int i = 0; i <= lines;i++) { - dist_cutoff[i] = (i + 0.5) / precision; - } - vector dist_count(lines+1,0); - list::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(); diff --git a/readmatrix.hpp b/readmatrix.hpp index 2c47832..d4edb5b 100644 --- a/readmatrix.hpp +++ b/readmatrix.hpp @@ -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; } diff --git a/readphylip.cpp b/readphylip.cpp index 6d7d4d0..edda415 100644 --- a/readphylip.cpp +++ b/readphylip.cpp @@ -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;icontrol_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;jcontrol_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> 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> name; matrixNames.push_back(name); + + if(nameMap == NULL){ list->set(i, name); for(int j=0;j> 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> 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) { diff --git a/readphylip.h b/readphylip.h index 9277338..3e5e749 100644 --- a/readphylip.h +++ b/readphylip.h @@ -18,7 +18,7 @@ class ReadPhylipMatrix : public ReadMatrix { public: ReadPhylipMatrix(string); ~ReadPhylipMatrix(); - void read(NameAssignment*); + int read(NameAssignment*); private: ifstream fileHandle; string distFile; diff --git a/readtree.cpp b/readtree.cpp index 661a5a9..3062f66 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -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 == '('){ diff --git a/readtreecommand.cpp b/readtreecommand.cpp index da66ee1..6065448 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -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 diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index c76c711..e8565d0 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -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"); diff --git a/removeseqscommand.h b/removeseqscommand.h index ddda08c..1f429d9 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -27,12 +27,12 @@ class RemoveSeqsCommand : public Command { bool abort, dups; vector outputNames; - void readFasta(); - void readName(); - void readGroup(); - void readAlign(); + int readFasta(); + int readName(); + int readGroup(); + int readAlign(); void readAccnos(); - void readList(); + int readList(); }; diff --git a/reversecommand.cpp b/reversecommand.cpp index 4efcbcc..114750e 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -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(); diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index bb8d1f5..5b3d7d7 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -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 badSeqNames){ +int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ ifstream inputNames; openInputFile(namefile, inputNames); @@ -232,10 +246,14 @@ void ScreenSeqsCommand::screenNameGroupFile(set 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 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 badSeqNames){ } } } + + return 0; + } //*************************************************************************************************************** -void ScreenSeqsCommand::screenGroupFile(set badSeqNames){ +int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ ifstream inputGroups; openInputFile(groupfile, inputGroups); @@ -321,10 +346,14 @@ void ScreenSeqsCommand::screenGroupFile(set 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 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 badSeqNames){ goodGroupOut.close(); badGroupOut.close(); + if (m->control_pressed) { remove(goodGroupFile.c_str()); remove(badGroupFile.c_str()); } + + + return 0; + } //*************************************************************************************************************** -void ScreenSeqsCommand::screenAlignReport(set badSeqNames){ +int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ ifstream inputAlignReport; openInputFile(alignreport, inputAlignReport); @@ -364,6 +400,8 @@ void ScreenSeqsCommand::screenAlignReport(set 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 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 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 badSeqNames){ inputAlignReport.close(); goodAlignReportOut.close(); badAlignReportOut.close(); + + if (m->control_pressed) { remove(goodAlignReportFile.c_str()); remove(badAlignReportFile.c_str()); return 0; } + + return 0; + } diff --git a/screenseqscommand.h b/screenseqscommand.h index 5b44091..54f4bb1 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -21,13 +21,14 @@ public: void help(); private: - void screenNameGroupFile(set); - void screenGroupFile(set); - void screenAlignReport(set); + int screenNameGroupFile(set); + int screenGroupFile(set); + int screenAlignReport(set); bool abort; string fastafile, namefile, groupfile, alignreport, outputDir; int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength; + vector outputNames; }; #endif diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index e23a0ac..dc40611 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -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(); diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index 49edc36..4514e01 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -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(); diff --git a/sharedcommand.cpp b/sharedcommand.cpp index f03152b..213fd49 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -49,6 +49,7 @@ SharedCommand::SharedCommand(string o) : outputDir(o) { //clears file before we start to write to it below for (int i=0; igetLabel(); vector 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; iGroups.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 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; iallLines == 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; igetSharedListVector(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; igetSharedListVector(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; isetListFile(""); globaldata->setGroupFile(""); globaldata->setSharedFile(filename); - + + if (m->control_pressed) { + delete input; globaldata->ginput = NULL; + remove(filename.c_str()); + for (int i=0; imothurOutEndLine(); + 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 thislookup) { } } //********************************************************************************************************************** -void SharedCommand::eliminateZeroOTUS(vector& thislookup) { +int SharedCommand::eliminateZeroOTUS(vector& thislookup) { try { vector newLookup; @@ -250,6 +307,7 @@ void SharedCommand::eliminateZeroOTUS(vector& 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& 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& 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"); diff --git a/sharedcommand.h b/sharedcommand.h index 3d39b8b..399f3d3 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -33,16 +33,16 @@ public: private: void printSharedData(vector); - void createMisMatchFile(); + int createMisMatchFile(); bool isValidGroup(string, vector); - void eliminateZeroOTUS(vector&); + int eliminateZeroOTUS(vector&); GlobalData* globaldata; ReadOTUFile* read; SharedListVector* SharedList; InputData* input; GroupMap* groupMap; - vector groups; + vector groups, outputNames; ofstream out; string filename, fileroot, outputDir; bool firsttime, pickedGroups; diff --git a/slayer.cpp b/slayer.cpp index 2d079cd..5d5a48b 100644 --- a/slayer.cpp +++ b/slayer.cpp @@ -20,6 +20,8 @@ string Slayer::getResults(Sequence* query, vector 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 refSeqs) { map spots; //map from spot in original sequence to spot in filtered sequence for query and both parents vector divs = runBellerophon(q, leftParent, rightParent, spots); + if (m->control_pressed) { + delete q; + delete leftParent; + delete rightParent; + return "no"; + } + vector selectedDivs; for (int k = 0; k < divs.size(); k++) { vector snpsLeft = getSNPS(divs[k].parentA.getAligned(), divs[k].querySeq.getAligned(), divs[k].parentB.getAligned(), divs[k].winLStart, divs[k].winLEnd); vector 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 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 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 Slayer::getSNPS(string parentA, string query, string parentB, int l } } /***********************************************************************/ -void Slayer::bootstrapSNPS(vector left, vector right, float& BSA, float& BSB) { +int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, float& BSB) { try { srand((unsigned)time( NULL )); @@ -276,6 +301,8 @@ void Slayer::bootstrapSNPS(vector left, vector right, float& BSA, fl for (int i = 0; i < iters; i++) { //random sampling with replacement. + if (m->control_pressed) { return 0; } + vector selectedLeft; for (int j = 0; j < numLeft; j++) { @@ -339,6 +366,8 @@ void Slayer::bootstrapSNPS(vector left, vector 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) { diff --git a/slayer.h b/slayer.h index d746b47..33ccc3f 100644 --- a/slayer.h +++ b/slayer.h @@ -83,7 +83,7 @@ class Slayer { vector runBellerophon(Sequence*, Sequence*, Sequence*, map&); vector getSNPS(string, string, string, int, int); - void bootstrapSNPS(vector, vector, float&, float&); + int bootstrapSNPS(vector, vector, float&, float&); float snpQA(vector); float snpQB(vector); float snpAB(vector); diff --git a/slibshuff.cpp b/slibshuff.cpp index e1ffb0e..92998e6 100644 --- a/slibshuff.cpp +++ b/slibshuff.cpp @@ -53,13 +53,24 @@ vector > 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]); diff --git a/summarycommand.cpp b/summarycommand.cpp index 12382a4..5ad1ee6 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -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 processedLabels; set 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;isabund = 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;isabund = 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 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;isabund = 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 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;isabund = 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;iginput = NULL; return 0; } + //output error messages about any remaining user labels set::iterator it; bool needToRun = false; @@ -296,6 +310,9 @@ int SummaryCommand::execute(){ outputFileHandle << sabund->getLabel(); for(int i=0;i 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;isabund = 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;iginput = NULL; return 0; } + + delete input; globaldata->ginput = NULL; delete read; delete validCalculator; globaldata->sabund = NULL; + for(int i=0;icontrol_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(); } diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index b6b4f52..b8956ec 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -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;iGroups.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 processedLabels; set 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;iGroups.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;iGroups.clear(); + return 0; + } + //output error messages about any remaining user labels set::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;iginput = 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 thisLookup) { +int SummarySharedCommand::process(vector 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 thisLookup) { for(int i=0;igetMultiple() == 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 thisLookup) { for(int i=0;igetValues(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 thisLookup) { } n++; } - + return 0; } catch(exception& e) { m->errorOut(e, "SummarySharedCommand", "process"); diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 8f37eeb..bcd8ab6 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -41,7 +41,7 @@ private: vector lookup; string outputFileName, format, outAllFileName, outputDir; ofstream outputFileHandle, outAll; - void process(vector); + int process(vector); }; diff --git a/taxonomyequalizer.cpp b/taxonomyequalizer.cpp index f3ccfe4..fc36eb6 100644 --- a/taxonomyequalizer.cpp +++ b/taxonomyequalizer.cpp @@ -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"); diff --git a/tree.cpp b/tree.cpp index eca53d5..7da3cef 100644 --- 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 04d9fb1..23ddf5d 100644 --- 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 tree; //the first n nodes are the leaves, where n is the number of sequences. diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 6ce5ee9..c4e58c2 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -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 processedLabels; set 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::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 thisLookup) { +int TreeGroupCommand::process(vector thisLookup) { try{ EstOutput data; vector subset; @@ -551,9 +582,9 @@ void TreeGroupCommand::process(vector 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 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) { diff --git a/treegroupscommand.h b/treegroupscommand.h index 899716c..3e8fbb0 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -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 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); + int process(vector); diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 1b5c7cf..3d80f9e 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -184,8 +184,6 @@ int TrimSeqsCommand::execute(){ if (abort == true) { return 0; } - vector 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;iclose(); + 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& 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")); } } } diff --git a/trimseqscommand.h b/trimseqscommand.h index 9b02be9..a93eba0 100644 --- a/trimseqscommand.h +++ b/trimseqscommand.h @@ -38,7 +38,7 @@ private: bool flip, allFiles, qtrim; int numFPrimers, numRPrimers, maxAmbig, maxHomoP, minLength, maxLength, qThreshold, qAverage; - vector forPrimer, revPrimer; + vector forPrimer, revPrimer, outputNames; map barcodes; vector groupVector; }; diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 01f6f98..28bc2ac 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -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(); } diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index c6fc46a..f6f8678 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -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(); diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 3c6c037..cd7fec1 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -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; sassembleRandomUnifracTree(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(); } diff --git a/unweighted.cpp b/unweighted.cpp index 5bf6ee3..2a2a41c 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -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;igetNumNodes();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;igetNumNodes();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;igetNumNodes();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;igetNumNodes();i++){ + if (m->control_pressed) { delete copyTree; return data; } copyIpcount = copyTree->tree[i].pcount; for (it = copyIpcount.begin(); it != copyIpcount.end();) { diff --git a/venn.cpp b/venn.cpp index 43129f5..638a12f 100644 --- a/venn.cpp +++ b/venn.cpp @@ -37,6 +37,8 @@ vector Venn::getPic(SAbundVector* sabund, vector 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 data = vCalcs[i]->getValues(sabund); @@ -83,7 +85,9 @@ vector Venn::getPic(vector lookup, vectorinputFileName) + 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 Venn::getPic(vector lookup, vectorcontrol_pressed) { outsvg.close(); return outputNames; } + //get estimates for sharedAB vector shared = vCalcs[i]->getValues(subset); @@ -203,6 +209,8 @@ vector Venn::getPic(vector lookup, vectorcontrol_pressed) { outsvg.close(); return outputNames; } + if (vCalcs[i]->getName() == "sharedace") { singleCalc = new Ace(10); @@ -459,7 +467,8 @@ vector Venn::getPic(vector lookup, vectorcontrol_pressed) { outsvg.close(); return outputNames; } + //in essence you want to run it like a single if (vCalcs[i]->getName() == "sharedsobs") { singleCalc = new Sobs(); diff --git a/venncommand.cpp b/venncommand.cpp index 57228ad..35c814d 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -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 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 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::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 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 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 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::iterator it; bool needToRun = false; @@ -355,12 +392,17 @@ int VennCommand::execute(){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); vector 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]; } diff --git a/weighted.cpp b/weighted.cpp index 9a0d5d2..a114d2c 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -33,6 +33,9 @@ EstOutput Weighted::getValues(Tree* t) { /********************************************************/ //calculate a D value for each group combo for(int v=0;vgetNumLeaves();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; bcontrol_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;vgetNumLeaves();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;igetNumNodes();i++){ + + if (m->control_pressed) { return data; } + double u; //does this node have descendants from groupA it = t->tree[i].pcount.find(groupA); -- 2.39.2