lines.push_back(new linePair(0, numFastaSeqs));
- driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+ int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+ if (exitCommand == 0) {
+ remove(accnosFileName.c_str());
+ remove(alignFileName.c_str());
+ remove(reportFileName.c_str());
+ return 0;
+ }
//delete accnos file if its blank else report to user
if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; }
lines.push_back(new linePair(startPos, numSeqsPerProcessor));
}
- createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+ int exitCommand = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
rename((alignFileName + toString(processIDS[0]) + ".temp").c_str(), alignFileName.c_str());
rename((reportFileName + toString(processIDS[0]) + ".temp").c_str(), reportFileName.c_str());
}else{ m->mothurOut(" If the reverse compliment proved to be better it was reported."); }
m->mothurOutEndLine();
}else{ hasAccnos = false; }
+
+ if (exitCommand == 0) {
+ remove(accnosFileName.c_str());
+ remove(alignFileName.c_str());
+ remove(reportFileName.c_str());
+ return 0;
+ }
}
#else
ifstream inFASTA;
lines.push_back(new linePair(0, numFastaSeqs));
- driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+ int exitCommand = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]);
+ if (exitCommand == 0) {
+ remove(accnosFileName.c_str());
+ remove(alignFileName.c_str());
+ remove(reportFileName.c_str());
+ return 0;
+ }
//delete accnos file if its blank else report to user
if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; }
inFASTA.seekg(line->start);
for(int i=0;i<line->numSeqs;i++){
-
+
+ if (m->control_pressed) { return 0; }
+
Sequence* candidateSeq = new Sequence(inFASTA); gobble(inFASTA);
int origNumBases = candidateSeq->getNumBases();
string originalUnaligned = candidateSeq->getUnaligned();
/**************************************************************************************************/
-void AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
+int AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) {
try {
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
int process = 0;
+ int exitCommand;
// processIDS.resize(0);
//loop through and create all the processes you want
processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
process++;
}else if (pid == 0){
- driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
+ exitCommand = driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename);
exit(0);
}else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
}
int temp = processIDS[i];
wait(&temp);
}
+
+ return exitCommand;
#endif
}
catch(exception& e) {
Alignment* alignment;
int driver(linePair*, string, string, string, string);
- void createProcesses(string, string, string, string);
+ int createProcesses(string, string, string, string);
void appendAlignFiles(string, string);
void appendReportFiles(string, string);
readNamesFile();
}
+
//read list file
read = new ReadOTUFile(globaldata->getListFile());
read->read(&*globaldata);
list = globaldata->gListVector;
string lastLabel = list->getLabel();
+ if (m->control_pressed) { return 0; }
+
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = labels;
if(allLines == 1 || labels.count(list->getLabel()) == 1){
error = process(list);
- if (error == 1) { return 0; }
+ if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
list = input->getListVector(lastLabel);
error = process(list);
- if (error == 1) { return 0; }
+ if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
processedLabels.insert(list->getLabel());
userLabels.erase(list->getLabel());
list = input->getListVector(lastLabel);
error = process(list);
- if (error == 1) { return 0; }
+ if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
delete list;
}
//for each bin in the list vector
for (int i = 0; i < list->size(); i++) {
-
+
+ if (m->control_pressed) { return 1; }
+
binnames = list->get(i);
while (binnames.find_first_of(',') != -1) {
name = binnames.substr(0,binnames.find_first_of(','));
string group = groupMap->getGroup(name);
if (group == "not found") {
m->mothurOut(name + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
- remove(outputFileName.c_str());
return 1;
}else{
name = name + "|" + group + "|" + toString(i+1);
}
}else {
m->mothurOut(name + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine();
- remove(outputFileName.c_str());
return 1;
}
string group = groupMap->getGroup(binnames);
if (group == "not found") {
m->mothurOut(binnames + " is missing from your group file. Please correct. "); m->mothurOutEndLine();
- remove(outputFileName.c_str());
return 1;
}else{
binnames = binnames + "|" + group + "|" + toString(i+1);
}
}else {
m->mothurOut(binnames + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine();
- remove(outputFileName.c_str());
return 1;
}
}
if(allLines == 1 || labels.count(order->getLabel()) == 1){
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
- process(order);
+ int error = process(order);
+ if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
delete order;
order = input->getSharedOrderVector(lastLabel);
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
- process(order);
+ int error = process(order);
+ if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
if (order != NULL) { delete order; }
order = input->getSharedOrderVector(lastLabel);
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
- process(order);
+ int error = process(order);
+ if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
delete order;
}
}
//**********************************************************************************************************************
-void BootSharedCommand::createTree(ostream* out, Tree* t){
+int BootSharedCommand::createTree(ostream* out, Tree* t){
try {
//do merges and create tree structure by setting parents and children
//there are numGroups - 1 merges to do
for (int i = 0; i < (numGroups - 1); i++) {
+ if (m->control_pressed) { return 1; }
+
float largest = -1000.0;
int row, column;
//find largest value in sims matrix by searching lower triangle
//print newick file
t->print(*out);
+
+ return 0;
}
catch(exception& e) {
}
}
/***********************************************************/
-void BootSharedCommand::process(SharedOrderVector* order) {
+int BootSharedCommand::process(SharedOrderVector* order) {
try{
EstOutput data;
vector<SharedRAbundVector*> subset;
//create a file for each calculator with the 1000 trees in it.
for (int p = 0; p < iters; p++) {
+ if (m->control_pressed) { return 1; }
+
util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order); //fills group vectors from order vector.
//for each calculator
for(int i = 0 ; i < treeCalculators.size(); i++) {
-
+
+ if (m->control_pressed) { return 1; }
+
//initialize simMatrix
simMatrix.clear();
simMatrix.resize(numGroups);
- for (int m = 0; m < simMatrix.size(); m++) {
+ for (int o = 0; o < simMatrix.size(); o++) {
for (int j = 0; j < simMatrix.size(); j++) {
- simMatrix[m].push_back(0.0);
+ simMatrix[o].push_back(0.0);
}
}
tempTree = new Tree();
+ if (m->control_pressed) { delete tempTree; return 1; }
+
//creates tree from similarity matrix and write out file
createTree(out[i], tempTree);
m->mothurOut("Generating consensus tree for " + treeCalculators[k]->getName()); m->mothurOutEndLine();
+ if (m->control_pressed) { return 1; }
+
//set global data to calc trees
globaldata->gTree = trees[k];
//close ostream for each calc
for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); }
+
+ return 0;
}
catch(exception& e) {
void help();
private:
- void createTree(ostream*, Tree*);
+ int createTree(ostream*, Tree*);
void printSims();
- void process(SharedOrderVector*);
+ int process(SharedOrderVector*);
GlobalData* globaldata;
double saveCutoff = cutoff;
while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){
+
+ if (m->control_pressed) { //clean up
+ delete globaldata->gSparseMatrix; globaldata->gSparseMatrix = NULL;
+ delete globaldata->gListVector; globaldata->gListVector = NULL;
+ if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); }
+ else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); }
+ sabundFile.close();rabundFile.close();listFile.close();
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
if (print_start && isTrue(timing)) {
m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/"
+ toString(roundDist(matrix->getSmallDist(), precision))
/***********************************************************************/
-void Collect::getCurve(int increment = 1){
+int Collect::getCurve(int increment = 1){
try {
RAbundVector* lookup = new RAbundVector(order->getNumBins());
SAbundVector* rank = new SAbundVector(order->getMaxRank()+1);
displays[i]->init(label); //sets displays label
}
for(int i=0;i<numSeqs;i++){
-
+
+ if (m->control_pressed) { delete lookup; delete rank; delete ccd; return 1; }
+
int binNumber = order->get(i);
int abundance = lookup->get(binNumber);
delete lookup;
delete rank;
delete ccd;
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "Collect", "getCurve");
}
/***********************************************************************/
-void Collect::getSharedCurve(int increment = 1){
+int Collect::getSharedCurve(int increment = 1){
try {
globaldata = GlobalData::getInstance();
vector<SharedRAbundVector*> lookup;
//sample all the members
for(int i=0;i<numSeqs;i++){
+
+ if (m->control_pressed) { for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } delete ccd; return 1; }
+
//get first sample
individual chosen = sharedorder->get(i);
int abundance;
for (int i = 0; i < lookup.size(); i++) {
delete lookup[i];
}
+
+ return 0;
}
catch(exception& e) {
numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel()) { m = MothurOut::getInstance(); }
~Collect(){ };
- void getCurve(int);
- void getSharedCurve(int);
+ int getCurve(int);
+ int getSharedCurve(int);
private:
SharedOrderVector* sharedorder;
else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); }
for (int p = 0; p < inputFileNames.size(); p++) {
-
+
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }
+
if (outputDir == "") { outputDir += hasPath(inputFileNames[p]); }
string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p]));
globaldata->inputFileName = inputFileNames[p];
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = labels;
+
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
if(allLines == 1 || labels.count(order->getLabel()) == 1){
cCurve = new Collect(order, cDisplays);
- cCurve->getCurve(freq);
+ int error = cCurve->getCurve(freq);
delete cCurve;
+ if (error == 1) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
order = (input->getOrderVector(lastLabel));
cCurve = new Collect(order, cDisplays);
- cCurve->getCurve(freq);
+ int error = cCurve->getCurve(freq);
delete cCurve;
+ if (error == 1) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
userLabels.erase(order->getLabel());
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
cCurve = new Collect(order, cDisplays);
- cCurve->getCurve(freq);
+ int error = cCurve->getCurve(freq);
delete cCurve;
+
+ if (error == 1) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
delete order;
}
//create collectors curve
cCurve = new Collect(order, cDisplays);
- cCurve->getSharedCurve(freq);
+ int error = cCurve->getSharedCurve(freq);
delete cCurve;
+
+ if (error == 1) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
//create collectors curve
cCurve = new Collect(order, cDisplays);
- cCurve->getSharedCurve(freq);
+ int error = cCurve->getSharedCurve(freq);
delete cCurve;
+
+ if (error == 1) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
processedLabels.insert(order->getLabel());
order = input->getSharedOrderVector(lastLabel);
cCurve = new Collect(order, cDisplays);
- cCurve->getSharedCurve(freq);
+ int error = cCurve->getSharedCurve(freq);
delete cCurve;
+ if (error == 1) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
+ delete input; globaldata->ginput = NULL;
+ delete read;
+ delete order; globaldata->gorder = NULL;
+ delete validCalculator;
+ globaldata->Groups.clear();
+ return 0;
+ }
+
+
m->mothurOut(order->getLabel()); m->mothurOutEndLine();
delete order;
}
//executes valid command
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
+ mout->control_pressed = 0;
}else {
mout->mothurOut("Your input contains errors. Please try again.");
//executes valid command
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
+ mout->control_pressed = 0;
}else {
mout->mothurOut("Invalid.");
mout->mothurOutEndLine();
//executes valid command
Command* command = cFactory->getCommand(commandName, options);
quitCommandCalled = command->execute();
+ mout->control_pressed = 0;
}else {
mout->mothurOut("Invalid.");
mout->mothurOutEndLine();
CommandFactory* CommandFactory::_uniqueInstance = 0;
MothurOut* MothurOut::_uniqueInstance = 0;
+/***********************************************************************/
+volatile int ctrlc_pressed = 0;
+void ctrlc_handler ( int sig ) {
+ MothurOut* m = MothurOut::getInstance();
+ ctrlc_pressed = 1;
+ m->control_pressed = ctrlc_pressed;
+}
+/***********************************************************************/
int main(int argc, char *argv[]){
MothurOut* m = MothurOut::getInstance();
try {
- //string log = "mothur.logFile";
- //remove(log.c_str());
-
+ signal(SIGINT, ctrlc_handler );
+
time_t ltime = time(NULL); /* calendar time */
string logFileName = "mothur." + toString(ltime) + ".logfile";
return output.str();
}
/***********************************************************************/
-
inline int openOutputFileAppend(string fileName, ofstream& fileHandle){
fileHandle.open(fileName.c_str(), ios::app);
--- /dev/null
+/*
+ * m->mothurOut.cpp
+ * Mothur
+ *
+ * Created by westcott on 2/25/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "mothurout.h"
+
+/******************************************************/
+MothurOut* MothurOut::getInstance() {
+ if( _uniqueInstance == 0) {
+ _uniqueInstance = new MothurOut();
+ }
+ return _uniqueInstance;
+}
+/*********************************************************************************************/
+void MothurOut::setFileName(string filename) {
+ try {
+ logFileName = filename;
+ openOutputFile(filename, out);
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "setFileName");
+ exit(1);
+ }
+}
+/*********************************************************************************************/
+MothurOut::~MothurOut() {
+ try {
+ _uniqueInstance = 0;
+ out.close();
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "MothurOut");
+ exit(1);
+ }
+}
+
+/*********************************************************************************************/
+void MothurOut::mothurOut(string output) {
+ try {
+
+ cout << output;
+ out << output;
+
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "MothurOut");
+ exit(1);
+ }
+}
+/*********************************************************************************************/
+void MothurOut::mothurOutEndLine() {
+ try {
+ cout << endl;
+ out << endl;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "MothurOutEndLine");
+ exit(1);
+ }
+}
+/*********************************************************************************************/
+void MothurOut::mothurOutJustToLog(string output) {
+ try {
+ out << output;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "MothurOutJustToLog");
+ exit(1);
+ }
+}
+/*********************************************************************************************/
+void MothurOut::errorOut(exception& e, string object, string function) {
+ mothurOut("Error: ");
+ mothurOut(toString(e.what()));
+ mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");
+ mothurOutEndLine();
+}
+/*********************************************************************************************/
+
+
+
+
+
--- /dev/null
+#ifndef MOTHUROUT_H
+#define MOTHUROUT_H
+
+/*
+ * m->mothurOut.h
+ * Mothur
+ *
+ * Created by westcott on 2/25/10.
+ * Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "mothur.h"
+
+/***********************************************/
+
+class MothurOut {
+
+ public:
+ static MothurOut* getInstance();
+ void setFileName(string);
+
+ void mothurOut(string);
+ void mothurOutEndLine();
+ void mothurOutJustToLog(string);
+ void errorOut(exception&, string, string);
+ int control_pressed;
+
+
+ private:
+ static MothurOut* _uniqueInstance;
+ MothurOut( const MothurOut& ); // Disable copy constructor
+ void operator=( const MothurOut& ); // Disable assignment operator
+ MothurOut() {};
+ ~MothurOut();
+
+ string logFileName;
+ ofstream out;
+
+};
+/***********************************************/
+
+#endif
+