X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chimeraseqscommand.cpp;h=1758cf682fad21efcd0201b0b50b0ada7857d100;hb=818dcf9513122fa52616a7722f4893f77685a621;hp=2ec6ea9c85e2d8034aafa6527fd53b6bf28a052d;hpb=81276c241b984898f8d30ad123c00592ee6db7b8;p=mothur.git diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp index 2ec6ea9..1758cf6 100644 --- a/chimeraseqscommand.cpp +++ b/chimeraseqscommand.cpp @@ -311,36 +311,37 @@ int ChimeraSeqsCommand::execute(){ chimera->setIters(iters); chimera->setTemplateFile(templatefile); + string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".chimeras"; + string accnosFileName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".accnos"; + - - vector templateSeqs; if ((method != "bellerophon") && (method != "chimeracheck")) { - templateSeqs = chimera->readSeqs(templatefile); if (chimera->getUnaligned()) { - mothurOut("Your sequences need to be aligned when you use the chimeraslayer method."); mothurOutEndLine(); - //free memory - for (int i = 0; i < templateSeqs.size(); i++) { delete templateSeqs[i]; } + mothurOut("Your template sequences are different lengths, please correct."); mothurOutEndLine(); + delete chimera; return 0; } - - //set options - chimera->setTemplateSeqs(templateSeqs); - }else if (method == "bellerophon") {//run bellerophon separately since you need to read entire fastafile to run it chimera->getChimeras(); - string outputFName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".chimeras"; ofstream out; - openOutputFile(outputFName, out); + openOutputFile(outputFileName, out); + + ofstream out2; + openOutputFile(accnosFileName, out2); - chimera->print(out); + chimera->print(out, out2); out.close(); + out2.close(); + return 0; } //some methods need to do prep work before processing the chimeras chimera->doPrep(); + templateSeqsLength = chimera->getLength(); + ofstream outHeader; string tempHeader = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".chimeras.tempHeader"; openOutputFile(tempHeader, outHeader); @@ -348,7 +349,6 @@ int ChimeraSeqsCommand::execute(){ chimera->printHeader(outHeader); outHeader.close(); - string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".chimeras"; //break up file #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -360,7 +360,7 @@ int ChimeraSeqsCommand::execute(){ lines.push_back(new linePair(0, numSeqs)); - driver(lines[0], outputFileName, fastafile); + driver(lines[0], outputFileName, fastafile, accnosFileName); }else{ vector positions; @@ -391,14 +391,19 @@ int ChimeraSeqsCommand::execute(){ } - createProcesses(outputFileName, fastafile); - + createProcesses(outputFileName, fastafile, accnosFileName); + rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str()); - + rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str()); + //append alignment and report files for(int i=1;igetName() != "") { //incase there is a commented sequence at the end of a file - - //find chimeras - chimera->getChimeras(candidateSeq); + + if ((candidateSeq->getAligned().length() != templateSeqsLength) && (method != "chimeracheck")) { //chimeracheck does not require seqs to be aligned + mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); mothurOutEndLine(); + }else{ + //find chimeras + chimera->getChimeras(candidateSeq); - //print results - chimera->print(out); + //print results + chimera->print(out, out2); + } } delete candidateSeq; @@ -467,6 +480,7 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena if((line->numSeqs) % 100 != 0){ mothurOut("Processing sequence: " + toString(line->numSeqs)); mothurOutEndLine(); } out.close(); + out2.close(); inFASTA.close(); return 1; @@ -479,7 +493,7 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena /**************************************************************************************************/ -void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename) { +void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, string accnos) { try { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) int process = 0; @@ -493,7 +507,7 @@ void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename) 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], outputFileName + toString(getpid()) + ".temp", filename); + driver(lines[process], outputFileName + toString(getpid()) + ".temp", filename, accnos + toString(getpid()) + ".temp"); exit(0); }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); } } @@ -520,7 +534,7 @@ void ChimeraSeqsCommand::appendOutputFiles(string temp, string filename) { ifstream input; openOutputFileAppend(temp, output); - openInputFile(filename, input); + openInputFile(filename, input, "noerror"); while(char c = input.get()){ if(input.eof()) { break; }