]> git.donarmstrong.com Git - mothur.git/blob - screenseqscommand.cpp
added [ERROR] flag if command aborts
[mothur.git] / screenseqscommand.cpp
1 /*
2  *  screenseqscommand.cpp
3  *  Mothur
4  *
5  *  Created by Pat Schloss on 6/3/09.
6  *  Copyright 2009 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "screenseqscommand.h"
11 #include "sequence.hpp"
12
13 //**********************************************************************************************************************
14 vector<string> ScreenSeqsCommand::getValidParameters(){ 
15         try {
16                 string Array[] =  {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength",
17                                                                         "name", "group", "alignreport","processors","outputdir","inputdir"};
18                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
19                 return myArray;
20         }
21         catch(exception& e) {
22                 m->errorOut(e, "ScreenSeqsCommand", "getValidParameters");
23                 exit(1);
24         }
25 }
26 //**********************************************************************************************************************
27 ScreenSeqsCommand::ScreenSeqsCommand(){ 
28         try {
29                 abort = true; calledHelp = true; 
30                 vector<string> tempOutNames;
31                 outputTypes["fasta"] = tempOutNames;
32                 outputTypes["name"] = tempOutNames;
33                 outputTypes["group"] = tempOutNames;
34                 outputTypes["alignreport"] = tempOutNames;
35                 outputTypes["accnos"] = tempOutNames;
36         }
37         catch(exception& e) {
38                 m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand");
39                 exit(1);
40         }
41 }
42 //**********************************************************************************************************************
43 vector<string> ScreenSeqsCommand::getRequiredParameters(){      
44         try {
45                 string Array[] =  {"fasta"};
46                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
47                 return myArray;
48         }
49         catch(exception& e) {
50                 m->errorOut(e, "ScreenSeqsCommand", "getRequiredParameters");
51                 exit(1);
52         }
53 }
54 //**********************************************************************************************************************
55 vector<string> ScreenSeqsCommand::getRequiredFiles(){   
56         try {
57                 vector<string> myArray;
58                 return myArray;
59         }
60         catch(exception& e) {
61                 m->errorOut(e, "ScreenSeqsCommand", "getRequiredFiles");
62                 exit(1);
63         }
64 }
65 //***************************************************************************************************************
66
67 ScreenSeqsCommand::ScreenSeqsCommand(string option)  {
68         try {
69                 abort = false; calledHelp = false;   
70                 
71                 //allow user to run help
72                 if(option == "help") { help(); abort = true; calledHelp = true; }
73                 
74                 else {
75                         //valid paramters for this command
76                         string AlignArray[] =  {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength",
77                                                                         "name", "group", "alignreport","processors","outputdir","inputdir"};
78                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
79                         
80                         OptionParser parser(option);
81                         map<string,string> parameters = parser.getParameters();
82                         
83                         ValidParameters validParameter("screen.seqs");
84                         map<string,string>::iterator it;
85                         
86                         //check to make sure all parameters are valid for command
87                         for (it = parameters.begin(); it != parameters.end(); it++) { 
88                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
89                         }
90                         
91                         //initialize outputTypes
92                         vector<string> tempOutNames;
93                         outputTypes["fasta"] = tempOutNames;
94                         outputTypes["name"] = tempOutNames;
95                         outputTypes["group"] = tempOutNames;
96                         outputTypes["alignreport"] = tempOutNames;
97                         outputTypes["accnos"] = tempOutNames;
98                         
99                         //if the user changes the input directory command factory will send this info to us in the output parameter 
100                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
101                         if (inputDir == "not found"){   inputDir = "";          }
102                         else {
103                                 string path;
104                                 it = parameters.find("fasta");
105                                 //user has given a template file
106                                 if(it != parameters.end()){ 
107                                         path = m->hasPath(it->second);
108                                         //if the user has not given a path then, add inputdir. else leave path alone.
109                                         if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
110                                 }
111                                 
112                                 it = parameters.find("group");
113                                 //user has given a template file
114                                 if(it != parameters.end()){ 
115                                         path = m->hasPath(it->second);
116                                         //if the user has not given a path then, add inputdir. else leave path alone.
117                                         if (path == "") {       parameters["group"] = inputDir + it->second;            }
118                                 }
119                                 
120                                 it = parameters.find("name");
121                                 //user has given a template file
122                                 if(it != parameters.end()){ 
123                                         path = m->hasPath(it->second);
124                                         //if the user has not given a path then, add inputdir. else leave path alone.
125                                         if (path == "") {       parameters["name"] = inputDir + it->second;             }
126                                 }
127                                 
128                                 it = parameters.find("alignreport");
129                                 //user has given a template file
130                                 if(it != parameters.end()){ 
131                                         path = m->hasPath(it->second);
132                                         //if the user has not given a path then, add inputdir. else leave path alone.
133                                         if (path == "") {       parameters["alignreport"] = inputDir + it->second;              }
134                                 }
135                         }
136
137                         //check for required parameters
138                         fastafile = validParameter.validFile(parameters, "fasta", true);
139                         if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); m->mothurOutEndLine(); abort = true; }
140                         else if (fastafile == "not open") { abort = true; }     
141         
142                         groupfile = validParameter.validFile(parameters, "group", true);
143                         if (groupfile == "not open") { abort = true; }  
144                         else if (groupfile == "not found") { groupfile = ""; }
145                         
146                         namefile = validParameter.validFile(parameters, "name", true);
147                         if (namefile == "not open") { abort = true; }
148                         else if (namefile == "not found") { namefile = ""; }    
149
150                         alignreport = validParameter.validFile(parameters, "alignreport", true);
151                         if (alignreport == "not open") { abort = true; }
152                         else if (alignreport == "not found") { alignreport = ""; }      
153                         
154                         //if the user changes the output directory command factory will send this info to us in the output parameter 
155                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
156                                 outputDir = ""; 
157                                 outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it       
158                         }
159
160                         //check for optional parameter and set defaults
161                         // ...at some point should added some additional type checking...
162                         string temp;
163                         temp = validParameter.validFile(parameters, "start", false);            if (temp == "not found") { temp = "-1"; }
164                         convert(temp, startPos); 
165                 
166                         temp = validParameter.validFile(parameters, "end", false);                      if (temp == "not found") { temp = "-1"; }
167                         convert(temp, endPos);  
168
169                         temp = validParameter.validFile(parameters, "maxambig", false);         if (temp == "not found") { temp = "-1"; }
170                         convert(temp, maxAmbig);  
171
172                         temp = validParameter.validFile(parameters, "maxhomop", false);         if (temp == "not found") { temp = "-1"; }
173                         convert(temp, maxHomoP);  
174
175                         temp = validParameter.validFile(parameters, "minlength", false);        if (temp == "not found") { temp = "-1"; }
176                         convert(temp, minLength); 
177                         
178                         temp = validParameter.validFile(parameters, "maxlength", false);        if (temp == "not found") { temp = "-1"; }
179                         convert(temp, maxLength); 
180                         
181                         temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = "1";                             }
182                         convert(temp, processors); 
183                         
184                         temp = validParameter.validFile(parameters, "optimize", false); //optimizing trumps the optimized values original value
185                         if (temp == "not found"){       temp = "";              }
186                         else {  m->splitAtDash(temp, optimize);         }
187                         
188                         //check for invalid optimize options
189                         set<string> validOptimizers;
190                         validOptimizers.insert("start"); validOptimizers.insert("end"); validOptimizers.insert("maxambig"); validOptimizers.insert("maxhomop"); validOptimizers.insert("minlength"); validOptimizers.insert("maxlength");
191                         
192                         for (int i = 0; i < optimize.size(); i++) { 
193                                 if (validOptimizers.count(optimize[i]) == 0) { 
194                                         m->mothurOut(optimize[i] + " is not a valid optimizer. Valid options are start, end, maxambig, maxhomop, minlength and maxlength."); m->mothurOutEndLine();
195                                         optimize.erase(optimize.begin()+i);
196                                         i--;
197                                 }
198                         }
199                         
200                         temp = validParameter.validFile(parameters, "criteria", false); if (temp == "not found"){       temp = "90";                            }
201                         convert(temp, criteria); 
202                 }
203
204         }
205         catch(exception& e) {
206                 m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand");
207                 exit(1);
208         }
209 }
210 //**********************************************************************************************************************
211
212 void ScreenSeqsCommand::help(){
213         try {
214                 m->mothurOut("The screen.seqs command reads a fastafile and creates .....\n");
215                 m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group, optimize, criteria and processors.\n");
216                 m->mothurOut("The fasta parameter is required.\n");
217                 m->mothurOut("The start parameter .... The default is -1.\n");
218                 m->mothurOut("The end parameter .... The default is -1.\n");
219                 m->mothurOut("The maxambig parameter .... The default is -1.\n");
220                 m->mothurOut("The maxhomop parameter .... The default is -1.\n");
221                 m->mothurOut("The minlength parameter .... The default is -1.\n");
222                 m->mothurOut("The maxlength parameter .... The default is -1.\n");
223                 m->mothurOut("The processors parameter allows you to specify the number of processors to use while running the command. The default is 1.\n");
224                 m->mothurOut("The optimize and criteria parameters allow you set the start, end, maxabig, maxhomop, minlength and maxlength parameters relative to your set of sequences .\n");
225                 m->mothurOut("For example optimize=start-end, criteria=90, would set the start and end values to the position 90% of your sequences started and ended.\n");
226                 m->mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n");
227                 m->mothurOut("The screen.seqs command should be in the following format: \n");
228                 m->mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig,  \n");
229                 m->mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength)  \n");    
230                 m->mothurOut("Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n");
231                 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
232
233         }
234         catch(exception& e) {
235                 m->errorOut(e, "ScreenSeqsCommand", "help");
236                 exit(1);
237         }
238 }
239
240 //***************************************************************************************************************
241
242 ScreenSeqsCommand::~ScreenSeqsCommand(){        /*      do nothing      */      }
243
244 //***************************************************************************************************************
245
246 int ScreenSeqsCommand::execute(){
247         try{
248                 
249                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
250                 
251                 //if the user want to optimize we need to no the 90% mark
252                 vector<unsigned long int> positions;
253                 if (optimize.size() != 0) {  getSummary(positions); } //get summary is paralellized so we need to divideFile, no need to do this step twice so I moved it here
254                 else { 
255                         positions = m->divideFile(fastafile, processors);
256                         for (int i = 0; i < (positions.size()-1); i++) {
257                                 lines.push_back(new linePair(positions[i], positions[(i+1)]));
258                         }       
259                 }
260                                 
261                 string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "good" + m->getExtension(fastafile);
262                 string badAccnosFile =  outputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos";
263                 
264                 int numFastaSeqs = 0;
265                 set<string> badSeqNames;
266                 int start = time(NULL);
267                 
268 #ifdef USE_MPI  
269                         int pid, numSeqsPerProcessor; 
270                         int tag = 2001;
271                         vector<unsigned long int> MPIPos;
272                         
273                         MPI_Status status; 
274                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
275                         MPI_Comm_size(MPI_COMM_WORLD, &processors); 
276
277                         MPI_File inMPI;
278                         MPI_File outMPIGood;
279                         MPI_File outMPIBadAccnos;
280                         
281                         int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY; 
282                         int inMode=MPI_MODE_RDONLY; 
283                         
284                         char outGoodFilename[1024];
285                         strcpy(outGoodFilename, goodSeqFile.c_str());
286
287                         char outBadAccnosFilename[1024];
288                         strcpy(outBadAccnosFilename, badAccnosFile.c_str());
289
290                         char inFileName[1024];
291                         strcpy(inFileName, fastafile.c_str());
292                         
293                         MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
294                         MPI_File_open(MPI_COMM_WORLD, outGoodFilename, outMode, MPI_INFO_NULL, &outMPIGood);
295                         MPI_File_open(MPI_COMM_WORLD, outBadAccnosFilename, outMode, MPI_INFO_NULL, &outMPIBadAccnos);
296                         
297                         if (m->control_pressed) { MPI_File_close(&inMPI);  MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; }
298                         
299                         if (pid == 0) { //you are the root process 
300                                 
301                                 MPIPos = m->setFilePosFasta(fastafile, numFastaSeqs); //fills MPIPos, returns numSeqs
302                                 
303                                 //send file positions to all processes
304                                 for(int i = 1; i < processors; i++) { 
305                                         MPI_Send(&numFastaSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
306                                         MPI_Send(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
307                                 }
308                                 
309                                 //figure out how many sequences you have to align
310                                 numSeqsPerProcessor = numFastaSeqs / processors;
311                                 int startIndex =  pid * numSeqsPerProcessor;
312                                 if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
313                 //      cout << pid << '\t' << numSeqsPerProcessor << '\t' <<   startIndex << endl;
314                                 //align your part
315                                 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames);
316                 //cout << pid << " done" << endl;
317                                 if (m->control_pressed) { MPI_File_close(&inMPI);  MPI_File_close(&outMPIGood);  MPI_File_close(&outMPIBadAccnos);  return 0; }
318
319                                 for (int i = 1; i < processors; i++) {
320                                 
321                                         //get bad lists
322                                         int badSize;
323                                         MPI_Recv(&badSize, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status);
324                                         /*for (int j = 0; j < badSize; j++) {
325                                                 int length;
326                                                 MPI_Recv(&length, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status);  //recv the length of the name
327                                                 char* buf2 = new char[length];                                                                          //make space to recieve it
328                                                 MPI_Recv(buf2, length, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status);  //get name
329                                                 
330                                                 string tempBuf = buf2;
331                                                 if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
332                                                 delete buf2;
333                                                 
334                                                 badSeqNames.insert(tempBuf);
335                                         }*/
336                                 }
337                         }else{ //you are a child process
338                                 MPI_Recv(&numFastaSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
339                                 MPIPos.resize(numFastaSeqs+1);
340                                 MPI_Recv(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
341
342                                 //figure out how many sequences you have to align
343                                 numSeqsPerProcessor = numFastaSeqs / processors;
344                                 int startIndex =  pid * numSeqsPerProcessor;
345                                 if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
346                 //cout << pid << '\t' << numSeqsPerProcessor << '\t' <<         startIndex << endl;             
347                                 //align your part
348                                 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames);
349 //cout << pid << " done" << endl;
350                                 if (m->control_pressed) { MPI_File_close(&inMPI);  MPI_File_close(&outMPIGood);  MPI_File_close(&outMPIBadAccnos); return 0; }
351                                 
352                                 //send bad list 
353                                 int badSize = badSeqNames.size();
354                                 MPI_Send(&badSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
355                                 
356                                 /*
357                                 set<string>::iterator it;
358                                 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
359                                         string name = *it;
360                                         int length = name.length();
361                                         char* buf2 = new char[length];
362                                         memcpy(buf2, name.c_str(), length);
363                                         
364                                         MPI_Send(&length, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
365                                         MPI_Send(buf2, length, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
366                                 }*/
367                         }
368                         
369                         //close files 
370                         MPI_File_close(&inMPI);
371                         MPI_File_close(&outMPIGood);
372                         MPI_File_close(&outMPIBadAccnos);
373                         MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
374                                         
375 #else
376                                                 
377         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
378                         if(processors == 1){
379                                 numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);
380                                 
381                                 if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; }
382                                 
383                         }else{
384                                 processIDS.resize(0);
385                                 
386                                 numFastaSeqs = createProcesses(goodSeqFile, badAccnosFile, fastafile, badSeqNames); 
387                                 
388                                 rename((goodSeqFile + toString(processIDS[0]) + ".temp").c_str(), goodSeqFile.c_str());
389                                 rename((badAccnosFile + toString(processIDS[0]) + ".temp").c_str(), badAccnosFile.c_str());
390                                 
391                                 //append alignment and report files
392                                 for(int i=1;i<processors;i++){
393                                         m->appendFiles((goodSeqFile + toString(processIDS[i]) + ".temp"), goodSeqFile);
394                                         remove((goodSeqFile + toString(processIDS[i]) + ".temp").c_str());
395                         
396                                         m->appendFiles((badAccnosFile + toString(processIDS[i]) + ".temp"), badAccnosFile);
397                                         remove((badAccnosFile + toString(processIDS[i]) + ".temp").c_str());
398                                 }
399                                 
400                                 if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; }
401                                 
402                                 //read badSeqs in because root process doesnt know what other "bad" seqs the children found
403                                 ifstream inBad;
404                                 int ableToOpen = m->openInputFile(badAccnosFile, inBad, "no error");
405                                 
406                                 if (ableToOpen == 0) {
407                                         badSeqNames.clear();
408                                         string tempName;
409                                         while (!inBad.eof()) {
410                                                 inBad >> tempName; m->gobble(inBad);
411                                                 badSeqNames.insert(tempName);
412                                         }
413                                         inBad.close();
414                                 }
415                         }
416         #else
417                         numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);
418                         
419                         if (m->control_pressed) { remove(goodSeqFile.c_str()); return 0; }
420                         
421         #endif
422
423 #endif          
424
425                 #ifdef USE_MPI
426                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
427                                         
428                         if (pid == 0) { //only one process should fix files
429                         
430                                 //read accnos file with all names in it, process 0 just has its names
431                                 MPI_File inMPIAccnos;
432                                 MPI_Offset size;
433                         
434                                 char inFileName[1024];
435                                 strcpy(inFileName, badAccnosFile.c_str());
436                         
437                                 MPI_File_open(MPI_COMM_SELF, inFileName, inMode, MPI_INFO_NULL, &inMPIAccnos);  //comm, filename, mode, info, filepointer
438                                 MPI_File_get_size(inMPIAccnos, &size);
439                         
440                                 char* buffer = new char[size];
441                                 MPI_File_read(inMPIAccnos, buffer, size, MPI_CHAR, &status);
442                         
443                                 string tempBuf = buffer;
444                                 if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size);  }
445                                 istringstream iss (tempBuf,istringstream::in);
446
447                                 delete buffer;
448                                 MPI_File_close(&inMPIAccnos);
449                                 
450                                 badSeqNames.clear();
451                                 string tempName;
452                                 while (!iss.eof()) {
453                                         iss >> tempName; m->gobble(iss);
454                                         badSeqNames.insert(tempName);
455                                 }
456                 #endif
457                                                                                                                                                                         
458                 if(namefile != "" && groupfile != "")   {       
459                         screenNameGroupFile(badSeqNames);       
460                         if (m->control_pressed) {  remove(goodSeqFile.c_str()); return 0; }
461                 }else if(namefile != "")        {       
462                         screenNameGroupFile(badSeqNames);
463                         if (m->control_pressed) {  remove(goodSeqFile.c_str());  return 0; }    
464                 }else if(groupfile != "")                               {       screenGroupFile(badSeqNames);           }       // this screens just the group
465                 
466                 if (m->control_pressed) { remove(goodSeqFile.c_str());  return 0; }
467
468                 if(alignreport != "")                                   {       screenAlignReport(badSeqNames);         }
469                 
470                 if (m->control_pressed) { remove(goodSeqFile.c_str());  return 0; }
471                 
472                 #ifdef USE_MPI
473                         }
474                 #endif
475
476                 m->mothurOutEndLine();
477                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
478                 m->mothurOut(goodSeqFile); m->mothurOutEndLine();       outputTypes["fasta"].push_back(goodSeqFile);
479                 m->mothurOut(badAccnosFile); m->mothurOutEndLine();      outputTypes["accnos"].push_back(badAccnosFile);
480                 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
481                 m->mothurOutEndLine();
482                 m->mothurOutEndLine();
483
484                 m->mothurOut("It took " + toString(time(NULL) - start) + " secs to screen " + toString(numFastaSeqs) + " sequences.");
485                 m->mothurOutEndLine();
486
487                 return 0;
488         }
489         catch(exception& e) {
490                 m->errorOut(e, "ScreenSeqsCommand", "execute");
491                 exit(1);
492         }
493 }
494
495 //***************************************************************************************************************
496
497 int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
498         try {
499                 ifstream inputNames;
500                 m->openInputFile(namefile, inputNames);
501                 set<string> badSeqGroups;
502                 string seqName, seqList, group;
503                 set<string>::iterator it;
504
505                 string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + "good" + m->getExtension(namefile);
506                 outputNames.push_back(goodNameFile);  outputTypes["name"].push_back(goodNameFile);
507                 
508                 ofstream goodNameOut;   m->openOutputFile(goodNameFile, goodNameOut);
509                 
510                 while(!inputNames.eof()){
511                         if (m->control_pressed) { goodNameOut.close();  inputNames.close(); remove(goodNameFile.c_str());  return 0; }
512
513                         inputNames >> seqName >> seqList;
514                         it = badSeqNames.find(seqName);
515                                 
516                         if(it != badSeqNames.end()){
517                                 badSeqNames.erase(it);
518                                 
519                                 if(namefile != ""){
520                                         int start = 0;
521                                         for(int i=0;i<seqList.length();i++){
522                                                 if(seqList[i] == ','){
523                                                         badSeqGroups.insert(seqList.substr(start,i-start));
524                                                         start = i+1;
525                                                 }                                       
526                                         }
527                                         badSeqGroups.insert(seqList.substr(start,seqList.length()-start));
528                                 }
529                         }
530                         else{
531                                 goodNameOut << seqName << '\t' << seqList << endl;
532                         }
533                         m->gobble(inputNames);
534                 }
535                 inputNames.close();
536                 goodNameOut.close();
537         
538                 //we were unable to remove some of the bad sequences
539                 if (badSeqNames.size() != 0) {
540                         for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
541                                 m->mothurOut("Your namefile does not include the sequence " + *it + " please correct."); 
542                                 m->mothurOutEndLine();
543                         }
544                 }
545
546                 if(groupfile != ""){
547                         
548                         ifstream inputGroups;
549                         m->openInputFile(groupfile, inputGroups);
550
551                         string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile);
552                         outputNames.push_back(goodGroupFile);   outputTypes["group"].push_back(goodGroupFile);
553                         
554                         ofstream goodGroupOut;  m->openOutputFile(goodGroupFile, goodGroupOut);
555                         
556                         while(!inputGroups.eof()){
557                                 if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodNameFile.c_str());  remove(goodGroupFile.c_str()); return 0; }
558
559                                 inputGroups >> seqName >> group;
560                                 
561                                 it = badSeqGroups.find(seqName);
562                                 
563                                 if(it != badSeqGroups.end()){
564                                         badSeqGroups.erase(it);
565                                 }
566                                 else{
567                                         goodGroupOut << seqName << '\t' << group << endl;
568                                 }
569                                 m->gobble(inputGroups);
570                         }
571                         inputGroups.close();
572                         goodGroupOut.close();
573                         
574                         //we were unable to remove some of the bad sequences
575                         if (badSeqGroups.size() != 0) {
576                                 for (it = badSeqGroups.begin(); it != badSeqGroups.end(); it++) {  
577                                         m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); 
578                                         m->mothurOutEndLine();
579                                 }
580                         }
581                 }
582                 
583                 
584                 return 0;
585         
586         }
587         catch(exception& e) {
588                 m->errorOut(e, "ScreenSeqsCommand", "screenNameGroupFile");
589                 exit(1);
590         }
591 }
592 //***************************************************************************************************************
593 int ScreenSeqsCommand::getSummary(vector<unsigned long int>& positions){
594         try {
595                 
596                 vector<int> startPosition;
597                 vector<int> endPosition;
598                 vector<int> seqLength;
599                 vector<int> ambigBases;
600                 vector<int> longHomoPolymer;
601                 
602                 vector<unsigned long int> positions = m->divideFile(fastafile, processors);
603                                 
604                 for (int i = 0; i < (positions.size()-1); i++) {
605                         lines.push_back(new linePair(positions[i], positions[(i+1)]));
606                 }       
607                 
608                 int numSeqs = 0;
609                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
610                         if(processors == 1){
611                                 numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
612                         }else{
613                                 numSeqs = createProcessesCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile); 
614                         }
615                                 
616                         if (m->control_pressed) {  return 0; }
617                 #else
618                         numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
619                         if (m->control_pressed) {  return 0; }
620                 #endif
621
622                 sort(startPosition.begin(), startPosition.end());
623                 sort(endPosition.begin(), endPosition.end());
624                 sort(seqLength.begin(), seqLength.end());
625                 sort(ambigBases.begin(), ambigBases.end());
626                 sort(longHomoPolymer.begin(), longHomoPolymer.end());
627                 
628                 int criteriaPercentile  = int(numSeqs * (criteria / (float) 100));
629                 
630                 for (int i = 0; i < optimize.size(); i++) {
631                         if (optimize[i] == "start") { startPos = startPosition[criteriaPercentile]; m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); }
632                         else if (optimize[i] == "end") { int endcriteriaPercentile = int(numSeqs * ((100 - criteria) / (float) 100));  endPos = endPosition[endcriteriaPercentile]; m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();}
633                         else if (optimize[i] == "maxambig") { maxAmbig = ambigBases[criteriaPercentile]; m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); }
634                         else if (optimize[i] == "maxhomop") { maxHomoP = longHomoPolymer[criteriaPercentile]; m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); }
635                         else if (optimize[i] == "minlength") { int mincriteriaPercentile = int(numSeqs * ((100 - criteria) / (float) 100)); minLength = seqLength[mincriteriaPercentile]; m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); }
636                         else if (optimize[i] == "maxlength") { maxLength = seqLength[criteriaPercentile]; m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); }
637                 }
638
639                 return 0;
640         }
641         catch(exception& e) {
642                 m->errorOut(e, "ScreenSeqsCommand", "getSummary");
643                 exit(1);
644         }
645 }
646 /**************************************************************************************/
647 int ScreenSeqsCommand::driverCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename, linePair* filePos) {   
648         try {
649                 
650                 ifstream in;
651                 m->openInputFile(filename, in);
652                                 
653                 in.seekg(filePos->start);
654
655                 bool done = false;
656                 int count = 0;
657         
658                 while (!done) {
659                                 
660                         if (m->control_pressed) { in.close(); return 1; }
661                                         
662                         Sequence current(in); m->gobble(in);
663         
664                         if (current.getName() != "") {
665                                 startPosition.push_back(current.getStartPos());
666                                 endPosition.push_back(current.getEndPos());
667                                 seqLength.push_back(current.getNumBases());
668                                 ambigBases.push_back(current.getAmbigBases());
669                                 longHomoPolymer.push_back(current.getLongHomoPolymer());
670                                 count++;
671                         }
672                         
673                         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
674                                 unsigned long int pos = in.tellg();
675                                 if ((pos == -1) || (pos >= filePos->end)) { break; }
676                         #else
677                                 if (in.eof()) { break; }
678                         #endif
679                         
680                 }
681                 
682                 in.close();
683                 
684                 return count;
685         }
686         catch(exception& e) {
687                 m->errorOut(e, "ScreenSeqsCommand", "driverCreateSummary");
688                 exit(1);
689         }
690 }
691 /**************************************************************************************************/
692 int ScreenSeqsCommand::createProcessesCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename) {
693         try {
694 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
695                 int process = 1;
696                 int num = 0;
697                 processIDS.clear();
698                 
699                 //loop through and create all the processes you want
700                 while (process != processors) {
701                         int pid = fork();
702                         
703                         if (pid > 0) {
704                                 processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
705                                 process++;
706                         }else if (pid == 0){
707                                 num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[process]);
708                                 
709                                 //pass numSeqs to parent
710                                 ofstream out;
711                                 string tempFile = fastafile + toString(getpid()) + ".num.temp";
712                                 m->openOutputFile(tempFile, out);
713                                 
714                                 out << num << endl;
715                                 for (int k = 0; k < startPosition.size(); k++)          {               out << startPosition[k] << '\t'; }  out << endl;
716                                 for (int k = 0; k < endPosition.size(); k++)            {               out << endPosition[k] << '\t'; }  out << endl;
717                                 for (int k = 0; k < seqLength.size(); k++)                      {               out << seqLength[k] << '\t'; }  out << endl;
718                                 for (int k = 0; k < ambigBases.size(); k++)                     {               out << ambigBases[k] << '\t'; }  out << endl;
719                                 for (int k = 0; k < longHomoPolymer.size(); k++)        {               out << longHomoPolymer[k] << '\t'; }  out << endl;
720                                 
721                                 out.close();
722                                 
723                                 exit(0);
724                         }else { 
725                                 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
726                                 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
727                                 exit(0);
728                         }
729                 }
730                 
731                 num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
732                 
733                 //force parent to wait until all the processes are done
734                 for (int i=0;i<processIDS.size();i++) { 
735                         int temp = processIDS[i];
736                         wait(&temp);
737                 }
738                 
739                 //parent reads in and combine Filter info
740                 for (int i = 0; i < processIDS.size(); i++) {
741                         string tempFilename = fastafile + toString(processIDS[i]) + ".num.temp";
742                         ifstream in;
743                         m->openInputFile(tempFilename, in);
744                         
745                         int temp, tempNum;
746                         in >> tempNum; m->gobble(in); num += tempNum;
747                         for (int k = 0; k < tempNum; k++)                       {               in >> temp; startPosition.push_back(temp);              }               m->gobble(in);
748                         for (int k = 0; k < tempNum; k++)                       {               in >> temp; endPosition.push_back(temp);                }               m->gobble(in);
749                         for (int k = 0; k < tempNum; k++)                       {               in >> temp; seqLength.push_back(temp);                  }               m->gobble(in);
750                         for (int k = 0; k < tempNum; k++)                       {               in >> temp; ambigBases.push_back(temp);                 }               m->gobble(in);
751                         for (int k = 0; k < tempNum; k++)                       {               in >> temp; longHomoPolymer.push_back(temp);    }               m->gobble(in);
752                                 
753                         in.close();
754                         remove(tempFilename.c_str());
755                 }
756                 
757                 return num;
758 #endif          
759         }
760         catch(exception& e) {
761                 m->errorOut(e, "ScreenSeqsCommand", "createProcessesCreateSummary");
762                 exit(1);
763         }
764 }
765
766 //***************************************************************************************************************
767
768 int ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
769         try {
770                 ifstream inputGroups;
771                 m->openInputFile(groupfile, inputGroups);
772                 string seqName, group;
773                 set<string>::iterator it;
774                 
775                 string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile);
776                 outputNames.push_back(goodGroupFile);  outputTypes["group"].push_back(goodGroupFile);
777                 ofstream goodGroupOut;  m->openOutputFile(goodGroupFile, goodGroupOut);
778                 
779                 while(!inputGroups.eof()){
780                         if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); remove(goodGroupFile.c_str()); return 0; }
781
782                         inputGroups >> seqName >> group;
783                         it = badSeqNames.find(seqName);
784                         
785                         if(it != badSeqNames.end()){
786                                 badSeqNames.erase(it);
787                         }
788                         else{
789                                 goodGroupOut << seqName << '\t' << group << endl;
790                         }
791                         m->gobble(inputGroups);
792                 }
793                 
794                 if (m->control_pressed) { goodGroupOut.close();  inputGroups.close(); remove(goodGroupFile.c_str());  return 0; }
795
796                 //we were unable to remove some of the bad sequences
797                 if (badSeqNames.size() != 0) {
798                         for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
799                                 m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); 
800                                 m->mothurOutEndLine();
801                         }
802                 }
803                 
804                 inputGroups.close();
805                 goodGroupOut.close();
806                 
807                 if (m->control_pressed) { remove(goodGroupFile.c_str());   }
808                 
809                 return 0;
810         
811         }
812         catch(exception& e) {
813                 m->errorOut(e, "ScreenSeqsCommand", "screenGroupFile");
814                 exit(1);
815         }
816 }
817
818 //***************************************************************************************************************
819
820 int ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
821         try {
822                 ifstream inputAlignReport;
823                 m->openInputFile(alignreport, inputAlignReport);
824                 string seqName, group;
825                 set<string>::iterator it;
826                 
827                 string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + "good" + m->getExtension(alignreport);
828                 outputNames.push_back(goodAlignReportFile);  outputTypes["alignreport"].push_back(goodAlignReportFile);
829                 ofstream goodAlignReportOut;    m->openOutputFile(goodAlignReportFile, goodAlignReportOut);
830
831                 while (!inputAlignReport.eof()) {               //      need to copy header
832                         char c = inputAlignReport.get();
833                         goodAlignReportOut << c;
834                         if (c == 10 || c == 13){        break;  }       
835                 }
836
837                 while(!inputAlignReport.eof()){
838                         if (m->control_pressed) { goodAlignReportOut.close(); inputAlignReport.close(); remove(goodAlignReportFile.c_str()); return 0; }
839
840                         inputAlignReport >> seqName;
841                         it = badSeqNames.find(seqName);
842                         string line;            
843                         while (!inputAlignReport.eof()) {               //      need to copy header
844                                 char c = inputAlignReport.get();
845                                 line += c;
846                                 if (c == 10 || c == 13){        break;  }       
847                         }
848                         
849                         if(it != badSeqNames.end()){
850                                 badSeqNames.erase(it);
851                         }
852                         else{
853                                 goodAlignReportOut << seqName << '\t' << line;
854                         }
855                         m->gobble(inputAlignReport);
856                 }
857                 
858                 if (m->control_pressed) { goodAlignReportOut.close();  inputAlignReport.close(); remove(goodAlignReportFile.c_str());  return 0; }
859
860                 //we were unable to remove some of the bad sequences
861                 if (badSeqNames.size() != 0) {
862                         for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {  
863                                 m->mothurOut("Your alignreport file does not include the sequence " + *it + " please correct."); 
864                                 m->mothurOutEndLine();
865                         }
866                 }
867
868                 inputAlignReport.close();
869                 goodAlignReportOut.close();
870                                 
871                 if (m->control_pressed) {  remove(goodAlignReportFile.c_str());  return 0; }
872                 
873                 return 0;
874         
875         }
876         catch(exception& e) {
877                 m->errorOut(e, "ScreenSeqsCommand", "screenAlignReport");
878                 exit(1);
879         }
880         
881 }
882 //**********************************************************************************************************************
883
884 int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badAccnosFName, string filename, set<string>& badSeqNames){
885         try {
886                 ofstream goodFile;
887                 m->openOutputFile(goodFName, goodFile);
888                 
889                 ofstream badAccnosFile;
890                 m->openOutputFile(badAccnosFName, badAccnosFile);
891                 
892                 ifstream inFASTA;
893                 m->openInputFile(filename, inFASTA);
894
895                 inFASTA.seekg(filePos->start);
896
897                 bool done = false;
898                 int count = 0;
899         
900                 while (!done) {
901                 
902                         if (m->control_pressed) {  return 0; }
903                         
904                         Sequence currSeq(inFASTA); m->gobble(inFASTA);
905                         if (currSeq.getName() != "") {
906                                 bool goodSeq = 1;               //      innocent until proven guilty
907                                 if(goodSeq == 1 && startPos != -1 && startPos < currSeq.getStartPos())                  {       goodSeq = 0;    }
908                                 if(goodSeq == 1 && endPos != -1 && endPos > currSeq.getEndPos())                                {       goodSeq = 0;    }
909                                 if(goodSeq == 1 && maxAmbig != -1 && maxAmbig < currSeq.getAmbigBases())                {       goodSeq = 0;    }
910                                 if(goodSeq == 1 && maxHomoP != -1 && maxHomoP < currSeq.getLongHomoPolymer())   {       goodSeq = 0;    }
911                                 if(goodSeq == 1 && minLength != -1 && minLength > currSeq.getNumBases())                {       goodSeq = 0;    }
912                                 if(goodSeq == 1 && maxLength != -1 && maxLength < currSeq.getNumBases())                {       goodSeq = 0;    }
913                                 
914                                 if(goodSeq == 1){
915                                         currSeq.printSequence(goodFile);        
916                                 }
917                                 else{
918                                         badAccnosFile << currSeq.getName() << endl;
919                                         badSeqNames.insert(currSeq.getName());
920                                 }
921                         count++;
922                         }
923                         
924                         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
925                                 unsigned long int pos = inFASTA.tellg();
926                                 if ((pos == -1) || (pos >= filePos->end)) { break; }
927                         #else
928                                 if (inFASTA.eof()) { break; }
929                         #endif
930                         
931                         //report progress
932                         if((count) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine();         }
933                 }
934                 //report progress
935                 if((count) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine();         }
936                 
937                         
938                 goodFile.close();
939                 inFASTA.close();
940                 badAccnosFile.close();
941                 
942                 return count;
943         }
944         catch(exception& e) {
945                 m->errorOut(e, "ScreenSeqsCommand", "driver");
946                 exit(1);
947         }
948 }
949 //**********************************************************************************************************************
950 #ifdef USE_MPI
951 int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& goodFile, MPI_File& badAccnosFile, vector<unsigned long int>& MPIPos, set<string>& badSeqNames){
952         try {
953                 string outputString = "";
954                 MPI_Status statusGood; 
955                 MPI_Status statusBadAccnos; 
956                 MPI_Status status; 
957                 int pid;
958                 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
959
960                 for(int i=0;i<num;i++){
961                 
962                         if (m->control_pressed) {  return 0; }
963                         
964                         //read next sequence
965                         int length = MPIPos[start+i+1] - MPIPos[start+i];
966
967                         char* buf4 = new char[length];
968                         memcpy(buf4, outputString.c_str(), length);
969
970                         MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
971                         
972                         string tempBuf = buf4;  delete buf4;
973                         if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length);  }
974                         istringstream iss (tempBuf,istringstream::in);
975                         
976                         Sequence currSeq(iss);                  
977                         
978                         //process seq
979                         if (currSeq.getName() != "") {
980                                 bool goodSeq = 1;               //      innocent until proven guilty
981                                 if(goodSeq == 1 && startPos != -1 && startPos < currSeq.getStartPos())                  {       goodSeq = 0;    }
982                                 if(goodSeq == 1 && endPos != -1 && endPos > currSeq.getEndPos())                                {       goodSeq = 0;    }
983                                 if(goodSeq == 1 && maxAmbig != -1 && maxAmbig < currSeq.getAmbigBases())                {       goodSeq = 0;    }
984                                 if(goodSeq == 1 && maxHomoP != -1 && maxHomoP < currSeq.getLongHomoPolymer())   {       goodSeq = 0;    }
985                                 if(goodSeq == 1 && minLength != -1 && minLength > currSeq.getNumBases())                {       goodSeq = 0;    }
986                                 if(goodSeq == 1 && maxLength != -1 && maxLength < currSeq.getNumBases())                {       goodSeq = 0;    }
987                                 
988                                 if(goodSeq == 1){
989                                         outputString =  ">" + currSeq.getName() + "\n" + currSeq.getAligned() + "\n";
990                                 
991                                         //print good seq
992                                         length = outputString.length();
993                                         char* buf2 = new char[length];
994                                         memcpy(buf2, outputString.c_str(), length);
995                                         
996                                         MPI_File_write_shared(goodFile, buf2, length, MPI_CHAR, &statusGood);
997                                         delete buf2;
998                                 }
999                                 else{
1000
1001                                         badSeqNames.insert(currSeq.getName());
1002                                         
1003                                         //write to bad accnos file
1004                                         outputString = currSeq.getName() + "\n";
1005                                 
1006                                         length = outputString.length();
1007                                         char* buf3 = new char[length];
1008                                         memcpy(buf3, outputString.c_str(), length);
1009                                         
1010                                         MPI_File_write_shared(badAccnosFile, buf3, length, MPI_CHAR, &statusBadAccnos);
1011                                         delete buf3;
1012                                 }
1013                         }
1014                         
1015                         //report progress
1016                         if((i) % 100 == 0){     m->mothurOut("Processing sequence: " + toString(i)); m->mothurOutEndLine();             }
1017                 }
1018                                 
1019                 return 1;
1020         }
1021         catch(exception& e) {
1022                 m->errorOut(e, "ScreenSeqsCommand", "driverMPI");
1023                 exit(1);
1024         }
1025 }
1026 #endif
1027 /**************************************************************************************************/
1028
1029 int ScreenSeqsCommand::createProcesses(string goodFileName, string badAccnos, string filename, set<string>& badSeqNames) {
1030         try {
1031 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
1032                 int process = 0;
1033                 int num = 0;
1034                 
1035                 //loop through and create all the processes you want
1036                 while (process != processors) {
1037                         int pid = fork();
1038                         
1039                         if (pid > 0) {
1040                                 processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
1041                                 process++;
1042                         }else if (pid == 0){
1043                                 num = driver(lines[process], goodFileName + toString(getpid()) + ".temp", badAccnos + toString(getpid()) + ".temp", filename, badSeqNames);
1044                                 
1045                                 //pass numSeqs to parent
1046                                 ofstream out;
1047                                 string tempFile = filename + toString(getpid()) + ".num.temp";
1048                                 m->openOutputFile(tempFile, out);
1049                                 out << num << endl;
1050                                 out.close();
1051                                 
1052                                 exit(0);
1053                         }else { 
1054                                 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
1055                                 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
1056                                 exit(0);
1057                         }
1058                 }
1059                 
1060                 //force parent to wait until all the processes are done
1061                 for (int i=0;i<processors;i++) { 
1062                         int temp = processIDS[i];
1063                         wait(&temp);
1064                 }
1065                 
1066                 for (int i = 0; i < processIDS.size(); i++) {
1067                         ifstream in;
1068                         string tempFile =  filename + toString(processIDS[i]) + ".num.temp";
1069                         m->openInputFile(tempFile, in);
1070                         if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
1071                         in.close(); remove(tempFile.c_str());
1072                 }
1073                 
1074                 return num;
1075 #endif          
1076         }
1077         catch(exception& e) {
1078                 m->errorOut(e, "ScreenSeqsCommand", "createProcesses");
1079                 exit(1);
1080         }
1081 }
1082
1083 //***************************************************************************************************************
1084
1085