2 * chimeraccodecommand.cpp
5 * Created by westcott on 3/30/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "chimeraccodecommand.h"
12 #include "referencedb.h"
13 //**********************************************************************************************************************
14 vector<string> ChimeraCcodeCommand::setParameters(){
16 CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate);
17 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-mapinfo-accnos",false,true,true); parameters.push_back(pfasta);
18 CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pfilter);
19 CommandParameter pwindow("window", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pwindow);
20 CommandParameter pnumwanted("numwanted", "Number", "", "20", "", "", "","",false,false); parameters.push_back(pnumwanted);
21 CommandParameter pmask("mask", "String", "", "", "", "", "","",false,false); parameters.push_back(pmask);
22 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
23 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
24 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
25 CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave);
27 vector<string> myArray;
28 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
32 m->errorOut(e, "ChimeraCcodeCommand", "setParameters");
36 //**********************************************************************************************************************
37 string ChimeraCcodeCommand::getHelpString(){
39 string helpString = "";
40 helpString += "The chimera.ccode command reads a fastafile and referencefile and outputs potentially chimeric sequences.\n";
41 helpString += "This command was created using the algorithms described in the 'Evaluating putative chimeric sequences from PCR-amplified products' paper by Juan M. Gonzalez, Johannes Zimmerman and Cesareo Saiz-Jimenez.\n";
42 helpString += "The chimera.ccode command parameters are fasta, reference, filter, mask, processors, window and numwanted.\n";
43 helpString += "The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required unless you have a valid current fasta file. \n";
44 helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n";
45 helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. \n";
46 helpString += "The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n";
47 helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n";
49 helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n";
51 helpString += "The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences. \n";
52 helpString += "The window parameter allows you to specify the window size for searching for chimeras. \n";
53 helpString += "The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n";
54 helpString += "If the save parameter is set to true the reference sequences will be saved in memory, to clear them later you can use the clear.memory command. Default=f.";
55 helpString += "The chimera.ccode command should be in the following format: \n";
56 helpString += "chimera.ccode(fasta=yourFastaFile, reference=yourTemplate) \n";
57 helpString += "Example: chimera.ccode(fasta=AD.align, reference=core_set_aligned.imputed.fasta) \n";
58 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n";
62 m->errorOut(e, "ChimeraCcodeCommand", "getHelpString");
66 //**********************************************************************************************************************
67 string ChimeraCcodeCommand::getOutputPattern(string type) {
71 if (type == "chimera") { pattern = "[filename],[tag],ccode.chimeras-[filename],ccode.chimeras"; }
72 else if (type == "accnos") { pattern = "[filename],[tag],ccode.accnos-[filename],ccode.accnos"; }
73 else if (type == "mapinfo") { pattern = "[filename],mapinfo"; }
74 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
79 m->errorOut(e, "ChimeraCcodeCommand", "getOutputPattern");
83 //**********************************************************************************************************************
84 ChimeraCcodeCommand::ChimeraCcodeCommand(){
86 abort = true; calledHelp = true;
88 vector<string> tempOutNames;
89 outputTypes["chimera"] = tempOutNames;
90 outputTypes["mapinfo"] = tempOutNames;
91 outputTypes["accnos"] = tempOutNames;
95 m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand");
99 //***************************************************************************************************************
100 ChimeraCcodeCommand::ChimeraCcodeCommand(string option) {
102 abort = false; calledHelp = false;
103 ReferenceDB* rdb = ReferenceDB::getInstance();
105 //allow user to run help
106 if(option == "help") { help(); abort = true; calledHelp = true; }
107 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
110 vector<string> myArray = setParameters();
112 OptionParser parser(option);
113 map<string,string> parameters = parser.getParameters();
115 ValidParameters validParameter("chimera.ccode");
116 map<string,string>::iterator it;
118 //check to make sure all parameters are valid for command
119 for (it = parameters.begin(); it != parameters.end(); it++) {
120 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
123 vector<string> tempOutNames;
124 outputTypes["chimera"] = tempOutNames;
125 outputTypes["mapinfo"] = tempOutNames;
126 outputTypes["accnos"] = tempOutNames;
129 //if the user changes the input directory command factory will send this info to us in the output parameter
130 string inputDir = validParameter.validFile(parameters, "inputdir", false);
131 if (inputDir == "not found"){ inputDir = ""; }
134 it = parameters.find("reference");
135 //user has given a template file
136 if(it != parameters.end()){
137 path = m->hasPath(it->second);
138 //if the user has not given a path then, add inputdir. else leave path alone.
139 if (path == "") { parameters["reference"] = inputDir + it->second; }
143 //check for required parameters
144 fastafile = validParameter.validFile(parameters, "fasta", false);
145 if (fastafile == "not found") { //if there is a current fasta file, use it
146 string filename = m->getFastaFile();
147 if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
148 else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
150 m->splitAtDash(fastafile, fastaFileNames);
152 //go through files and make sure they are good, if not, then disregard them
153 for (int i = 0; i < fastaFileNames.size(); i++) {
156 if (fastaFileNames[i] == "current") {
157 fastaFileNames[i] = m->getFastaFile();
158 if (fastaFileNames[i] != "") { m->mothurOut("Using " + fastaFileNames[i] + " as input file for the fasta parameter where you had given current."); m->mothurOutEndLine(); }
160 m->mothurOut("You have no current fastafile, ignoring current."); m->mothurOutEndLine(); ignore=true;
161 //erase from file list
162 fastaFileNames.erase(fastaFileNames.begin()+i);
169 if (inputDir != "") {
170 string path = m->hasPath(fastaFileNames[i]);
171 //if the user has not given a path then, add inputdir. else leave path alone.
172 if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; }
178 ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror");
180 //if you can't open it, try default location
181 if (ableToOpen == 1) {
182 if (m->getDefaultPath() != "") { //default path is set
183 string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]);
184 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
186 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
188 fastaFileNames[i] = tryPath;
192 //if you can't open it, try default location
193 if (ableToOpen == 1) {
194 if (m->getOutputDir() != "") { //default path is set
195 string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]);
196 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
198 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
200 fastaFileNames[i] = tryPath;
206 if (ableToOpen == 1) {
207 m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
208 //erase from file list
209 fastaFileNames.erase(fastaFileNames.begin()+i);
212 m->setFastaFile(fastaFileNames[i]);
217 //make sure there is at least one valid file left
218 if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
221 //if the user changes the output directory command factory will send this info to us in the output parameter
222 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
224 maskfile = validParameter.validFile(parameters, "mask", false);
225 if (maskfile == "not found") { maskfile = ""; }
226 else if (maskfile != "default") {
227 if (inputDir != "") {
228 string path = m->hasPath(maskfile);
229 //if the user has not given a path then, add inputdir. else leave path alone.
230 if (path == "") { maskfile = inputDir + maskfile; }
234 int ableToOpen = m->openInputFile(maskfile, in);
235 if (ableToOpen == 1) { abort = true; }
240 temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; }
241 filter = m->isTrue(temp);
243 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
244 m->setProcessors(temp);
245 m->mothurConvert(temp, processors);
247 temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; }
248 m->mothurConvert(temp, window);
250 temp = validParameter.validFile(parameters, "numwanted", false); if (temp == "not found") { temp = "20"; }
251 m->mothurConvert(temp, numwanted);
253 temp = validParameter.validFile(parameters, "save", false); if (temp == "not found"){ temp = "f"; }
254 save = m->isTrue(temp);
256 if (save) { //clear out old references
260 //this has to go after save so that if the user sets save=t and provides no reference we abort
261 templatefile = validParameter.validFile(parameters, "reference", true);
262 if (templatefile == "not found") {
263 //check for saved reference sequences
264 if (rdb->referenceSeqs.size() != 0) {
265 templatefile = "saved";
267 m->mothurOut("[ERROR]: You don't have any saved reference sequences and the reference parameter is a required.");
268 m->mothurOutEndLine();
271 }else if (templatefile == "not open") { abort = true; }
272 else { if (save) { rdb->setSavedReference(templatefile); } }
277 catch(exception& e) {
278 m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand");
282 //***************************************************************************************************************
283 int ChimeraCcodeCommand::execute(){
286 if (abort == true) { if (calledHelp) { return 0; } return 2; }
288 for (int s = 0; s < fastaFileNames.size(); s++) {
290 m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
292 int start = time(NULL);
295 if (maskfile == "default") { m->mothurOut("I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); m->mothurOutEndLine(); }
297 chimera = new Ccode(fastaFileNames[s], templatefile, filter, maskfile, window, numwanted, outputDir);
299 //is your template aligned?
300 if (chimera->getUnaligned()) { m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine(); delete chimera; return 0; }
301 templateSeqsLength = chimera->getLength();
303 if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it
304 string outputFileName, accnosFileName;
305 map<string, string> variables;
306 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s]));
307 string mapInfo = getOutputFileName("mapinfo", variables);
308 if (maskfile != "") { variables["[tag]"] = maskfile; }
309 outputFileName = getOutputFileName("chimera", variables);
310 accnosFileName = getOutputFileName("accnos", variables);
312 if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); return 0; }
316 int pid, numSeqsPerProcessor;
318 vector<unsigned long long> MPIPos;
321 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
322 MPI_Comm_size(MPI_COMM_WORLD, &processors);
326 MPI_File outMPIAccnos;
328 int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
329 int inMode=MPI_MODE_RDONLY;
331 char outFilename[1024];
332 strcpy(outFilename, outputFileName.c_str());
334 char outAccnosFilename[1024];
335 strcpy(outAccnosFilename, accnosFileName.c_str());
337 char inFileName[1024];
338 strcpy(inFileName, fastaFileNames[s].c_str());
340 MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
341 MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
342 MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos);
344 if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); delete chimera; return 0; }
346 if (pid == 0) { //you are the root process
347 string outTemp = "For full window mapping info refer to " + mapInfo + "\n";
350 int length = outTemp.length();
351 char* buf2 = new char[length];
352 memcpy(buf2, outTemp.c_str(), length);
354 MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status);
357 MPIPos = m->setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs
359 //send file positions to all processes
360 for(int i = 1; i < processors; i++) {
361 MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
362 MPI_Send(&MPIPos[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
365 //figure out how many sequences you have to align
366 numSeqsPerProcessor = numSeqs / processors;
367 int startIndex = pid * numSeqsPerProcessor;
368 if(pid == (processors - 1)){ numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor; }
372 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
374 if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); m->mothurRemove(outputFileName); m->mothurRemove(accnosFileName); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); delete chimera; return 0; }
376 }else{ //you are a child process
377 MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
378 MPIPos.resize(numSeqs+1);
379 MPI_Recv(&MPIPos[0], (numSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
381 //figure out how many sequences you have to align
382 numSeqsPerProcessor = numSeqs / processors;
383 int startIndex = pid * numSeqsPerProcessor;
384 if(pid == (processors - 1)){ numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor; }
388 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
390 if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPI); MPI_File_close(&outMPIAccnos); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); delete chimera; return 0; }
394 MPI_File_close(&inMPI);
395 MPI_File_close(&outMPI);
396 MPI_File_close(&outMPIAccnos);
398 MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
402 string tempHeader = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + "ccode.chimeras.tempHeader";
403 m->openOutputFile(tempHeader, outHeader);
405 outHeader << "For full window mapping info refer to " << mapInfo << endl << endl;
412 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
413 vector<unsigned long long> positions = m->divideFile(fastaFileNames[s], processors);
415 for (int i = 0; i < (positions.size()-1); i++) {
416 lines.push_back(new linePair(positions[i], positions[(i+1)]));
421 numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
423 if (m->control_pressed) { m->mothurRemove(outputFileName); m->mothurRemove(tempHeader); m->mothurRemove(accnosFileName); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } outputTypes.clear(); lines.clear(); delete chimera; return 0; }
426 processIDS.resize(0);
428 numSeqs = createProcesses(outputFileName, fastaFileNames[s], accnosFileName);
430 rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str());
431 rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str());
433 //append output files
434 for(int i=1;i<processors;i++){
435 m->appendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName);
436 m->mothurRemove((outputFileName + toString(processIDS[i]) + ".temp"));
439 //append output files
440 for(int i=1;i<processors;i++){
441 m->appendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName);
442 m->mothurRemove((accnosFileName + toString(processIDS[i]) + ".temp"));
445 if (m->control_pressed) {
446 m->mothurRemove(outputFileName);
447 m->mothurRemove(accnosFileName);
448 for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear();
449 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
457 lines.push_back(new linePair(0, 1000));
458 numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
460 if (m->control_pressed) { m->mothurRemove(outputFileName); m->mothurRemove(tempHeader); m->mothurRemove(accnosFileName); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } for (int i = 0; i < lines.size(); i++) { delete lines[i]; } outputTypes.clear(); lines.clear(); delete chimera; return 0; }
464 m->appendFiles(outputFileName, tempHeader);
466 m->mothurRemove(outputFileName);
467 rename(tempHeader.c_str(), outputFileName.c_str());
472 outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName);
473 outputNames.push_back(mapInfo); outputTypes["mapinfo"].push_back(mapInfo);
474 outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName);
476 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
478 m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
482 //set accnos file as new current accnosfile
484 itTypes = outputTypes.find("accnos");
485 if (itTypes != outputTypes.end()) {
486 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); }
489 m->mothurOutEndLine();
490 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
491 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
492 m->mothurOutEndLine();
497 catch(exception& e) {
498 m->errorOut(e, "ChimeraCcodeCommand", "execute");
502 //**********************************************************************************************************************
504 int ChimeraCcodeCommand::driver(linePair* filePos, string outputFName, string filename, string accnos){
507 m->openOutputFile(outputFName, out);
510 m->openOutputFile(accnos, out2);
513 m->openInputFile(filename, inFASTA);
515 inFASTA.seekg(filePos->start);
522 if (m->control_pressed) { return 1; }
524 Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA);
526 if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
528 if (candidateSeq->getAligned().length() != templateSeqsLength) {
529 m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
532 chimera->getChimeras(candidateSeq);
534 if (m->control_pressed) { delete candidateSeq; return 1; }
537 chimera->print(out, out2);
543 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
544 unsigned long long pos = inFASTA.tellg();
545 if ((pos == -1) || (pos >= filePos->end)) { break; }
547 if (inFASTA.eof()) { break; }
551 if((count) % 100 == 0){ m->mothurOutJustToScreen("Processing sequence: " + toString(count) + "\n"); }
554 if((count) % 100 != 0){ m->mothurOutJustToScreen("Processing sequence: " + toString(count) + "\n"); }
562 catch(exception& e) {
563 m->errorOut(e, "ChimeraCcodeCommand", "driver");
567 //**********************************************************************************************************************
569 int ChimeraCcodeCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& outMPI, MPI_File& outAccMPI, vector<unsigned long long>& MPIPos){
574 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
576 for(int i=0;i<num;i++){
578 if (m->control_pressed) { return 0; }
581 int length = MPIPos[start+i+1] - MPIPos[start+i];
583 char* buf4 = new char[length];
585 MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
587 string tempBuf = buf4;
588 if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
589 istringstream iss (tempBuf,istringstream::in);
592 Sequence* candidateSeq = new Sequence(iss); m->gobble(iss);
594 if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
596 if (candidateSeq->getAligned().length() != templateSeqsLength) {
597 m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
600 chimera->getChimeras(candidateSeq);
602 if (m->control_pressed) { delete candidateSeq; return 1; }
605 chimera->print(outMPI, outAccMPI);
611 if((i+1) % 100 == 0){ cout << "Processing sequence: " << (i+1) << endl; m->mothurOutJustToLog("Processing sequence: " + toString(i+1) + "\n"); }
614 if(num % 100 != 0){ cout << "Processing sequence: " << num << endl; m->mothurOutJustToLog("Processing sequence: " + toString(num) + "\n"); }
619 catch(exception& e) {
620 m->errorOut(e, "ChimeraCcodeCommand", "driverMPI");
626 /**************************************************************************************************/
628 int ChimeraCcodeCommand::createProcesses(string outputFileName, string filename, string accnos) {
630 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
634 //loop through and create all the processes you want
635 while (process != processors) {
639 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
642 num = driver(lines[process], outputFileName + toString(m->mothurGetpid(process)) + ".temp", filename, accnos + toString(m->mothurGetpid(process)) + ".temp");
644 //pass numSeqs to parent
646 string tempFile = outputFileName + toString(m->mothurGetpid(process)) + ".num.temp";
647 m->openOutputFile(tempFile, out);
653 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
654 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
659 //force parent to wait until all the processes are done
660 for (int i=0;i<processors;i++) {
661 int temp = processIDS[i];
665 for (int i = 0; i < processIDS.size(); i++) {
667 string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp";
668 m->openInputFile(tempFile, in);
669 if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
670 in.close(); m->mothurRemove(tempFile);
676 catch(exception& e) {
677 m->errorOut(e, "ChimeraCcodeCommand", "createProcesses");
681 //**********************************************************************************************************************