X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chimerapintailcommand.cpp;h=c5e579e730e1cfbd3da0040359393ef08b497295;hb=37eac2026d91179acda0494c4dcca22f176551b9;hp=a8a85eb07bd8df6639ee7a3db7122d588c889e34;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;p=mothur.git diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index a8a85eb..c5e579e 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -10,8 +10,54 @@ #include "chimerapintailcommand.h" #include "pintail.h" +//********************************************************************************************************************** +vector ChimeraPintailCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","filter","processors","window" ,"increment","template","conservation","quantile","mask","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ChimeraPintailCommand::ChimeraPintailCommand(){ + try { + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "ChimeraPintailCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraPintailCommand::getRequiredParameters(){ + try { + string AlignArray[] = {"template","fasta"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChimeraPintailCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** - ChimeraPintailCommand::ChimeraPintailCommand(string option) { try { abort = false; @@ -35,6 +81,10 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -90,10 +140,24 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (m->getDefaultPath() != "") { //default path is set string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = m->openInputFile(tryPath, in, "noerror"); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + fastaFileNames[i] = tryPath; + } + } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); fastaFileNames[i] = tryPath; } } + in.close(); if (ableToOpen == 1) { @@ -131,17 +195,40 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { } ifstream in; - int ableToOpen = m->openInputFile(maskfile, in); - if (ableToOpen == 1) { abort = true; } + int ableToOpen = m->openInputFile(maskfile, in, "no error"); + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + m->getSimpleName(maskfile); + m->mothurOut("Unable to open " + maskfile + ". Trying default " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + maskfile = tryPath; + } + } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(maskfile); + m->mothurOut("Unable to open " + maskfile + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + maskfile = tryPath; + } + } + in.close(); + + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + maskfile + "."); m->mothurOutEndLine(); + abort = true; + } } //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it - } + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } templatefile = validParameter.validFile(parameters, "template", true); if (templatefile == "not open") { abort = true; } @@ -159,6 +246,15 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (GoodFile) { m->mothurOut("I found " + tempConsFile + " in your input file directory. I will use it to save time."); m->mothurOutEndLine(); consfile = tempConsFile; FileTest.close(); } + }else { + string tempConsFile = m->getDefaultPath() + m->getRootName(m->getSimpleName(templatefile)) + "freq"; + ifstream FileTest2(tempConsFile.c_str()); + if(FileTest2){ + bool GoodFile = m->checkReleaseVersion(FileTest2, m->getVersion()); + if (GoodFile) { + m->mothurOut("I found " + tempConsFile + " in your input file directory. I will use it to save time."); m->mothurOutEndLine(); consfile = tempConsFile; FileTest2.close(); + } + } } } @@ -242,14 +338,35 @@ int ChimeraPintailCommand::execute(){ if (GoodFile) { m->mothurOut("I found " + tempQuan + " in your input file directory. I will use it to save time."); m->mothurOutEndLine(); quanfile = tempQuan; FileTest.close(); } + }else { + string tryPath = m->getDefaultPath(); + string tempQuan = ""; + if ((!filter) && (maskfile == "")) { + tempQuan = tryPath + m->getRootName(m->getSimpleName(templatefile)) + "pintail.quan"; + }else if ((!filter) && (maskfile != "")) { + tempQuan = tryPath + m->getRootName(m->getSimpleName(templatefile)) + "pintail.masked.quan"; + }else if ((filter) && (maskfile != "")) { + tempQuan = tryPath + m->getRootName(m->getSimpleName(templatefile)) + "pintail.filtered." + m->getSimpleName(m->getRootName(fastaFileNames[s])) + "masked.quan"; + }else if ((filter) && (maskfile == "")) { + tempQuan = tryPath + m->getRootName(m->getSimpleName(templatefile)) + "pintail.filtered." + m->getSimpleName(m->getRootName(fastaFileNames[s])) + "quan"; + } + + ifstream FileTest2(tempQuan.c_str()); + if(FileTest2){ + bool GoodFile = m->checkReleaseVersion(FileTest2, m->getVersion()); + if (GoodFile) { + m->mothurOut("I found " + tempQuan + " in your input file directory. I will use it to save time."); m->mothurOutEndLine(); quanfile = tempQuan; FileTest2.close(); + } + } } chimera = new Pintail(fastaFileNames[s], templatefile, filter, processors, maskfile, consfile, quanfile, window, increment, outputDir); + if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it string outputFileName, accnosFileName; if (maskfile != "") { - outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".pintail.chimeras"; - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".pintail.accnos"; + outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + m->getSimpleName(m->getRootName(maskfile)) + ".pintail.chimeras"; + accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + m->getSimpleName(m->getRootName(maskfile)) + ".pintail.accnos"; }else { outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "pintail.chimeras"; accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "pintail.accnos"; @@ -265,7 +382,7 @@ int ChimeraPintailCommand::execute(){ templateSeqsLength = chimera->getLength(); #ifdef USE_MPI - int pid, end, numSeqsPerProcessor; + int pid, numSeqsPerProcessor; int tag = 2001; vector MPIPos; @@ -293,7 +410,7 @@ int ChimeraPintailCommand::execute(){ MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI); MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos); - 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; } + if (m->control_pressed) { outputTypes.clear(); 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; } if (pid == 0) { //you are the root process @@ -313,7 +430,7 @@ int ChimeraPintailCommand::execute(){ //do your part driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos); - 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; } + if (m->control_pressed) { outputTypes.clear(); 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; } }else{ //you are a child process MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); @@ -328,7 +445,7 @@ int ChimeraPintailCommand::execute(){ //do your part 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; } + if (m->control_pressed) { outputTypes.clear(); 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; } } //close files @@ -349,7 +466,7 @@ int ChimeraPintailCommand::execute(){ numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } }else{ processIDS.resize(0); @@ -374,7 +491,7 @@ int ChimeraPintailCommand::execute(){ if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); - for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } + for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } outputTypes.clear(); for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; @@ -384,7 +501,7 @@ int ChimeraPintailCommand::execute(){ #else numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName); - if (m->control_pressed) { remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(accnosFileName.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); delete chimera; return 0; } #endif #endif @@ -392,8 +509,8 @@ int ChimeraPintailCommand::execute(){ delete chimera; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - outputNames.push_back(outputFileName); - outputNames.push_back(accnosFileName); + outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); + outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); m->mothurOutEndLine(); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); @@ -453,8 +570,12 @@ int ChimeraPintailCommand::driver(linePair* filePos, string outputFName, string } delete candidateSeq; - unsigned long int pos = inFASTA.tellg(); - if ((pos == -1) || (pos >= filePos->end)) { break; } + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + unsigned long int pos = inFASTA.tellg(); + if ((pos == -1) || (pos >= filePos->end)) { break; } + #else + if (inFASTA.eof()) { break; } + #endif //report progress if((count) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); } @@ -510,7 +631,7 @@ int ChimeraPintailCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_Fi if (m->control_pressed) { delete candidateSeq; return 1; } //print results - bool isChimeric = chimera->print(outMPI, outAccMPI); + chimera->print(outMPI, outAccMPI); } } delete candidateSeq; @@ -557,7 +678,11 @@ int ChimeraPintailCommand::createProcesses(string outputFileName, string filenam out.close(); exit(0); - }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } } //force parent to wait until all the processes are done