2 * chimeraslayercommand.cpp
5 * Created by westcott on 3/31/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "chimeraslayercommand.h"
11 #include "chimeraslayer.h"
13 //**********************************************************************************************************************
14 vector<string> ChimeraSlayerCommand::getValidParameters(){
16 string AlignArray[] = {"fasta", "processors", "window", "template","numwanted", "ksize", "match","mismatch",
17 "divergence", "minsim","mincov","minbs", "minsnp","parents", "iters","outputdir","inputdir", "search","realign" };
18 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
22 m->errorOut(e, "ChimeraSlayerCommand", "getValidParameters");
26 //**********************************************************************************************************************
27 ChimeraSlayerCommand::ChimeraSlayerCommand(){
29 vector<string> tempOutNames;
30 outputTypes["chimera"] = tempOutNames;
31 outputTypes["accnos"] = tempOutNames;
34 m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand");
38 //**********************************************************************************************************************
39 vector<string> ChimeraSlayerCommand::getRequiredParameters(){
41 string AlignArray[] = {"template","fasta"};
42 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
46 m->errorOut(e, "ChimeraSlayerCommand", "getRequiredParameters");
50 //**********************************************************************************************************************
51 vector<string> ChimeraSlayerCommand::getRequiredFiles(){
53 vector<string> myArray;
57 m->errorOut(e, "ChimeraSlayerCommand", "getRequiredFiles");
61 //***************************************************************************************************************
62 ChimeraSlayerCommand::ChimeraSlayerCommand(string option) {
66 //allow user to run help
67 if(option == "help") { help(); abort = true; }
70 //valid paramters for this command
71 string Array[] = {"fasta", "processors", "window", "template","numwanted", "ksize", "match","mismatch",
72 "divergence", "minsim","mincov","minbs", "minsnp","parents", "iters","outputdir","inputdir", "search","realign" };
73 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
75 OptionParser parser(option);
76 map<string,string> parameters = parser.getParameters();
78 ValidParameters validParameter("chimera.slayer");
79 map<string,string>::iterator it;
81 //check to make sure all parameters are valid for command
82 for (it = parameters.begin(); it != parameters.end(); it++) {
83 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
86 vector<string> tempOutNames;
87 outputTypes["chimera"] = tempOutNames;
88 outputTypes["accnos"] = tempOutNames;
90 //if the user changes the input directory command factory will send this info to us in the output parameter
91 string inputDir = validParameter.validFile(parameters, "inputdir", false);
92 if (inputDir == "not found"){ inputDir = ""; }
95 it = parameters.find("template");
96 //user has given a template file
97 if(it != parameters.end()){
98 path = m->hasPath(it->second);
99 //if the user has not given a path then, add inputdir. else leave path alone.
100 if (path == "") { parameters["template"] = inputDir + it->second; }
105 //check for required parameters
106 fastafile = validParameter.validFile(parameters, "fasta", false);
107 if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.slayer command."); m->mothurOutEndLine(); abort = true; }
109 m->splitAtDash(fastafile, fastaFileNames);
111 //go through files and make sure they are good, if not, then disregard them
112 for (int i = 0; i < fastaFileNames.size(); i++) {
113 if (inputDir != "") {
114 string path = m->hasPath(fastaFileNames[i]);
115 //if the user has not given a path then, add inputdir. else leave path alone.
116 if (path == "") { fastaFileNames[i] = inputDir + fastaFileNames[i]; }
122 ableToOpen = m->openInputFile(fastaFileNames[i], in, "noerror");
124 //if you can't open it, try default location
125 if (ableToOpen == 1) {
126 if (m->getDefaultPath() != "") { //default path is set
127 string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]);
128 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
130 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
132 fastaFileNames[i] = tryPath;
136 if (ableToOpen == 1) {
137 if (m->getOutputDir() != "") { //default path is set
138 string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]);
139 m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine();
141 ableToOpen = m->openInputFile(tryPath, in2, "noerror");
143 fastaFileNames[i] = tryPath;
149 if (ableToOpen == 1) {
150 m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
151 //erase from file list
152 fastaFileNames.erase(fastaFileNames.begin()+i);
157 //make sure there is at least one valid file left
158 if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
161 //if the user changes the output directory command factory will send this info to us in the output parameter
162 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
164 templatefile = validParameter.validFile(parameters, "template", true);
165 if (templatefile == "not open") { abort = true; }
166 else if (templatefile == "not found") { templatefile = ""; m->mothurOut("template is a required parameter for the chimera.slayer command."); m->mothurOutEndLine(); abort = true; }
168 string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; }
169 convert(temp, processors);
171 temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found") { temp = "7"; }
172 convert(temp, ksize);
174 temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "50"; }
175 convert(temp, window);
177 temp = validParameter.validFile(parameters, "match", false); if (temp == "not found") { temp = "5"; }
178 convert(temp, match);
180 temp = validParameter.validFile(parameters, "mismatch", false); if (temp == "not found") { temp = "-4"; }
181 convert(temp, mismatch);
183 temp = validParameter.validFile(parameters, "divergence", false); if (temp == "not found") { temp = "1.007"; }
186 temp = validParameter.validFile(parameters, "minsim", false); if (temp == "not found") { temp = "90"; }
187 convert(temp, minSimilarity);
189 temp = validParameter.validFile(parameters, "mincov", false); if (temp == "not found") { temp = "70"; }
190 convert(temp, minCoverage);
192 temp = validParameter.validFile(parameters, "minbs", false); if (temp == "not found") { temp = "90"; }
193 convert(temp, minBS);
195 temp = validParameter.validFile(parameters, "minsnp", false); if (temp == "not found") { temp = "100"; }
196 convert(temp, minSNP);
198 temp = validParameter.validFile(parameters, "parents", false); if (temp == "not found") { temp = "3"; }
199 convert(temp, parents);
201 temp = validParameter.validFile(parameters, "realign", false); if (temp == "not found") { temp = "f"; }
202 realign = m->isTrue(temp);
204 search = validParameter.validFile(parameters, "search", false); if (search == "not found") { search = "distance"; }
206 temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "100"; }
207 convert(temp, iters);
209 temp = validParameter.validFile(parameters, "increment", false); if (temp == "not found") { temp = "5"; }
210 convert(temp, increment);
212 temp = validParameter.validFile(parameters, "numwanted", false); if (temp == "not found") { temp = "15"; }
213 convert(temp, numwanted);
215 if ((search != "distance") && (search != "blast") && (search != "kmer")) { m->mothurOut(search + " is not a valid search."); m->mothurOutEndLine(); abort = true; }
218 catch(exception& e) {
219 m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand");
223 //**********************************************************************************************************************
225 void ChimeraSlayerCommand::help(){
228 m->mothurOut("The chimera.slayer command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n");
229 m->mothurOut("This command was modeled after the chimeraSlayer written by the Broad Institute.\n");
230 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,
231 m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n");
232 m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n");
233 m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n");
234 m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n");
236 m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n");
238 m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras, default=50. \n");
239 m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default=5.\n");
240 m->mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with, default=15.\n");
241 m->mothurOut("The ksize parameter allows you to input kmersize, default is 7, used if search is kmer. \n");
242 m->mothurOut("The match parameter allows you to reward matched bases in blast search, default is 5. \n");
243 m->mothurOut("The parents parameter allows you to select the number of potential parents to investigate from the numwanted best matches after rating them, default is 3. \n");
244 m->mothurOut("The mismatch parameter allows you to penalize mismatched bases in blast search, default is -4. \n");
245 m->mothurOut("The divergence parameter allows you to set a cutoff for chimera determination, default is 1.007. \n");
246 m->mothurOut("The iters parameter allows you to specify the number of bootstrap iters to do with the chimeraslayer method, default=100.\n");
247 m->mothurOut("The minsim parameter allows you to specify a minimum similarity with the parent fragments, default=90. \n");
248 m->mothurOut("The mincov parameter allows you to specify minimum coverage by closest matches found in template. Default is 70, meaning 70%. \n");
249 m->mothurOut("The minbs parameter allows you to specify minimum bootstrap support for calling a sequence chimeric. Default is 90, meaning 90%. \n");
250 m->mothurOut("The minsnp parameter allows you to specify percent of SNPs to sample on each side of breakpoint for computing bootstrap support (default: 100) \n");
251 m->mothurOut("The search parameter allows you to specify search method for finding the closest parent. Choices are distance, blast, and kmer, default distance. \n");
252 m->mothurOut("The realign parameter allows you to realign the query to the potential parents. Choices are true or false, default false. \n");
253 m->mothurOut("The chimera.slayer command should be in the following format: \n");
254 m->mothurOut("chimera.slayer(fasta=yourFastaFile, template=yourTemplate, search=yourSearch) \n");
255 m->mothurOut("Example: chimera.slayer(fasta=AD.align, template=core_set_aligned.imputed.fasta, search=kmer) \n");
256 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");
258 catch(exception& e) {
259 m->errorOut(e, "ChimeraSlayerCommand", "help");
264 //***************************************************************************************************************
266 ChimeraSlayerCommand::~ChimeraSlayerCommand(){ /* do nothing */ }
268 //***************************************************************************************************************
270 int ChimeraSlayerCommand::execute(){
273 if (abort == true) { return 0; }
275 for (int s = 0; s < fastaFileNames.size(); s++) {
277 m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
279 int start = time(NULL);
281 chimera = new ChimeraSlayer(fastaFileNames[s], templatefile, search, ksize, match, mismatch, window, divR, minSimilarity, minCoverage, minBS, minSNP, parents, iters, increment, numwanted, realign);
283 if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it
284 string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.chimeras";
285 string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.accnos";
287 if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; }
289 if (chimera->getUnaligned()) {
290 m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine();
294 templateSeqsLength = chimera->getLength();
297 int pid, end, numSeqsPerProcessor;
299 vector<unsigned long int> MPIPos;
302 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
303 MPI_Comm_size(MPI_COMM_WORLD, &processors);
307 MPI_File outMPIAccnos;
309 int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
310 int inMode=MPI_MODE_RDONLY;
312 char outFilename[1024];
313 strcpy(outFilename, outputFileName.c_str());
315 char outAccnosFilename[1024];
316 strcpy(outAccnosFilename, accnosFileName.c_str());
318 char inFileName[1024];
319 strcpy(inFileName, fastaFileNames[s].c_str());
321 MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
322 MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
323 MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos);
325 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; }
327 if (pid == 0) { //you are the root process
328 m->mothurOutEndLine();
329 m->mothurOut("Only reporting sequence supported by " + toString(minBS) + "% of bootstrapped results.");
330 m->mothurOutEndLine();
332 string outTemp = "Name\tLeftParent\tRightParent\tDivQLAQRB\tPerIDQLAQRB\tBootStrapA\tDivQLBQRA\tPerIDQLBQRA\tBootStrapB\tFlag\tLeftWindow\tRightWindow\n";
335 int length = outTemp.length();
336 char* buf2 = new char[length];
337 memcpy(buf2, outTemp.c_str(), length);
339 MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status);
342 MPIPos = m->setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs
344 //send file positions to all processes
345 for(int i = 1; i < processors; i++) {
346 MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
347 MPI_Send(&MPIPos[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
350 //figure out how many sequences you have to align
351 numSeqsPerProcessor = numSeqs / processors;
352 int startIndex = pid * numSeqsPerProcessor;
353 if(pid == (processors - 1)){ numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor; }
356 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
358 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()); } remove(outputFileName.c_str()); remove(accnosFileName.c_str()); 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; }
371 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
373 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; }
377 MPI_File_close(&inMPI);
378 MPI_File_close(&outMPI);
379 MPI_File_close(&outMPIAccnos);
380 MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
384 string tempHeader = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.chimeras.tempHeader";
385 m->openOutputFile(tempHeader, outHeader);
387 chimera->printHeader(outHeader);
390 vector<unsigned long int> positions = m->divideFile(fastaFileNames[s], processors);
392 for (int i = 0; i < (positions.size()-1); i++) {
393 lines.push_back(new linePair(positions[i], positions[(i+1)]));
397 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
399 numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
401 if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(tempHeader.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; }
404 processIDS.resize(0);
406 numSeqs = createProcesses(outputFileName, fastaFileNames[s], accnosFileName);
408 rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str());
409 rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str());
411 //append output files
412 for(int i=1;i<processors;i++){
413 m->appendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName);
414 remove((outputFileName + toString(processIDS[i]) + ".temp").c_str());
417 //append output files
418 for(int i=1;i<processors;i++){
419 m->appendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName);
420 remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str());
423 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; }
427 numSeqs = driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
429 if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); remove(tempHeader.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; }
433 m->appendFiles(outputFileName, tempHeader);
435 remove(outputFileName.c_str());
436 rename(tempHeader.c_str(), outputFileName.c_str());
442 for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear();
444 outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName);
445 outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName);
447 m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
450 m->mothurOutEndLine();
451 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
452 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
453 m->mothurOutEndLine();
458 catch(exception& e) {
459 m->errorOut(e, "ChimeraSlayerCommand", "execute");
463 //**********************************************************************************************************************
465 int ChimeraSlayerCommand::driver(linePair* filePos, string outputFName, string filename, string accnos){
468 m->openOutputFile(outputFName, out);
471 m->openOutputFile(accnos, out2);
474 m->openInputFile(filename, inFASTA);
476 inFASTA.seekg(filePos->start);
483 if (m->control_pressed) { return 1; }
485 Sequence* candidateSeq = new Sequence(inFASTA); m->gobble(inFASTA);
487 if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
489 if (candidateSeq->getAligned().length() != templateSeqsLength) {
490 m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
493 chimera->getChimeras(candidateSeq);
495 if (m->control_pressed) { delete candidateSeq; return 1; }
498 chimera->print(out, out2);
504 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
505 unsigned long int pos = inFASTA.tellg();
506 if ((pos == -1) || (pos >= filePos->end)) { break; }
508 if (inFASTA.eof()) { break; }
512 if((count) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); }
515 if((count) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); }
523 catch(exception& e) {
524 m->errorOut(e, "ChimeraSlayerCommand", "driver");
528 //**********************************************************************************************************************
530 int ChimeraSlayerCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& outMPI, MPI_File& outAccMPI, vector<unsigned long int>& MPIPos){
534 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
536 for(int i=0;i<num;i++){
538 if (m->control_pressed) { return 1; }
541 int length = MPIPos[start+i+1] - MPIPos[start+i];
543 char* buf4 = new char[length];
544 MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
546 string tempBuf = buf4;
547 if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
548 istringstream iss (tempBuf,istringstream::in);
552 Sequence* candidateSeq = new Sequence(iss); m->gobble(iss);
554 if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
556 if (candidateSeq->getAligned().length() != templateSeqsLength) {
557 m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
561 chimera->getChimeras(candidateSeq);
563 if (m->control_pressed) { delete candidateSeq; return 1; }
564 //cout << "about to print" << endl;
566 bool isChimeric = chimera->print(outMPI, outAccMPI);
572 if((i+1) % 100 == 0){ cout << "Processing sequence: " << (i+1) << endl; m->mothurOutJustToLog("Processing sequence: " + toString(i+1) + "\n"); }
575 if(num % 100 != 0){ cout << "Processing sequence: " << num << endl; m->mothurOutJustToLog("Processing sequence: " + toString(num) + "\n"); }
580 catch(exception& e) {
581 m->errorOut(e, "ChimeraSlayerCommand", "driverMPI");
587 /**************************************************************************************************/
589 int ChimeraSlayerCommand::createProcesses(string outputFileName, string filename, string accnos) {
591 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
595 //loop through and create all the processes you want
596 while (process != processors) {
600 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
603 num = driver(lines[process], outputFileName + toString(getpid()) + ".temp", filename, accnos + toString(getpid()) + ".temp");
605 //pass numSeqs to parent
607 string tempFile = outputFileName + toString(getpid()) + ".num.temp";
608 m->openOutputFile(tempFile, out);
614 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
615 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
620 //force parent to wait until all the processes are done
621 for (int i=0;i<processors;i++) {
622 int temp = processIDS[i];
626 for (int i = 0; i < processIDS.size(); i++) {
628 string tempFile = outputFileName + toString(processIDS[i]) + ".num.temp";
629 m->openInputFile(tempFile, in);
630 if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
631 in.close(); remove(tempFile.c_str());
637 catch(exception& e) {
638 m->errorOut(e, "ChimeraSlayerCommand", "createProcesses");
643 /**************************************************************************************************/