Skip to content

Commit

Permalink
added checks for ^C to quit command instead of program
Browse files Browse the repository at this point in the history
  • Loading branch information
westcott committed Mar 3, 2010
1 parent 182db2b commit aa9238c
Show file tree
Hide file tree
Showing 125 changed files with 1,965 additions and 447 deletions.
18 changes: 11 additions & 7 deletions aligncommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ int AlignCommand::execute(){
vector<string> outputNames;

for (int s = 0; s < candidateFileNames.size(); s++) {
if (m->control_pressed) { return 0; }

m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine();

if (outputDir == "") { outputDir += hasPath(candidateFileNames[s]); }
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions alignmentdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions bayesian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -143,6 +146,8 @@ string Bayesian::bootstrapResults(vector<int> kmers, int tax, int numToSelect) {
map<int, int>::iterator itConvert;

for (int i = 0; i < iters; i++) {
if (m->control_pressed) { return "control"; }

vector<int> temp;

for (int j = 0; j < numToSelect; j++) {
Expand Down
39 changes: 35 additions & 4 deletions bellerophon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -89,17 +94,21 @@ 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"; }

}

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();
Expand Down Expand Up @@ -142,10 +151,15 @@ cout << "fastafile = " << fastafile << endl;
int count = 0;
while (count < iters) {

if (m->control_pressed) { return 0; }

//create 2 vectors of sequences, 1 for left side and one for right side
vector<Sequence> left; vector<Sequence> right;

for (int i = 0; i < seqs.size(); i++) {

if (m->control_pressed) { return 0; }

//cout << "midpoint = " << midpoint << "\twindow = " << window << endl;
//cout << "whole = " << seqs[i]->getAligned().length() << endl;
//save left side
Expand Down Expand Up @@ -176,8 +190,13 @@ cout << "fastafile = " << fastafile << endl;
SparseMatrix* SparseRight = new SparseMatrix();

createSparseMatrix(0, left.size(), SparseLeft, left);

if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }

createSparseMatrix(0, right.size(), SparseRight, right);

if (m->control_pressed) { delete SparseLeft; delete SparseRight; return 0; }

vector<SeqMap> distMapRight;
vector<SeqMap> distMapLeft;

Expand All @@ -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;
}

Expand Down Expand Up @@ -246,6 +267,8 @@ int Bellerophon::createSparseMatrix(int startSeq, int endSeq, SparseMatrix* spar
for(int i=startSeq; i<endSeq; i++){

for(int j=0;j<i;j++){

if (m->control_pressed) { return 0; }

distCalculator->calcDist(s[i], s[j]);
float dist = distCalculator->getDist();
Expand All @@ -264,7 +287,7 @@ int Bellerophon::createSparseMatrix(int startSeq, int endSeq, SparseMatrix* spar
}
}
/***************************************************************************************************************/
void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right, int mid){
int Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right, int mid){
try {

float dme = 0.0;
Expand All @@ -288,6 +311,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
SeqMap currentRight = right[i]; // same as left but with distances on the right side.

for (int j = 0; j < i; j++) {

if (m->control_pressed) { return 0; }

itL = currentLeft.find(j);
itR = currentRight.find(j);
Expand Down Expand Up @@ -352,6 +377,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
//cout << endl << "dme = " << dme << endl;
//recalculate prefernences based on dme
for (int i = 0; i < pref.size(); i++) {

if (m->control_pressed) { return 0; }
//cout << "unadjusted pref " << i << " = " << pref[i].score[1] << endl;
// gives the actual percentage of the dme this seq adds
pref[i].score[1] = pref[i].score[1] / dme;
Expand All @@ -368,6 +395,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
//is this score bigger then the last score
for (int i = 0; i < pref.size(); i++) {

if (m->control_pressed) { return 0; }

//update biggest score
if (pref[i].score[1] > pref[i].score[0]) {
pref[i].score[0] = pref[i].score[1];
Expand All @@ -379,6 +408,8 @@ void Bellerophon::generatePreferences(vector<SeqMap> left, vector<SeqMap> right,
}

}

return 1;

}
catch(exception& e) {
Expand Down
8 changes: 2 additions & 6 deletions bellerophon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +39,7 @@ class Bellerophon : public Chimera {
string fastafile;
int iters;

void generatePreferences(vector<SeqMap>, vector<SeqMap>, int);
int generatePreferences(vector<SeqMap>, vector<SeqMap>, int);
int createSparseMatrix(int, int, SparseMatrix*, vector<Sequence>);
};

Expand Down
7 changes: 6 additions & 1 deletion binsequencecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -230,7 +232,8 @@ int BinSeqCommand::execute(){
list = input->getListVector();
}


if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }

//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
Expand All @@ -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(); }
Expand Down
14 changes: 13 additions & 1 deletion bootstrapsharedcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -255,6 +256,9 @@ int BootSharedCommand::execute(){
order = input->getSharedOrderVector();
}


if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; }

//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
Expand All @@ -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; }
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit aa9238c

Please sign in to comment.