From 0c78e45408d8c099bc51579225ebfc227f7523b2 Mon Sep 17 00:00:00 2001 From: westcott Date: Thu, 24 Jun 2010 17:18:38 +0000 Subject: [PATCH] created blank accnos in chimera commands if no seqs are deemed chimeric. modified get.seqs and remove.seqs to handle blank files --- chimerabellerophoncommand.cpp | 6 +---- chimeraccodecommand.cpp | 48 +++++---------------------------- chimeraccodecommand.h | 2 +- chimerapintailcommand.cpp | 50 +++++----------------------------- chimerapintailcommand.h | 2 +- chimeraslayercommand.cpp | 51 ++++++----------------------------- chimeraslayercommand.h | 2 +- getseqscommand.cpp | 38 +++++++++----------------- mgclustercommand.cpp | 42 ++++++++++++++++++++++------- mothur.h | 2 +- nameassignment.cpp | 1 + readblast.cpp | 8 +++--- removeseqscommand.cpp | 40 ++++++++++----------------- 13 files changed, 91 insertions(+), 201 deletions(-) diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index d7f60e7..2a38438 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -164,7 +164,6 @@ int ChimeraBellerophonCommand::execute(){ string outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "bellerophon.chimeras"; string accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "bellerophon.accnos"; - bool hasAccnos = true; chimera->getChimeras(); @@ -206,13 +205,10 @@ int ChimeraBellerophonCommand::execute(){ if (m->control_pressed) { remove(accnosFileName.c_str()); remove(outputFileName.c_str()); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete chimera; return 0; } - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } - m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine(); outputNames.push_back(outputFileName); - if (hasAccnos) { outputNames.push_back(accnosFileName); } + outputNames.push_back(accnosFileName); delete chimera; } diff --git a/chimeraccodecommand.cpp b/chimeraccodecommand.cpp index 2b46f2b..3d3c9ae 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -211,7 +211,6 @@ int ChimeraCcodeCommand::execute(){ } string mapInfo = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "mapinfo"; - bool hasAccnos = true; if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } @@ -220,8 +219,7 @@ int ChimeraCcodeCommand::execute(){ int pid, end, numSeqsPerProcessor; int tag = 2001; vector MPIPos; - MPIWroteAccnos = false; - + MPI_Status status; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are MPI_Comm_size(MPI_COMM_WORLD, &processors); @@ -278,11 +276,6 @@ int ChimeraCcodeCommand::execute(){ if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } - for (int i = 1; i < processors; i++) { - bool tempResult; - MPI_Recv(&tempResult, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status); - if (tempResult != 0) { MPIWroteAccnos = true; } - } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); MPIPos.resize(numSeqs+1); @@ -298,8 +291,6 @@ int ChimeraCcodeCommand::execute(){ driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } - - MPI_Send(&MPIWroteAccnos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); } //close files @@ -308,14 +299,6 @@ int ChimeraCcodeCommand::execute(){ MPI_File_close(&outMPIAccnos); MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case - - //delete accnos file if blank - if (pid == 0) { - if (!MPIWroteAccnos) { - hasAccnos = false; - remove(accnosFileName.c_str()); - } - } #else ofstream outHeader; @@ -348,9 +331,6 @@ int ChimeraCcodeCommand::execute(){ return 0; } - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } - }else{ vector positions; processIDS.resize(0); @@ -383,6 +363,7 @@ int ChimeraCcodeCommand::execute(){ createProcesses(outputFileName, fastaFileNames[s], accnosFileName); rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str()); + rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str()); //append output files for(int i=1;i nonBlankAccnosFiles; - //delete blank accnos files generated with multiple processes - for(int i=0;icontrol_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); @@ -438,8 +407,6 @@ int ChimeraCcodeCommand::execute(){ return 0; } - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } #endif appendFiles(outputFileName, tempHeader); @@ -452,7 +419,7 @@ int ChimeraCcodeCommand::execute(){ outputNames.push_back(outputFileName); outputNames.push_back(mapInfo); - if (hasAccnos) { outputNames.push_back(accnosFileName); } + outputNames.push_back(accnosFileName); for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); @@ -565,7 +532,6 @@ int ChimeraCcodeCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File //print results bool isChimeric = chimera->print(outMPI, outAccMPI); - if (isChimeric) { MPIWroteAccnos = true; } } } delete candidateSeq; diff --git a/chimeraccodecommand.h b/chimeraccodecommand.h index a07178e..c3d71c9 100644 --- a/chimeraccodecommand.h +++ b/chimeraccodecommand.h @@ -42,7 +42,7 @@ private: int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, vector&); #endif - bool abort, filter, MPIWroteAccnos; + bool abort, filter; string fastafile, templatefile, outputDir, maskfile; int processors, window, numwanted, numSeqs, templateSeqsLength; Chimera* chimera; diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index 4cfc3bc..6cf581b 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -253,7 +253,6 @@ int ChimeraPintailCommand::execute(){ outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "pintail.chimeras"; accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "pintail.accnos"; } - bool hasAccnos = true; if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } @@ -268,7 +267,6 @@ int ChimeraPintailCommand::execute(){ int pid, end, numSeqsPerProcessor; int tag = 2001; vector MPIPos; - MPIWroteAccnos = false; MPI_Status status; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are @@ -316,11 +314,6 @@ int ChimeraPintailCommand::execute(){ if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } - for (int i = 1; i < processors; i++) { - bool tempResult; - MPI_Recv(&tempResult, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status); - if (tempResult != 0) { MPIWroteAccnos = true; } - } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); MPIPos.resize(numSeqs+1); @@ -335,8 +328,6 @@ int ChimeraPintailCommand::execute(){ driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } - - MPI_Send(&MPIWroteAccnos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); } //close files @@ -344,15 +335,6 @@ int ChimeraPintailCommand::execute(){ MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case - - //delete accnos file if blank - if (pid == 0) { - if (!MPIWroteAccnos) { - hasAccnos = false; - remove(accnosFileName.c_str()); - } - } - #else //break up file @@ -376,9 +358,6 @@ int ChimeraPintailCommand::execute(){ return 0; } - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } - }else{ vector positions; processIDS.resize(0); @@ -410,6 +389,7 @@ int ChimeraPintailCommand::execute(){ createProcesses(outputFileName, fastaFileNames[s], accnosFileName); rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str()); + rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str()); //append output files for(int i=1;i nonBlankAccnosFiles; - //delete blank accnos files generated with multiple processes - for(int i=0;icontrol_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); @@ -462,9 +430,6 @@ int ChimeraPintailCommand::execute(){ delete chimera; return 0; } - - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } #endif #endif @@ -473,7 +438,7 @@ int ChimeraPintailCommand::execute(){ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); outputNames.push_back(outputFileName); - if (hasAccnos) { outputNames.push_back(accnosFileName); } + outputNames.push_back(accnosFileName); m->mothurOutEndLine(); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); @@ -584,7 +549,6 @@ int ChimeraPintailCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_Fi //print results bool isChimeric = chimera->print(outMPI, outAccMPI); - if (isChimeric) { MPIWroteAccnos = true; } } } delete candidateSeq; diff --git a/chimerapintailcommand.h b/chimerapintailcommand.h index b0dcceb..65e67fe 100644 --- a/chimerapintailcommand.h +++ b/chimerapintailcommand.h @@ -43,7 +43,7 @@ private: int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, vector&); #endif - bool abort, filter, MPIWroteAccnos; + bool abort, filter; string fastafile, templatefile, consfile, quanfile, maskfile, outputDir, inputDir; int processors, window, increment, numSeqs, templateSeqsLength; Chimera* chimera; diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index 35b0433..ae98ff3 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -177,7 +177,7 @@ void ChimeraSlayerCommand::help(){ m->mothurOut("This command was modeled after the chimeraSlayer written by the Broad Institute.\n"); m->mothurOut("The chimera.slayer command parameters are fasta, template, processors, ksize, window, match, mismatch, divergence. minsim, mincov, minbs, minsnp, parents, search, iters, increment and numwanted.\n"); //realign, m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n"); - m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); + m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n"); m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n"); m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); #ifdef USE_MPI @@ -230,7 +230,6 @@ int ChimeraSlayerCommand::execute(){ string outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "slayer.chimeras"; string accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "slayer.accnos"; - bool hasAccnos = true; if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } @@ -245,7 +244,6 @@ int ChimeraSlayerCommand::execute(){ int pid, end, numSeqsPerProcessor; int tag = 2001; vector MPIPos; - MPIWroteAccnos = false; MPI_Status status; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are @@ -306,11 +304,6 @@ int ChimeraSlayerCommand::execute(){ if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } remove(outputFileName.c_str()); remove(accnosFileName.c_str()); delete chimera; return 0; } - for (int i = 1; i < processors; i++) { - bool tempResult; - MPI_Recv(&tempResult, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status); - if (tempResult != 0) { MPIWroteAccnos = true; } - } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); MPIPos.resize(numSeqs+1); @@ -325,8 +318,6 @@ int ChimeraSlayerCommand::execute(){ driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } delete chimera; return 0; } - - MPI_Send(&MPIWroteAccnos, 1, MPI_INT, 0, tag, MPI_COMM_WORLD); } //close files @@ -335,14 +326,6 @@ int ChimeraSlayerCommand::execute(){ MPI_File_close(&outMPIAccnos); MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case - //delete accnos file if blank - if (pid == 0) { - if (!MPIWroteAccnos) { - hasAccnos = false; - remove(accnosFileName.c_str()); - } - } - #else ofstream outHeader; string tempHeader = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "slayer.chimeras.tempHeader"; @@ -373,9 +356,6 @@ int ChimeraSlayerCommand::execute(){ return 0; } - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } - }else{ vector positions; processIDS.resize(0); @@ -407,6 +387,7 @@ int ChimeraSlayerCommand::execute(){ createProcesses(outputFileName, fastaFileNames[s], accnosFileName); rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str()); + rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str()); //append output files for(int i=1;i nonBlankAccnosFiles; - //delete blank accnos files generated with multiple processes - for(int i=0;icontrol_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); @@ -462,8 +431,6 @@ int ChimeraSlayerCommand::execute(){ return 0; } - //delete accnos file if its blank - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } #endif appendFiles(outputFileName, tempHeader); @@ -478,10 +445,10 @@ int ChimeraSlayerCommand::execute(){ for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); outputNames.push_back(outputFileName); - if (hasAccnos) { outputNames.push_back(accnosFileName); } + outputNames.push_back(accnosFileName); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); - } + } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -589,8 +556,6 @@ int ChimeraSlayerCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_Fil //cout << "about to print" << endl; //print results bool isChimeric = chimera->print(outMPI, outAccMPI); - if (isChimeric) { MPIWroteAccnos = true; } - } } delete candidateSeq; diff --git a/chimeraslayercommand.h b/chimeraslayercommand.h index 7ae956a..7c20fb9 100644 --- a/chimeraslayercommand.h +++ b/chimeraslayercommand.h @@ -42,7 +42,7 @@ private: int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, vector&); #endif - bool abort, realign, MPIWroteAccnos; + bool abort, realign; string fastafile, templatefile, outputDir, search; int processors, window, iters, increment, numwanted, ksize, match, mismatch, parents, minSimilarity, minCoverage, minBS, minSNP, numSeqs, templateSeqsLength; float divR; diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 8bf93ce..5e77a1d 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -238,10 +238,8 @@ int GetSeqsCommand::readFasta(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; @@ -311,10 +309,8 @@ int GetSeqsCommand::readList(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; @@ -405,10 +401,8 @@ int GetSeqsCommand::readName(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; @@ -454,10 +448,8 @@ int GetSeqsCommand::readGroup(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; @@ -500,11 +492,9 @@ int GetSeqsCommand::readTax(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } - + if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); + return 0; } @@ -569,10 +559,8 @@ int GetSeqsCommand::readAlign(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index f8f3c78..182e78d 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -166,6 +166,13 @@ int MGClusterCommand::execute(){ list = new ListVector(nameMap->getListVector()); RAbundVector* rabund = new RAbundVector(list->getRAbundVector()); +for (int i = 0; i < list->getNumBins(); i++) { +string bin = list->get(i); +if(bin == "") { +cout << "bin " << i << " is blank."<< endl; +} +} +cout << "after outputting blank bins." << endl; if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; return 0; } @@ -208,7 +215,7 @@ int MGClusterCommand::execute(){ 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; } - + int count = 0; //cluster using cluster classes while (distMatrix->getSmallDist() < cutoff && distMatrix->getNNodes() > 0){ @@ -227,11 +234,12 @@ int MGClusterCommand::execute(){ }else{ rndDist = roundDist(dist, precision); } - +cout << "here " << count << '\t' << dist << endl; if(previousDist <= 0.0000 && dist != previousDist){ oldList.setLabel("unique"); printData(&oldList); + Seq2Bin = cluster->getSeqtoBin(); } else if(rndDist != rndPreviousDist){ if (merge) { @@ -252,9 +260,9 @@ int MGClusterCommand::execute(){ printData(&oldList); } } - + //cout << "after merge " << count << '\t' << dist << endl; + count++; previousDist = dist; - cout << "prev distance = " << previousDist << " dist = " << dist << endl; rndPreviousDist = rndDist; oldList = *list; oldSeq2Bin = Seq2Bin; @@ -263,6 +271,7 @@ int MGClusterCommand::execute(){ if(previousDist <= 0.0000){ oldList.setLabel("unique"); printData(&oldList); + Seq2Bin = cluster->getSeqtoBin(); } else if(rndPreviousDistgetSeqtoBin(); } else if((rndDist != rndPreviousDist)){ if (merge) { @@ -415,8 +425,8 @@ int MGClusterCommand::execute(){ } delete hcluster; - //remove(distFile.c_str()); - //remove(overlapFile.c_str()); + remove(distFile.c_str()); + remove(overlapFile.c_str()); } delete list; @@ -475,6 +485,17 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ try { //create new listvector so you don't overwrite the clustering ListVector* newList = new ListVector(oldList); +for (int i = 0; i < newList->getNumBins(); i++) { +string bin = newList->get(i); +if(bin == "") { +cout << "bin " << i << " is blank."<< endl; +for (map::iterator itBin = binInfo.begin(); itBin != binInfo.end(); itBin++) { + if (itBin->second == i) { cout << itBin->first << " maps to an empty bin." << endl; } +} +} +} +cout << "after outputting blank bins." << endl; + bool done = false; ifstream inOverlap; int count = 0; @@ -525,16 +546,17 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ if(itBin1 == binInfo.end()){ cerr << "AAError: Sequence '" << name1 << "' does not have any bin info.\n"; exit(1); } if(itBin2 == binInfo.end()){ cerr << "ABError: Sequence '" << name2 << "' does not have any bin info.\n"; exit(1); } - +cout << overlapNode.dist << '\t' << dist << endl; int binKeep = itBin1->second; int binRemove = itBin2->second; - + //if not merge bins and update binInfo if(binKeep != binRemove) { - + cout << "bin keep = " << binKeep << " bin remove = " << binRemove << endl; //save names in old bin string names = newList->get(binRemove); - + cout << names << endl << endl << endl; + cout << newList->get(binKeep) << endl << endl << endl; //merge bins into name1s bin newList->set(binKeep, newList->get(binRemove)+','+newList->get(binKeep)); newList->set(binRemove, ""); diff --git a/mothur.h b/mothur.h index a7946fd..c3f61b4 100644 --- a/mothur.h +++ b/mothur.h @@ -577,7 +577,7 @@ inline int openInputFile(string fileName, ifstream& fileHandle){ else { //check for blank file gobble(fileHandle); - if (fileHandle.eof()) { cout << completeFileName << " is blank. Please correct." << endl; return 1; } + if (fileHandle.eof()) { cout << completeFileName << " is blank. Please correct." << endl; } return 0; } diff --git a/nameassignment.cpp b/nameassignment.cpp index 641be4e..0a62a03 100644 --- a/nameassignment.cpp +++ b/nameassignment.cpp @@ -76,6 +76,7 @@ void NameAssignment::print(ostream& out){ //cout << (*this).size() << endl; for(it = (*this).begin(); it!=(*this).end(); it++){ out << it->first << '\t' << it->second << endl; //prints out keys and values of the map this. + //out << it->first << '\t' << it->first << endl; } } catch(exception& e) { diff --git a/readblast.cpp b/readblast.cpp index 4833d01..c3dfd48 100644 --- a/readblast.cpp +++ b/readblast.cpp @@ -177,8 +177,7 @@ int ReadBlast::read(NameAssignment* nameMap) { //if we have it then compare if (itDist != dists[it->first].end()) { - if (distance < 0.0) { cout << currentRow << '\t' << nameMap->get(it->first) << '\t' << "score = " << it->second << " refscore = " << refScore << " distance = " << distance << " distance = " << itDist->second << endl; } - + //if you want the minimum blast score ratio, then pick max distance if(minWanted) { distance = max(itDist->second, distance); } else{ distance = min(itDist->second, distance); } @@ -314,8 +313,8 @@ int ReadBlast::readNames(NameAssignment* nameMap) { ifstream in; openInputFile(blastfile, in); - ofstream outName; - openOutputFile("tempOutNames", outName); + //ofstream outName; + //openOutputFile((blastfile + ".tempOutNames"), outName); //read first line in >> prevName; @@ -351,6 +350,7 @@ int 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(); diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 5816cfd..afd9dd4 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -236,10 +236,8 @@ int RemoveSeqsCommand::readFasta(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; @@ -307,11 +305,9 @@ int RemoveSeqsCommand::readList(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } - + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); + return 0; } @@ -395,11 +391,9 @@ int RemoveSeqsCommand::readName(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } - + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); + return 0; } catch(exception& e) { @@ -439,10 +433,8 @@ int RemoveSeqsCommand::readGroup(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; } @@ -482,10 +474,8 @@ int RemoveSeqsCommand::readTax(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; } @@ -548,10 +538,8 @@ int RemoveSeqsCommand::readAlign(){ in.close(); out.close(); - if (wroteSomething == false) { - m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); - remove(outputFileName.c_str()); - }else { outputNames.push_back(outputFileName); } + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } + outputNames.push_back(outputFileName); return 0; -- 2.39.2