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); parameters.push_back(ptemplate);
17 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,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); 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 algorythms 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 ChimeraCcodeCommand::ChimeraCcodeCommand(){
69 abort = true; calledHelp = true;
71 vector<string> tempOutNames;
72 outputTypes["chimera"] = tempOutNames;
73 outputTypes["mapinfo"] = tempOutNames;
74 outputTypes["accnos"] = tempOutNames;
77 m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand");
81 //***************************************************************************************************************
82 ChimeraCcodeCommand::ChimeraCcodeCommand(string option) {
84 abort = false; calledHelp = false;
85 ReferenceDB* rdb = ReferenceDB::getInstance();
87 //allow user to run help
88 if(option == "help") { help(); abort = true; calledHelp = true; }
89 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
92 vector<string> myArray = setParameters();
94 OptionParser parser(option);
95 map<string,string> parameters = parser.getParameters();
97 ValidParameters validParameter("chimera.ccode");
98 map<string,string>::iterator it;
100 //check to make sure all parameters are valid for command
101 for (it = parameters.begin(); it != parameters.end(); it++) {
102 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
105 vector<string> tempOutNames;
106 outputTypes["chimera"] = tempOutNames;
107 outputTypes["mapinfo"] = tempOutNames;
108 outputTypes["accnos"] = tempOutNames;
110 //if the user changes the input directory command factory will send this info to us in the output parameter
111 string inputDir = validParameter.validFile(parameters, "inputdir", false);
112 if (inputDir == "not found"){ inputDir = ""; }
115 it = parameters.find("reference");
116 //user has given a template file
117 if(it != parameters.end()){
118 path = m->hasPath(it->second);
119 //if the user has not given a path then, add inputdir. else leave path alone.
120 if (path == "") { parameters["reference"] = inputDir + it->second; }
124 //check for required parameters
125 fastafile = validParameter.validFile(parameters, "fasta", false);
126 if (fastafile == "not found") { //if there is a current fasta file, use it
127 string filename = m->getFastaFile();
128 if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
129 else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
131 m->splitAtDash(fastafile, fastaFileNames);
133 //go through files and make sure they are good, if not, then disregard them
134 for (int i = 0; i < fastaFileNames.size(); i++) {
137 if (fastaFileNames[i] == "current") {
138 fastaFileNames[i] = m->getFastaFile();
139 if (fastaFileNames[i] != "") { m->mothurOut("Using " + fastaFileNames[i] + " as input file for the fasta parameter where you had given current."); m->mothurOutEndLine(); }
141 m->mothurOut("You have no current fastafile, ignoring current."); m->mothurOutEndLine(); ignore=true;
142 //erase from file list
143 fastaFileNames.erase(fastaFileNames.begin()+i);
150 if (inputDir != "") {
151 string path = m->hasPath(fastaFileNames[i]);
152 //if the user has not given a path then, add inputdir. else leave path alone.
153 if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; }
159 ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror");
161 //if you can't open it, try default location
162 if (ableToOpen == 1) {
163 if (m->getDefaultPath() != "") { //default path is set
164 string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]);
165 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
167 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
169 fastaFileNames[i] = tryPath;
173 //if you can't open it, try default location
174 if (ableToOpen == 1) {
175 if (m->getOutputDir() != "") { //default path is set
176 string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]);
177 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
179 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
181 fastaFileNames[i] = tryPath;
187 if (ableToOpen == 1) {
188 m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
189 //erase from file list
190 fastaFileNames.erase(fastaFileNames.begin()+i);
193 m->setFastaFile(fastaFileNames[i]);
198 //make sure there is at least one valid file left
199 if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
202 //if the user changes the output directory command factory will send this info to us in the output parameter
203 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
205 maskfile = validParameter.validFile(parameters, "mask", false);
206 if (maskfile == "not found") { maskfile = ""; }
207 else if (maskfile != "default") {
208 if (inputDir != "") {
209 string path = m->hasPath(maskfile);
210 //if the user has not given a path then, add inputdir. else leave path alone.
211 if (path == "") { maskfile = inputDir + maskfile; }
215 int ableToOpen = m->openInputFile(maskfile, in);
216 if (ableToOpen == 1) { abort = true; }
221 temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; }
222 filter = m->isTrue(temp);
224 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
225 m->setProcessors(temp);
226 m->mothurConvert(temp, processors);
228 temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; }
229 m->mothurConvert(temp, window);
231 temp = validParameter.validFile(parameters, "numwanted", false); if (temp == "not found") { temp = "20"; }
232 m->mothurConvert(temp, numwanted);
234 temp = validParameter.validFile(parameters, "save", false); if (temp == "not found"){ temp = "f"; }
235 save = m->isTrue(temp);
237 if (save) { //clear out old references
241 //this has to go after save so that if the user sets save=t and provides no reference we abort
242 templatefile = validParameter.validFile(parameters, "reference", true);
243 if (templatefile == "not found") {
244 //check for saved reference sequences
245 if (rdb->referenceSeqs.size() != 0) {
246 templatefile = "saved";
248 m->mothurOut("[ERROR]: You don't have any saved reference sequences and the reference parameter is a required.");
249 m->mothurOutEndLine();
252 }else if (templatefile == "not open") { abort = true; }
253 else { if (save) { rdb->setSavedReference(templatefile); } }
258 catch(exception& e) {
259 m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand");
263 //***************************************************************************************************************
264 int ChimeraCcodeCommand::execute(){
267 if (abort == true) { if (calledHelp) { return 0; } return 2; }
269 for (int s = 0; s < fastaFileNames.size(); s++) {
271 m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
273 int start = time(NULL);
276 if (maskfile == "default") { m->mothurOut("I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); m->mothurOutEndLine(); }
278 chimera = new Ccode(fastaFileNames[s], templatefile, filter, maskfile, window, numwanted, outputDir);
280 //is your template aligned?
281 if (chimera->getUnaligned()) { m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine(); delete chimera; return 0; }
282 templateSeqsLength = chimera->getLength();
284 if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it
285 string outputFileName, accnosFileName;
286 if (maskfile != "") {
287 outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.chimeras";
288 accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.accnos";
290 outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ccode.chimeras";
291 accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ccode.accnos";
294 string mapInfo = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "mapinfo";
296 if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); return 0; }
300 int pid, numSeqsPerProcessor;
302 vector<unsigned long long> MPIPos;
305 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
306 MPI_Comm_size(MPI_COMM_WORLD, &processors);
310 MPI_File outMPIAccnos;
312 int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
313 int inMode=MPI_MODE_RDONLY;
315 char outFilename[1024];
316 strcpy(outFilename, outputFileName.c_str());
318 char outAccnosFilename[1024];
319 strcpy(outAccnosFilename, accnosFileName.c_str());
321 char inFileName[1024];
322 strcpy(inFileName, fastaFileNames[s].c_str());
324 MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
325 MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
326 MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos);
328 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; }
330 if (pid == 0) { //you are the root process
331 string outTemp = "For full window mapping info refer to " + mapInfo + "\n";
334 int length = outTemp.length();
335 char* buf2 = new char[length];
336 memcpy(buf2, outTemp.c_str(), length);
338 MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status);
341 MPIPos = m->setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs
343 //send file positions to all processes
344 for(int i = 1; i < processors; i++) {
345 MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
346 MPI_Send(&MPIPos[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
349 //figure out how many sequences you have to align
350 numSeqsPerProcessor = numSeqs / processors;
351 int startIndex = pid * numSeqsPerProcessor;
352 if(pid == (processors - 1)){ numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor; }
356 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
358 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; }
360 }else{ //you are a child process
361 MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
362 MPIPos.resize(numSeqs+1);
363 MPI_Recv(&MPIPos[0], (numSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
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); for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); delete chimera; return 0; }
378 MPI_File_close(&inMPI);
379 MPI_File_close(&outMPI);
380 MPI_File_close(&outMPIAccnos);
382 MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
386 string tempHeader = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + "ccode.chimeras.tempHeader";
387 m->openOutputFile(tempHeader, outHeader);
389 outHeader << "For full window mapping info refer to " << mapInfo << endl << endl;
396 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
397 vector<unsigned long long> positions = m->divideFile(fastaFileNames[s], processors);
399 for (int i = 0; i < (positions.size()-1); i++) {
400 lines.push_back(new linePair(positions[i], positions[(i+1)]));
405 numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
407 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; }
410 processIDS.resize(0);
412 numSeqs = createProcesses(outputFileName, fastaFileNames[s], accnosFileName);
414 rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str());
415 rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str());
417 //append output files
418 for(int i=1;i<processors;i++){
419 m->appendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName);
420 m->mothurRemove((outputFileName + toString(processIDS[i]) + ".temp"));
423 //append output files
424 for(int i=1;i<processors;i++){
425 m->appendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName);
426 m->mothurRemove((accnosFileName + toString(processIDS[i]) + ".temp"));
429 if (m->control_pressed) {
430 m->mothurRemove(outputFileName);
431 m->mothurRemove(accnosFileName);
432 for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear();
433 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
441 lines.push_back(new linePair(0, 1000));
442 numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
444 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; }
448 m->appendFiles(outputFileName, tempHeader);
450 m->mothurRemove(outputFileName);
451 rename(tempHeader.c_str(), outputFileName.c_str());
456 outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName);
457 outputNames.push_back(mapInfo); outputTypes["mapinfo"].push_back(mapInfo);
458 outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName);
460 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
462 m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
466 //set accnos file as new current accnosfile
468 itTypes = outputTypes.find("accnos");
469 if (itTypes != outputTypes.end()) {
470 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); }
473 m->mothurOutEndLine();
474 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
475 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
476 m->mothurOutEndLine();
481 catch(exception& e) {
482 m->errorOut(e, "ChimeraCcodeCommand", "execute");
486 //**********************************************************************************************************************
488 int ChimeraCcodeCommand::driver(linePair* filePos, string outputFName, string filename, string accnos){
491 m->openOutputFile(outputFName, out);
494 m->openOutputFile(accnos, out2);
497 m->openInputFile(filename, inFASTA);
499 inFASTA.seekg(filePos->start);
506 if (m->control_pressed) { return 1; }
508 Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA);
510 if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
512 if (candidateSeq->getAligned().length() != templateSeqsLength) {
513 m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
516 chimera->getChimeras(candidateSeq);
518 if (m->control_pressed) { delete candidateSeq; return 1; }
521 chimera->print(out, out2);
527 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
528 unsigned long long pos = inFASTA.tellg();
529 if ((pos == -1) || (pos >= filePos->end)) { break; }
531 if (inFASTA.eof()) { break; }
535 if((count) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); }
538 if((count) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); }
546 catch(exception& e) {
547 m->errorOut(e, "ChimeraCcodeCommand", "driver");
551 //**********************************************************************************************************************
553 int ChimeraCcodeCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& outMPI, MPI_File& outAccMPI, vector<unsigned long long>& MPIPos){
558 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
560 for(int i=0;i<num;i++){
562 if (m->control_pressed) { return 0; }
565 int length = MPIPos[start+i+1] - MPIPos[start+i];
567 char* buf4 = new char[length];
569 MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
571 string tempBuf = buf4;
572 if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
573 istringstream iss (tempBuf,istringstream::in);
576 Sequence* candidateSeq = new Sequence(iss); m->gobble(iss);
578 if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
580 if (candidateSeq->getAligned().length() != templateSeqsLength) {
581 m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
584 chimera->getChimeras(candidateSeq);
586 if (m->control_pressed) { delete candidateSeq; return 1; }
589 chimera->print(outMPI, outAccMPI);
595 if((i+1) % 100 == 0){ cout << "Processing sequence: " << (i+1) << endl; m->mothurOutJustToLog("Processing sequence: " + toString(i+1) + "\n"); }
598 if(num % 100 != 0){ cout << "Processing sequence: " << num << endl; m->mothurOutJustToLog("Processing sequence: " + toString(num) + "\n"); }
603 catch(exception& e) {
604 m->errorOut(e, "ChimeraCcodeCommand", "driverMPI");
610 /**************************************************************************************************/
612 int ChimeraCcodeCommand::createProcesses(string outputFileName, string filename, string accnos) {
614 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
618 //loop through and create all the processes you want
619 while (process != processors) {
623 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
626 num = driver(lines[process], outputFileName + toString(getpid()) + ".temp", filename, accnos + toString(getpid()) + ".temp");
628 //pass numSeqs to parent
630 string tempFile = outputFileName + toString(getpid()) + ".num.temp";
631 m->openOutputFile(tempFile, out);
637 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
638 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
643 //force parent to wait until all the processes are done
644 for (int i=0;i<processors;i++) {
645 int temp = processIDS[i];
649 for (int i = 0; i < processIDS.size(); i++) {
651 string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp";
652 m->openInputFile(tempFile, in);
653 if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
654 in.close(); m->mothurRemove(tempFile);
660 catch(exception& e) {
661 m->errorOut(e, "ChimeraCcodeCommand", "createProcesses");
665 //**********************************************************************************************************************