]> git.donarmstrong.com Git - mothur.git/blob - chimeraccodecommand.cpp
modified calculators to use doubles, added numotu and fontsize parameters to heatmap...
[mothur.git] / chimeraccodecommand.cpp
1 /*
2  *  chimeraccodecommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 3/30/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "chimeraccodecommand.h"
11 #include "ccode.h"
12
13 //***************************************************************************************************************
14
15 ChimeraCcodeCommand::ChimeraCcodeCommand(string option)  {
16         try {
17                 abort = false;
18                 
19                 //allow user to run help
20                 if(option == "help") { help(); abort = true; }
21                 
22                 else {
23                         //valid paramters for this command
24                         string Array[] =  {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir", };
25                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
26                         
27                         OptionParser parser(option);
28                         map<string,string> parameters = parser.getParameters();
29                         
30                         ValidParameters validParameter("chimera.ccode");
31                         map<string,string>::iterator it;
32                         
33                         //check to make sure all parameters are valid for command
34                         for (it = parameters.begin(); it != parameters.end(); it++) { 
35                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
36                         }
37                         
38                         //if the user changes the input directory command factory will send this info to us in the output parameter 
39                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
40                         if (inputDir == "not found"){   inputDir = "";          }
41                         else {
42                                 string path;
43                                 it = parameters.find("template");
44                                 //user has given a template file
45                                 if(it != parameters.end()){ 
46                                         path = hasPath(it->second);
47                                         //if the user has not given a path then, add inputdir. else leave path alone.
48                                         if (path == "") {       parameters["template"] = inputDir + it->second;         }
49                                 }
50                         }
51
52                         //check for required parameters
53                         fastafile = validParameter.validFile(parameters, "fasta", false);
54                         if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.ccode command."); m->mothurOutEndLine(); abort = true;  }
55                         else { 
56                                 splitAtDash(fastafile, fastaFileNames);
57                                 
58                                 //go through files and make sure they are good, if not, then disregard them
59                                 for (int i = 0; i < fastaFileNames.size(); i++) {
60                                         if (inputDir != "") {
61                                                 string path = hasPath(fastaFileNames[i]);
62                                                 //if the user has not given a path then, add inputdir. else leave path alone.
63                                                 if (path == "") {       fastaFileNames[i] = inputDir + fastaFileNames[i];               }
64                                         }
65         
66                                         int ableToOpen;
67                                         ifstream in;
68                                         
69                                         ableToOpen = openInputFile(fastaFileNames[i], in, "noerror");
70                                 
71                                         //if you can't open it, try default location
72                                         if (ableToOpen == 1) {
73                                                 if (m->getDefaultPath() != "") { //default path is set
74                                                         string tryPath = m->getDefaultPath() + getSimpleName(fastaFileNames[i]);
75                                                         m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
76                                                         ableToOpen = openInputFile(tryPath, in, "noerror");
77                                                         fastaFileNames[i] = tryPath;
78                                                 }
79                                         }
80                                         in.close();
81                                         
82                                         if (ableToOpen == 1) { 
83                                                 m->mothurOut("Unable to open " + fastaFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); 
84                                                 //erase from file list
85                                                 fastaFileNames.erase(fastaFileNames.begin()+i);
86                                                 i--;
87                                         }
88                                 }
89                                 
90                                 //make sure there is at least one valid file left
91                                 if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
92                         }
93                         
94                         //if the user changes the output directory command factory will send this info to us in the output parameter 
95                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
96                                 outputDir = ""; 
97                                 outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
98                         }
99
100                         templatefile = validParameter.validFile(parameters, "template", true);
101                         if (templatefile == "not open") { abort = true; }
102                         else if (templatefile == "not found") { templatefile = ""; m->mothurOut("template is a required parameter for the chimera.ccode command."); m->mothurOutEndLine(); abort = true;  }             
103                         
104                         maskfile = validParameter.validFile(parameters, "mask", false);
105                         if (maskfile == "not found") { maskfile = "";  }        
106                         else if (maskfile != "default")  { 
107                                 if (inputDir != "") {
108                                         string path = hasPath(maskfile);
109                                         //if the user has not given a path then, add inputdir. else leave path alone.
110                                         if (path == "") {       maskfile = inputDir + maskfile;         }
111                                 }
112
113                                 ifstream in;
114                                 int     ableToOpen = openInputFile(maskfile, in);
115                                 if (ableToOpen == 1) { abort = true; }
116                                 in.close();
117                         }
118                         
119                         string temp;
120                         temp = validParameter.validFile(parameters, "filter", false);                   if (temp == "not found") { temp = "F"; }
121                         filter = isTrue(temp);
122                         
123                         temp = validParameter.validFile(parameters, "processors", false);               if (temp == "not found") { temp = "1"; }
124                         convert(temp, processors);
125                         
126                         temp = validParameter.validFile(parameters, "window", false);                   if (temp == "not found") { temp = "0"; }
127                         convert(temp, window);
128                         
129                         temp = validParameter.validFile(parameters, "numwanted", false);                if (temp == "not found") { temp = "20"; }
130                         convert(temp, numwanted);
131
132                 }
133         }
134         catch(exception& e) {
135                 m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand");
136                 exit(1);
137         }
138 }
139 //**********************************************************************************************************************
140
141 void ChimeraCcodeCommand::help(){
142         try {
143         
144                 m->mothurOut("The chimera.ccode command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n");
145                 m->mothurOut("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");
146                 m->mothurOut("The chimera.ccode command parameters are fasta, template, filter, mask, processors, window and numwanted.\n");
147                 m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n");
148                 m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n");
149                 m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n");
150                 m->mothurOut("The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n");
151                 m->mothurOut("The processors parameter allows you to specify how many processors you would like to use.  The default is 1. \n");
152                 #ifdef USE_MPI
153                 m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n");
154                 #endif
155                 m->mothurOut("The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences. \n");
156                 m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras. \n");
157                 m->mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n");
158                 m->mothurOut("The chimera.ccode command should be in the following format: \n");
159                 m->mothurOut("chimera.ccode(fasta=yourFastaFile, template=yourTemplate) \n");
160                 m->mothurOut("Example: chimera.ccode(fasta=AD.align, template=core_set_aligned.imputed.fasta) \n");
161                 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");     
162         }
163         catch(exception& e) {
164                 m->errorOut(e, "ChimeraCcodeCommand", "help");
165                 exit(1);
166         }
167 }
168
169 //***************************************************************************************************************
170
171 ChimeraCcodeCommand::~ChimeraCcodeCommand(){    /*      do nothing      */      }
172
173 //***************************************************************************************************************
174
175 int ChimeraCcodeCommand::execute(){
176         try{
177                 
178                 if (abort == true) { return 0; }
179                 
180                 for (int s = 0; s < fastaFileNames.size(); s++) {
181                                 
182                         m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
183                 
184                         int start = time(NULL); 
185                         
186                         //set user options
187                         if (maskfile == "default") { m->mothurOut("I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); m->mothurOutEndLine();  }
188
189                         chimera = new Ccode(fastaFileNames[s], templatefile, filter, maskfile, window, numwanted, outputDir);   
190                         
191                         //is your template aligned?
192                         if (chimera->getUnaligned()) { m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine(); delete chimera; return 0; }
193                         templateSeqsLength = chimera->getLength();
194                         
195                         string outputFileName, accnosFileName;
196                         if (maskfile != "") {
197                                 outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.chimeras";
198                                 accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.accnos";
199                         }else {
200                                 outputFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s]))  + "ccode.chimeras";
201                                 accnosFileName = outputDir + getRootName(getSimpleName(fastaFileNames[s]))  + "ccode.accnos";
202                         }
203
204                         string mapInfo = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "mapinfo";
205                         
206                         if (m->control_pressed) { delete chimera;  for (int j = 0; j < outputNames.size(); j++) {       remove(outputNames[j].c_str()); }  return 0;    }
207                         
208                 #ifdef USE_MPI
209                 
210                                 int pid, end, numSeqsPerProcessor; 
211                                 int tag = 2001;
212                                 vector<unsigned long int> MPIPos;
213                                                                 
214                                 MPI_Status status; 
215                                 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
216                                 MPI_Comm_size(MPI_COMM_WORLD, &processors); 
217
218                                 MPI_File inMPI;
219                                 MPI_File outMPI;
220                                 MPI_File outMPIAccnos;
221                                 
222                                 int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; 
223                                 int inMode=MPI_MODE_RDONLY; 
224                                 
225                                 char outFilename[1024];
226                                 strcpy(outFilename, outputFileName.c_str());
227                                 
228                                 char outAccnosFilename[1024];
229                                 strcpy(outAccnosFilename, accnosFileName.c_str());
230                                 
231                                 char inFileName[1024];
232                                 strcpy(inFileName, fastaFileNames[s].c_str());
233
234                                 MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
235                                 MPI_File_open(MPI_COMM_WORLD, outFilename, outMode, MPI_INFO_NULL, &outMPI);
236                                 MPI_File_open(MPI_COMM_WORLD, outAccnosFilename, outMode, MPI_INFO_NULL, &outMPIAccnos);
237
238                                 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;  }
239                         
240                                 if (pid == 0) { //you are the root process 
241                                         string outTemp = "For full window mapping info refer to " + mapInfo + "\n\n";
242                                         
243                                         //print header
244                                         int length = outTemp.length();
245                                         char* buf2 = new char[length];
246                                         memcpy(buf2, outTemp.c_str(), length);
247
248                                         MPI_File_write_shared(outMPI, buf2, length, MPI_CHAR, &status);
249                                         delete buf2;
250
251                                         MPIPos = setFilePosFasta(fastaFileNames[s], numSeqs); //fills MPIPos, returns numSeqs
252                                         
253                                         //send file positions to all processes
254                                         for(int i = 1; i < processors; i++) { 
255                                                 MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
256                                                 MPI_Send(&MPIPos[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
257                                         }
258                                         
259                                         //figure out how many sequences you have to align
260                                         numSeqsPerProcessor = numSeqs / processors;
261                                         int startIndex =  pid * numSeqsPerProcessor;
262                                         if(pid == (processors - 1)){    numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor;      }
263                                         
264                                 
265                                         //align your part
266                                         driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
267                                         
268                                         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;  }
269
270                                 }else{ //you are a child process
271                                         MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
272                                         MPIPos.resize(numSeqs+1);
273                                         MPI_Recv(&MPIPos[0], (numSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
274                                         
275                                         //figure out how many sequences you have to align
276                                         numSeqsPerProcessor = numSeqs / processors;
277                                         int startIndex =  pid * numSeqsPerProcessor;
278                                         if(pid == (processors - 1)){    numSeqsPerProcessor = numSeqs - pid * numSeqsPerProcessor;      }
279                                         
280                                         
281                                         //align your part
282                                         driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPI, outMPIAccnos, MPIPos);
283                                         
284                                         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;  }
285                                 }
286                                 
287                                 //close files 
288                                 MPI_File_close(&inMPI);
289                                 MPI_File_close(&outMPI);
290                                 MPI_File_close(&outMPIAccnos);
291                                 
292                                 MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
293                                         
294                 #else
295                         ofstream outHeader;
296                         string tempHeader = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + maskfile + "ccode.chimeras.tempHeader";
297                         openOutputFile(tempHeader, outHeader);
298                         
299                         outHeader << "For full window mapping info refer to " << mapInfo << endl << endl;
300
301                         outHeader.close();
302                         
303                         //break up file
304                         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
305                                 if(processors == 1){
306                                         ifstream inFASTA;
307                                         openInputFile(fastaFileNames[s], inFASTA);
308                                         getNumSeqs(inFASTA, numSeqs);
309                                         inFASTA.close();
310                                         
311                                         lines.push_back(new linePair(0, numSeqs));
312                                         
313                                         driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
314                                         
315                                         if (m->control_pressed) { 
316                                                 remove(outputFileName.c_str()); 
317                                                 remove(tempHeader.c_str()); 
318                                                 remove(accnosFileName.c_str());
319                                                 for (int j = 0; j < outputNames.size(); j++) {  remove(outputNames[j].c_str()); } 
320                                                 for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
321                                                 delete chimera;
322                                                 return 0;
323                                         }
324                                         
325                                 }else{
326                                         vector<unsigned long int> positions;
327                                         processIDS.resize(0);
328                                         
329                                         ifstream inFASTA;
330                                         openInputFile(fastaFileNames[s], inFASTA);
331                                         
332                                         string input;
333                                         while(!inFASTA.eof()){
334                                                 input = getline(inFASTA);
335                                                 if (input.length() != 0) {
336                                                         if(input[0] == '>'){    unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
337                                                 }
338                                         }
339                                         inFASTA.close();
340                                         
341                                         numSeqs = positions.size();
342                                         
343                                         int numSeqsPerProcessor = numSeqs / processors;
344                                         
345                                         for (int i = 0; i < processors; i++) {
346                                                 unsigned long int startPos = positions[ i * numSeqsPerProcessor ];
347                                                 if(i == processors - 1){
348                                                         numSeqsPerProcessor = numSeqs - i * numSeqsPerProcessor;
349                                                 }
350                                                 lines.push_back(new linePair(startPos, numSeqsPerProcessor));
351                                         }
352                                         
353                                         
354                                         createProcesses(outputFileName, fastaFileNames[s], accnosFileName); 
355                                 
356                                         rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str());
357                                         rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str());
358                                                 
359                                         //append output files
360                                         for(int i=1;i<processors;i++){
361                                                 appendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName);
362                                                 remove((outputFileName + toString(processIDS[i]) + ".temp").c_str());
363                                         }
364                                         
365                                         //append output files
366                                         for(int i=1;i<processors;i++){
367                                                 appendFiles((accnosFileName + toString(processIDS[i]) + ".temp"), accnosFileName);
368                                                 remove((accnosFileName + toString(processIDS[i]) + ".temp").c_str());
369                                         }
370                                         
371                                         if (m->control_pressed) { 
372                                                 remove(outputFileName.c_str()); 
373                                                 remove(accnosFileName.c_str());
374                                                 for (int j = 0; j < outputNames.size(); j++) {  remove(outputNames[j].c_str()); } 
375                                                 for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
376                                                 delete chimera;
377                                                 return 0;
378                                         }
379
380                                 }
381
382                         #else
383                                 ifstream inFASTA;
384                                 openInputFile(fastaFileNames[s], inFASTA);
385                                 getNumSeqs(inFASTA, numSeqs);
386                                 inFASTA.close();
387                                 lines.push_back(new linePair(0, numSeqs));
388                                 
389                                 driver(lines[0], outputFileName, fastaFileNames[s], accnosFileName);
390                                 
391                                 if (m->control_pressed) { 
392                                                 remove(outputFileName.c_str()); 
393                                                 remove(tempHeader.c_str()); 
394                                                 remove(accnosFileName.c_str());
395                                                 for (int j = 0; j < outputNames.size(); j++) {  remove(outputNames[j].c_str()); } 
396                                                 for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
397                                                 delete chimera;
398                                                 return 0;
399                                 }
400                                 
401                         #endif
402         
403                         appendFiles(outputFileName, tempHeader);
404                 
405                         remove(outputFileName.c_str());
406                         rename(tempHeader.c_str(), outputFileName.c_str());
407                 #endif
408                 
409                         delete chimera;
410                         
411                         outputNames.push_back(outputFileName);
412                         outputNames.push_back(mapInfo);
413                         outputNames.push_back(accnosFileName); 
414                         
415                         for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
416                         
417                         m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine();
418                 }
419                 
420                 m->mothurOutEndLine();
421                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
422                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }       
423                 m->mothurOutEndLine();
424                 
425                 return 0;
426                 
427         }
428         catch(exception& e) {
429                 m->errorOut(e, "ChimeraCcodeCommand", "execute");
430                 exit(1);
431         }
432 }
433 //**********************************************************************************************************************
434
435 int ChimeraCcodeCommand::driver(linePair* line, string outputFName, string filename, string accnos){
436         try {
437                 ofstream out;
438                 openOutputFile(outputFName, out);
439                 
440                 ofstream out2;
441                 openOutputFile(accnos, out2);
442                 
443                 ifstream inFASTA;
444                 openInputFile(filename, inFASTA);
445
446                 inFASTA.seekg(line->start);
447                 
448                 for(int i=0;i<line->numSeqs;i++){
449                 
450                         if (m->control_pressed) {       return 1;       }
451                 
452                         Sequence* candidateSeq = new Sequence(inFASTA);  gobble(inFASTA);
453                                 
454                         if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
455                                 
456                                 if (candidateSeq->getAligned().length() != templateSeqsLength) {  
457                                         m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
458                                 }else{
459                                         //find chimeras
460                                         chimera->getChimeras(candidateSeq);
461                                         
462                                         if (m->control_pressed) {       delete candidateSeq; return 1;  }
463                 
464                                         //print results
465                                         chimera->print(out, out2);
466                                 }
467                         }
468                         delete candidateSeq;
469                         
470                         //report progress
471                         if((i+1) % 100 == 0){   m->mothurOut("Processing sequence: " + toString(i+1)); m->mothurOutEndLine();           }
472                 }
473                 //report progress
474                 if((line->numSeqs) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(line->numSeqs)); m->mothurOutEndLine();         }
475                 
476                 out.close();
477                 out2.close();
478                 inFASTA.close();
479                                 
480                 return 0;
481         }
482         catch(exception& e) {
483                 m->errorOut(e, "ChimeraCcodeCommand", "driver");
484                 exit(1);
485         }
486 }
487 //**********************************************************************************************************************
488 #ifdef USE_MPI
489 int ChimeraCcodeCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& outMPI, MPI_File& outAccMPI, vector<unsigned long int>& MPIPos){
490         try {
491                                 
492                 MPI_Status status; 
493                 int pid;
494                 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
495                 
496                 for(int i=0;i<num;i++){
497                 
498                         if (m->control_pressed) { return 0; }
499                         
500                         //read next sequence
501                         int length = MPIPos[start+i+1] - MPIPos[start+i];
502         
503                         char* buf4 = new char[length];
504                                 
505                         MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
506                         
507                         string tempBuf = buf4;
508                         if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length);  }
509                         istringstream iss (tempBuf,istringstream::in);
510                         delete buf4;
511
512                         Sequence* candidateSeq = new Sequence(iss);  gobble(iss);
513                                 
514                         if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file
515                                 
516                                 if (candidateSeq->getAligned().length() != templateSeqsLength) {  
517                                         m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine();
518                                 }else{
519                                         //find chimeras
520                                         chimera->getChimeras(candidateSeq);
521                                         
522                                         if (m->control_pressed) {       delete candidateSeq; return 1;  }
523                 
524                                         //print results
525                                         bool isChimeric = chimera->print(outMPI, outAccMPI);
526                                 }
527                         }
528                         delete candidateSeq;
529                         
530                         //report progress
531                         if((i+1) % 100 == 0){  cout << "Processing sequence: " << (i+1) << endl;        m->mothurOutJustToLog("Processing sequence: " + toString(i+1) + "\n");          }
532                 }
533                 //report progress
534                 if(num % 100 != 0){             cout << "Processing sequence: " << num << endl; m->mothurOutJustToLog("Processing sequence: " + toString(num) + "\n");  }
535                 
536                                 
537                 return 0;
538         }
539         catch(exception& e) {
540                 m->errorOut(e, "ChimeraCcodeCommand", "driverMPI");
541                 exit(1);
542         }
543 }
544 #endif
545
546 /**************************************************************************************************/
547
548 int ChimeraCcodeCommand::createProcesses(string outputFileName, string filename, string accnos) {
549         try {
550 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
551                 int process = 0;
552                 //              processIDS.resize(0);
553                 
554                 //loop through and create all the processes you want
555                 while (process != processors) {
556                         int pid = fork();
557                         
558                         if (pid > 0) {
559                                 processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
560                                 process++;
561                         }else if (pid == 0){
562                                 driver(lines[process], outputFileName + toString(getpid()) + ".temp", filename, accnos + toString(getpid()) + ".temp");
563                                 exit(0);
564                         }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
565                 }
566                 
567                 //force parent to wait until all the processes are done
568                 for (int i=0;i<processors;i++) { 
569                         int temp = processIDS[i];
570                         wait(&temp);
571                 }
572                 
573                 return 0;
574 #endif          
575         }
576         catch(exception& e) {
577                 m->errorOut(e, "ChimeraCcodeCommand", "createProcesses");
578                 exit(1);
579         }
580 }
581 //**********************************************************************************************************************
582