2 * screenseqscommand.cpp
5 * Created by Pat Schloss on 6/3/09.
6 * Copyright 2009 Patrick D. Schloss. All rights reserved.
10 #include "screenseqscommand.h"
11 #include "sequence.hpp"
13 //**********************************************************************************************************************
14 vector<string> ScreenSeqsCommand::setParameters(){
16 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta);
17 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
18 CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
19 CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile);
20 CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(palignreport);
21 CommandParameter ptax("taxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptax);
22 CommandParameter pstart("start", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pstart);
23 CommandParameter pend("end", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pend);
24 CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxambig);
25 CommandParameter pmaxhomop("maxhomop", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxhomop);
26 CommandParameter pminlength("minlength", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pminlength);
27 CommandParameter pmaxlength("maxlength", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxlength);
28 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
29 CommandParameter pcriteria("criteria", "Number", "", "90", "", "", "",false,false); parameters.push_back(pcriteria);
30 CommandParameter poptimize("optimize", "Multiple", "none-start-end-maxambig-maxhomop-minlength-maxlength", "none", "", "", "",true,false); parameters.push_back(poptimize);
31 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
32 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
34 vector<string> myArray;
35 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
39 m->errorOut(e, "ScreenSeqsCommand", "setParameters");
43 //**********************************************************************************************************************
44 string ScreenSeqsCommand::getHelpString(){
46 string helpString = "";
47 helpString += "The screen.seqs command reads a fastafile and creates .....\n";
48 helpString += "The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group, qfile, alignreport, taxonomy, optimize, criteria and processors.\n";
49 helpString += "The fasta parameter is required.\n";
50 helpString += "The alignreport and taxonomy parameters allow you to remove bad seqs from taxonomy and alignreport files.\n";
51 helpString += "The start parameter .... The default is -1.\n";
52 helpString += "The end parameter .... The default is -1.\n";
53 helpString += "The maxambig parameter allows you to set the maximum number of ambigious bases allowed. The default is -1.\n";
54 helpString += "The maxhomop parameter allows you to set a maximum homopolymer length. \n";
55 helpString += "The minlength parameter allows you to set and minimum sequence length. \n";
56 helpString += "The maxlength parameter allows you to set and maximum sequence length. \n";
57 helpString += "The processors parameter allows you to specify the number of processors to use while running the command. The default is 1.\n";
58 helpString += "The optimize and criteria parameters allow you set the start, end, maxabig, maxhomop, minlength and maxlength parameters relative to your set of sequences .\n";
59 helpString += "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";
60 helpString += "The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n";
61 helpString += "The screen.seqs command should be in the following format: \n";
62 helpString += "screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig, \n";
63 helpString += "maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n";
64 helpString += "Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n";
65 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
69 m->errorOut(e, "ScreenSeqsCommand", "getHelpString");
73 //**********************************************************************************************************************
74 ScreenSeqsCommand::ScreenSeqsCommand(){
76 abort = true; calledHelp = true;
78 vector<string> tempOutNames;
79 outputTypes["fasta"] = tempOutNames;
80 outputTypes["name"] = tempOutNames;
81 outputTypes["group"] = tempOutNames;
82 outputTypes["alignreport"] = tempOutNames;
83 outputTypes["accnos"] = tempOutNames;
84 outputTypes["qfile"] = tempOutNames;
85 outputTypes["taxonomy"] = tempOutNames;
88 m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand");
92 //***************************************************************************************************************
94 ScreenSeqsCommand::ScreenSeqsCommand(string option) {
96 abort = false; calledHelp = false;
98 //allow user to run help
99 if(option == "help") { help(); abort = true; calledHelp = true; }
100 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
103 vector<string> myArray = setParameters();
105 OptionParser parser(option);
106 map<string,string> parameters = parser.getParameters();
108 ValidParameters validParameter("screen.seqs");
109 map<string,string>::iterator it;
111 //check to make sure all parameters are valid for command
112 for (it = parameters.begin(); it != parameters.end(); it++) {
113 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
116 //initialize outputTypes
117 vector<string> tempOutNames;
118 outputTypes["fasta"] = tempOutNames;
119 outputTypes["name"] = tempOutNames;
120 outputTypes["group"] = tempOutNames;
121 outputTypes["alignreport"] = tempOutNames;
122 outputTypes["accnos"] = tempOutNames;
123 outputTypes["qfile"] = tempOutNames;
124 outputTypes["taxonomy"] = tempOutNames;
126 //if the user changes the input directory command factory will send this info to us in the output parameter
127 string inputDir = validParameter.validFile(parameters, "inputdir", false);
128 if (inputDir == "not found"){ inputDir = ""; }
131 it = parameters.find("fasta");
132 //user has given a template file
133 if(it != parameters.end()){
134 path = m->hasPath(it->second);
135 //if the user has not given a path then, add inputdir. else leave path alone.
136 if (path == "") { parameters["fasta"] = inputDir + it->second; }
139 it = parameters.find("group");
140 //user has given a template file
141 if(it != parameters.end()){
142 path = m->hasPath(it->second);
143 //if the user has not given a path then, add inputdir. else leave path alone.
144 if (path == "") { parameters["group"] = inputDir + it->second; }
147 it = parameters.find("name");
148 //user has given a template file
149 if(it != parameters.end()){
150 path = m->hasPath(it->second);
151 //if the user has not given a path then, add inputdir. else leave path alone.
152 if (path == "") { parameters["name"] = inputDir + it->second; }
155 it = parameters.find("alignreport");
156 //user has given a template file
157 if(it != parameters.end()){
158 path = m->hasPath(it->second);
159 //if the user has not given a path then, add inputdir. else leave path alone.
160 if (path == "") { parameters["alignreport"] = inputDir + it->second; }
163 it = parameters.find("qfile");
164 //user has given a template file
165 if(it != parameters.end()){
166 path = m->hasPath(it->second);
167 //if the user has not given a path then, add inputdir. else leave path alone.
168 if (path == "") { parameters["qfile"] = inputDir + it->second; }
171 it = parameters.find("taxonomy");
172 //user has given a template file
173 if(it != parameters.end()){
174 path = m->hasPath(it->second);
175 //if the user has not given a path then, add inputdir. else leave path alone.
176 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
180 //check for required parameters
181 fastafile = validParameter.validFile(parameters, "fasta", true);
182 if (fastafile == "not found") {
183 fastafile = m->getFastaFile();
184 if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
185 else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
187 else if (fastafile == "not open") { abort = true; }
188 else { m->setFastaFile(fastafile); }
190 groupfile = validParameter.validFile(parameters, "group", true);
191 if (groupfile == "not open") { abort = true; }
192 else if (groupfile == "not found") { groupfile = ""; }
193 else { m->setGroupFile(groupfile); }
195 qualfile = validParameter.validFile(parameters, "qfile", true);
196 if (qualfile == "not open") { abort = true; }
197 else if (qualfile == "not found") { qualfile = ""; }
198 else { m->setQualFile(qualfile); }
200 namefile = validParameter.validFile(parameters, "name", true);
201 if (namefile == "not open") { namefile = ""; abort = true; }
202 else if (namefile == "not found") { namefile = ""; }
203 else { m->setNameFile(namefile); }
205 alignreport = validParameter.validFile(parameters, "alignreport", true);
206 if (alignreport == "not open") { abort = true; }
207 else if (alignreport == "not found") { alignreport = ""; }
209 taxonomy = validParameter.validFile(parameters, "taxonomy", true);
210 if (taxonomy == "not open") { abort = true; }
211 else if (taxonomy == "not found") { taxonomy = ""; }
213 //if the user changes the output directory command factory will send this info to us in the output parameter
214 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){
216 outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it
219 //check for optional parameter and set defaults
220 // ...at some point should added some additional type checking...
222 temp = validParameter.validFile(parameters, "start", false); if (temp == "not found") { temp = "-1"; }
223 m->mothurConvert(temp, startPos);
225 temp = validParameter.validFile(parameters, "end", false); if (temp == "not found") { temp = "-1"; }
226 m->mothurConvert(temp, endPos);
228 temp = validParameter.validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; }
229 m->mothurConvert(temp, maxAmbig);
231 temp = validParameter.validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "-1"; }
232 m->mothurConvert(temp, maxHomoP);
234 temp = validParameter.validFile(parameters, "minlength", false); if (temp == "not found") { temp = "-1"; }
235 m->mothurConvert(temp, minLength);
237 temp = validParameter.validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "-1"; }
238 m->mothurConvert(temp, maxLength);
240 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
241 m->setProcessors(temp);
242 m->mothurConvert(temp, processors);
244 temp = validParameter.validFile(parameters, "optimize", false); //optimizing trumps the optimized values original value
245 if (temp == "not found"){ temp = "none"; }
246 m->splitAtDash(temp, optimize);
248 //check for invalid optimize options
249 set<string> validOptimizers;
250 validOptimizers.insert("none"); validOptimizers.insert("start"); validOptimizers.insert("end"); validOptimizers.insert("maxambig"); validOptimizers.insert("maxhomop"); validOptimizers.insert("minlength"); validOptimizers.insert("maxlength");
251 for (int i = 0; i < optimize.size(); i++) {
252 if (validOptimizers.count(optimize[i]) == 0) {
253 m->mothurOut(optimize[i] + " is not a valid optimizer. Valid options are start, end, maxambig, maxhomop, minlength and maxlength."); m->mothurOutEndLine();
254 optimize.erase(optimize.begin()+i);
259 if (optimize.size() == 1) { if (optimize[0] == "none") { optimize.clear(); } }
261 temp = validParameter.validFile(parameters, "criteria", false); if (temp == "not found"){ temp = "90"; }
262 m->mothurConvert(temp, criteria);
266 catch(exception& e) {
267 m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand");
271 //***************************************************************************************************************
273 int ScreenSeqsCommand::execute(){
276 if (abort == true) { if (calledHelp) { return 0; } return 2; }
278 //if the user want to optimize we need to know the 90% mark
279 vector<unsigned long long> positions;
280 if (optimize.size() != 0) { //get summary is paralellized so we need to divideFile, no need to do this step twice so I moved it here
281 //use the namefile to optimize correctly
282 if (namefile != "") { nameMap = m->readNames(namefile); }
283 getSummary(positions);
286 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
287 positions = m->divideFile(fastafile, processors);
288 for (int i = 0; i < (positions.size()-1); i++) {
289 lines.push_back(new linePair(positions[i], positions[(i+1)]));
292 positions.push_back(0); positions.push_back(1000);
293 lines.push_back(new linePair(0, 1000));
297 string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "good" + m->getExtension(fastafile);
298 string badAccnosFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos";
300 int numFastaSeqs = 0;
301 set<string> badSeqNames;
302 int start = time(NULL);
305 int pid, numSeqsPerProcessor;
307 vector<unsigned long long> MPIPos;
310 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
311 MPI_Comm_size(MPI_COMM_WORLD, &processors);
315 MPI_File outMPIBadAccnos;
317 int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
318 int inMode=MPI_MODE_RDONLY;
320 char outGoodFilename[1024];
321 strcpy(outGoodFilename, goodSeqFile.c_str());
323 char outBadAccnosFilename[1024];
324 strcpy(outBadAccnosFilename, badAccnosFile.c_str());
326 char inFileName[1024];
327 strcpy(inFileName, fastafile.c_str());
329 MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
330 MPI_File_open(MPI_COMM_WORLD, outGoodFilename, outMode, MPI_INFO_NULL, &outMPIGood);
331 MPI_File_open(MPI_COMM_WORLD, outBadAccnosFilename, outMode, MPI_INFO_NULL, &outMPIBadAccnos);
333 if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; }
335 if (pid == 0) { //you are the root process
337 MPIPos = m->setFilePosFasta(fastafile, numFastaSeqs); //fills MPIPos, returns numSeqs
339 //send file positions to all processes
340 for(int i = 1; i < processors; i++) {
341 MPI_Send(&numFastaSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
342 MPI_Send(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
345 //figure out how many sequences you have to align
346 numSeqsPerProcessor = numFastaSeqs / processors;
347 int startIndex = pid * numSeqsPerProcessor;
348 if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
349 // cout << pid << '\t' << numSeqsPerProcessor << '\t' << startIndex << endl;
351 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames);
352 //cout << pid << " done" << endl;
353 if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; }
355 for (int i = 1; i < processors; i++) {
359 MPI_Recv(&badSize, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status);
360 /*for (int j = 0; j < badSize; j++) {
362 MPI_Recv(&length, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status); //recv the length of the name
363 char* buf2 = new char[length]; //make space to recieve it
364 MPI_Recv(buf2, length, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status); //get name
366 string tempBuf = buf2;
367 if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
370 badSeqNames.insert(tempBuf);
373 }else{ //you are a child process
374 MPI_Recv(&numFastaSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
375 MPIPos.resize(numFastaSeqs+1);
376 MPI_Recv(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
378 //figure out how many sequences you have to align
379 numSeqsPerProcessor = numFastaSeqs / processors;
380 int startIndex = pid * numSeqsPerProcessor;
381 if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
382 //cout << pid << '\t' << numSeqsPerProcessor << '\t' << startIndex << endl;
384 driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames);
385 //cout << pid << " done" << endl;
386 if (m->control_pressed) { MPI_File_close(&inMPI); MPI_File_close(&outMPIGood); MPI_File_close(&outMPIBadAccnos); return 0; }
389 int badSize = badSeqNames.size();
390 MPI_Send(&badSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
393 set<string>::iterator it;
394 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
396 int length = name.length();
397 char* buf2 = new char[length];
398 memcpy(buf2, name.c_str(), length);
400 MPI_Send(&length, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
401 MPI_Send(buf2, length, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
406 MPI_File_close(&inMPI);
407 MPI_File_close(&outMPIGood);
408 MPI_File_close(&outMPIBadAccnos);
409 MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
413 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
415 numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);
417 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
420 processIDS.resize(0);
422 numFastaSeqs = createProcesses(goodSeqFile, badAccnosFile, fastafile, badSeqNames);
424 rename((goodSeqFile + toString(processIDS[0]) + ".temp").c_str(), goodSeqFile.c_str());
425 rename((badAccnosFile + toString(processIDS[0]) + ".temp").c_str(), badAccnosFile.c_str());
427 //append alignment and report files
428 for(int i=1;i<processors;i++){
429 m->appendFiles((goodSeqFile + toString(processIDS[i]) + ".temp"), goodSeqFile);
430 m->mothurRemove((goodSeqFile + toString(processIDS[i]) + ".temp"));
432 m->appendFiles((badAccnosFile + toString(processIDS[i]) + ".temp"), badAccnosFile);
433 m->mothurRemove((badAccnosFile + toString(processIDS[i]) + ".temp"));
436 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
438 //read badSeqs in because root process doesnt know what other "bad" seqs the children found
440 int ableToOpen = m->openInputFile(badAccnosFile, inBad, "no error");
442 if (ableToOpen == 0) {
445 while (!inBad.eof()) {
446 inBad >> tempName; m->gobble(inBad);
447 badSeqNames.insert(tempName);
453 numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);
455 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
462 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
464 if (pid == 0) { //only one process should fix files
466 //read accnos file with all names in it, process 0 just has its names
467 MPI_File inMPIAccnos;
470 char inFileName[1024];
471 strcpy(inFileName, badAccnosFile.c_str());
473 MPI_File_open(MPI_COMM_SELF, inFileName, inMode, MPI_INFO_NULL, &inMPIAccnos); //comm, filename, mode, info, filepointer
474 MPI_File_get_size(inMPIAccnos, &size);
476 char* buffer = new char[size];
477 MPI_File_read(inMPIAccnos, buffer, size, MPI_CHAR, &status);
479 string tempBuf = buffer;
480 if (tempBuf.length() > size) { tempBuf = tempBuf.substr(0, size); }
481 istringstream iss (tempBuf,istringstream::in);
484 MPI_File_close(&inMPIAccnos);
489 iss >> tempName; m->gobble(iss);
490 badSeqNames.insert(tempName);
494 if(namefile != "" && groupfile != "") {
495 screenNameGroupFile(badSeqNames);
496 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
497 }else if(namefile != "") {
498 screenNameGroupFile(badSeqNames);
499 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
500 }else if(groupfile != "") { screenGroupFile(badSeqNames); } // this screens just the group
502 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
504 if(alignreport != "") { screenAlignReport(badSeqNames); }
505 if(qualfile != "") { screenQual(badSeqNames); }
506 if(taxonomy != "") { screenTaxonomy(badSeqNames); }
508 if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
514 m->mothurOutEndLine();
515 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
516 m->mothurOut(goodSeqFile); m->mothurOutEndLine(); outputTypes["fasta"].push_back(goodSeqFile);
517 m->mothurOut(badAccnosFile); m->mothurOutEndLine(); outputTypes["accnos"].push_back(badAccnosFile);
518 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
519 m->mothurOutEndLine();
520 m->mothurOutEndLine();
522 //set fasta file as new current fastafile
524 itTypes = outputTypes.find("fasta");
525 if (itTypes != outputTypes.end()) {
526 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
529 itTypes = outputTypes.find("name");
530 if (itTypes != outputTypes.end()) {
531 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
534 itTypes = outputTypes.find("group");
535 if (itTypes != outputTypes.end()) {
536 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
539 itTypes = outputTypes.find("qfile");
540 if (itTypes != outputTypes.end()) {
541 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
544 itTypes = outputTypes.find("taxonomy");
545 if (itTypes != outputTypes.end()) {
546 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
549 m->mothurOut("It took " + toString(time(NULL) - start) + " secs to screen " + toString(numFastaSeqs) + " sequences.");
550 m->mothurOutEndLine();
554 catch(exception& e) {
555 m->errorOut(e, "ScreenSeqsCommand", "execute");
560 //***************************************************************************************************************
562 int ScreenSeqsCommand::screenNameGroupFile(set<string> badSeqNames){
565 m->openInputFile(namefile, inputNames);
566 set<string> badSeqGroups;
567 string seqName, seqList, group;
568 set<string>::iterator it;
570 string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + "good" + m->getExtension(namefile);
571 outputNames.push_back(goodNameFile); outputTypes["name"].push_back(goodNameFile);
573 ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut);
575 while(!inputNames.eof()){
576 if (m->control_pressed) { goodNameOut.close(); inputNames.close(); m->mothurRemove(goodNameFile); return 0; }
578 inputNames >> seqName >> seqList;
579 it = badSeqNames.find(seqName);
581 if(it != badSeqNames.end()){
582 badSeqNames.erase(it);
586 for(int i=0;i<seqList.length();i++){
587 if(seqList[i] == ','){
588 badSeqGroups.insert(seqList.substr(start,i-start));
592 badSeqGroups.insert(seqList.substr(start,seqList.length()-start));
596 goodNameOut << seqName << '\t' << seqList << endl;
598 m->gobble(inputNames);
603 //we were unable to remove some of the bad sequences
604 if (badSeqNames.size() != 0) {
605 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
606 m->mothurOut("Your namefile does not include the sequence " + *it + " please correct.");
607 m->mothurOutEndLine();
613 ifstream inputGroups;
614 m->openInputFile(groupfile, inputGroups);
616 string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile);
617 outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile);
619 ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut);
621 while(!inputGroups.eof()){
622 if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); m->mothurRemove(goodNameFile); m->mothurRemove(goodGroupFile); return 0; }
624 inputGroups >> seqName >> group;
626 it = badSeqGroups.find(seqName);
628 if(it != badSeqGroups.end()){
629 badSeqGroups.erase(it);
632 goodGroupOut << seqName << '\t' << group << endl;
634 m->gobble(inputGroups);
637 goodGroupOut.close();
639 //we were unable to remove some of the bad sequences
640 if (badSeqGroups.size() != 0) {
641 for (it = badSeqGroups.begin(); it != badSeqGroups.end(); it++) {
642 m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct.");
643 m->mothurOutEndLine();
652 catch(exception& e) {
653 m->errorOut(e, "ScreenSeqsCommand", "screenNameGroupFile");
657 //***************************************************************************************************************
658 int ScreenSeqsCommand::getSummary(vector<unsigned long long>& positions){
661 vector<int> startPosition;
662 vector<int> endPosition;
663 vector<int> seqLength;
664 vector<int> ambigBases;
665 vector<int> longHomoPolymer;
667 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
668 vector<unsigned long long> positions = m->divideFile(fastafile, processors);
670 for (int i = 0; i < (positions.size()-1); i++) {
671 lines.push_back(new linePair(positions[i], positions[(i+1)]));
674 lines.push_back(new linePair(0, 1000));
679 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
682 driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
685 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
687 numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
689 numSeqs = createProcessesCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile);
692 if (m->control_pressed) { return 0; }
694 numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
695 if (m->control_pressed) { return 0; }
698 sort(startPosition.begin(), startPosition.end());
699 sort(endPosition.begin(), endPosition.end());
700 sort(seqLength.begin(), seqLength.end());
701 sort(ambigBases.begin(), ambigBases.end());
702 sort(longHomoPolymer.begin(), longHomoPolymer.end());
704 //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs
705 int criteriaPercentile = int(startPosition.size() * (criteria / (float) 100));
707 for (int i = 0; i < optimize.size(); i++) {
708 if (optimize[i] == "start") { startPos = startPosition[criteriaPercentile]; m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); }
709 else if (optimize[i] == "end") { int endcriteriaPercentile = int(endPosition.size() * ((100 - criteria) / (float) 100)); endPos = endPosition[endcriteriaPercentile]; m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();}
710 else if (optimize[i] == "maxambig") { maxAmbig = ambigBases[criteriaPercentile]; m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); }
711 else if (optimize[i] == "maxhomop") { maxHomoP = longHomoPolymer[criteriaPercentile]; m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); }
712 else if (optimize[i] == "minlength") { int mincriteriaPercentile = int(seqLength.size() * ((100 - criteria) / (float) 100)); minLength = seqLength[mincriteriaPercentile]; m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); }
713 else if (optimize[i] == "maxlength") { maxLength = seqLength[criteriaPercentile]; m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); }
720 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
721 MPI_Comm_size(MPI_COMM_WORLD, &processors);
724 //send file positions to all processes
725 for(int i = 1; i < processors; i++) {
726 MPI_Send(&startPos, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
727 MPI_Send(&endPos, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
728 MPI_Send(&maxAmbig, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
729 MPI_Send(&maxHomoP, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
730 MPI_Send(&minLength, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
731 MPI_Send(&maxLength, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
734 MPI_Recv(&startPos, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
735 MPI_Recv(&endPos, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
736 MPI_Recv(&maxAmbig, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
737 MPI_Recv(&maxHomoP, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
738 MPI_Recv(&minLength, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
739 MPI_Recv(&maxLength, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
741 MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
745 catch(exception& e) {
746 m->errorOut(e, "ScreenSeqsCommand", "getSummary");
750 /**************************************************************************************/
751 int ScreenSeqsCommand::driverCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename, linePair* filePos) {
755 m->openInputFile(filename, in);
757 in.seekg(filePos->start);
764 if (m->control_pressed) { in.close(); return 1; }
766 Sequence current(in); m->gobble(in);
768 if (current.getName() != "") {
770 if (namefile != "") {
771 //make sure this sequence is in the namefile, else error
772 map<string, int>::iterator it = nameMap.find(current.getName());
774 if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
775 else { num = it->second; }
778 //for each sequence this sequence represents
779 for (int i = 0; i < num; i++) {
780 startPosition.push_back(current.getStartPos());
781 endPosition.push_back(current.getEndPos());
782 seqLength.push_back(current.getNumBases());
783 ambigBases.push_back(current.getAmbigBases());
784 longHomoPolymer.push_back(current.getLongHomoPolymer());
789 //if((count) % 100 == 0){ m->mothurOut("Optimizing sequence: " + toString(count)); m->mothurOutEndLine(); }
790 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
791 unsigned long long pos = in.tellg();
792 if ((pos == -1) || (pos >= filePos->end)) { break; }
794 if (in.eof()) { break; }
803 catch(exception& e) {
804 m->errorOut(e, "ScreenSeqsCommand", "driverCreateSummary");
808 /**************************************************************************************************/
809 int ScreenSeqsCommand::createProcessesCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename) {
811 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
816 //loop through and create all the processes you want
817 while (process != processors) {
821 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
824 num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[process]);
826 //pass numSeqs to parent
828 string tempFile = fastafile + toString(getpid()) + ".num.temp";
829 m->openOutputFile(tempFile, out);
832 out << startPosition.size() << endl;
833 for (int k = 0; k < startPosition.size(); k++) { out << startPosition[k] << '\t'; } out << endl;
834 for (int k = 0; k < endPosition.size(); k++) { out << endPosition[k] << '\t'; } out << endl;
835 for (int k = 0; k < seqLength.size(); k++) { out << seqLength[k] << '\t'; } out << endl;
836 for (int k = 0; k < ambigBases.size(); k++) { out << ambigBases[k] << '\t'; } out << endl;
837 for (int k = 0; k < longHomoPolymer.size(); k++) { out << longHomoPolymer[k] << '\t'; } out << endl;
843 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
844 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
849 num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
851 //force parent to wait until all the processes are done
852 for (int i=0;i<processIDS.size();i++) {
853 int temp = processIDS[i];
857 //parent reads in and combine Filter info
858 for (int i = 0; i < processIDS.size(); i++) {
859 string tempFilename = fastafile + toString(processIDS[i]) + ".num.temp";
861 m->openInputFile(tempFilename, in);
864 in >> tempNum; m->gobble(in); num += tempNum;
865 in >> tempNum; m->gobble(in);
866 for (int k = 0; k < tempNum; k++) { in >> temp; startPosition.push_back(temp); } m->gobble(in);
867 for (int k = 0; k < tempNum; k++) { in >> temp; endPosition.push_back(temp); } m->gobble(in);
868 for (int k = 0; k < tempNum; k++) { in >> temp; seqLength.push_back(temp); } m->gobble(in);
869 for (int k = 0; k < tempNum; k++) { in >> temp; ambigBases.push_back(temp); } m->gobble(in);
870 for (int k = 0; k < tempNum; k++) { in >> temp; longHomoPolymer.push_back(temp); } m->gobble(in);
873 m->mothurRemove(tempFilename);
879 catch(exception& e) {
880 m->errorOut(e, "ScreenSeqsCommand", "createProcessesCreateSummary");
885 //***************************************************************************************************************
887 int ScreenSeqsCommand::screenGroupFile(set<string> badSeqNames){
889 ifstream inputGroups;
890 m->openInputFile(groupfile, inputGroups);
891 string seqName, group;
892 set<string>::iterator it;
894 string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile);
895 outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile);
896 ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut);
898 while(!inputGroups.eof()){
899 if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); m->mothurRemove(goodGroupFile); return 0; }
901 inputGroups >> seqName >> group;
902 it = badSeqNames.find(seqName);
904 if(it != badSeqNames.end()){
905 badSeqNames.erase(it);
908 goodGroupOut << seqName << '\t' << group << endl;
910 m->gobble(inputGroups);
913 if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); m->mothurRemove(goodGroupFile); return 0; }
915 //we were unable to remove some of the bad sequences
916 if (badSeqNames.size() != 0) {
917 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
918 m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct.");
919 m->mothurOutEndLine();
924 goodGroupOut.close();
926 if (m->control_pressed) { m->mothurRemove(goodGroupFile); }
931 catch(exception& e) {
932 m->errorOut(e, "ScreenSeqsCommand", "screenGroupFile");
937 //***************************************************************************************************************
939 int ScreenSeqsCommand::screenAlignReport(set<string> badSeqNames){
941 ifstream inputAlignReport;
942 m->openInputFile(alignreport, inputAlignReport);
943 string seqName, group;
944 set<string>::iterator it;
946 string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + "good" + m->getExtension(alignreport);
947 outputNames.push_back(goodAlignReportFile); outputTypes["alignreport"].push_back(goodAlignReportFile);
948 ofstream goodAlignReportOut; m->openOutputFile(goodAlignReportFile, goodAlignReportOut);
950 while (!inputAlignReport.eof()) { // need to copy header
951 char c = inputAlignReport.get();
952 goodAlignReportOut << c;
953 if (c == 10 || c == 13){ break; }
956 while(!inputAlignReport.eof()){
957 if (m->control_pressed) { goodAlignReportOut.close(); inputAlignReport.close(); m->mothurRemove(goodAlignReportFile); return 0; }
959 inputAlignReport >> seqName;
960 it = badSeqNames.find(seqName);
962 while (!inputAlignReport.eof()) { // need to copy header
963 char c = inputAlignReport.get();
965 if (c == 10 || c == 13){ break; }
968 if(it != badSeqNames.end()){
969 badSeqNames.erase(it);
972 goodAlignReportOut << seqName << '\t' << line;
974 m->gobble(inputAlignReport);
977 if (m->control_pressed) { goodAlignReportOut.close(); inputAlignReport.close(); m->mothurRemove(goodAlignReportFile); return 0; }
979 //we were unable to remove some of the bad sequences
980 if (badSeqNames.size() != 0) {
981 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
982 m->mothurOut("Your alignreport file does not include the sequence " + *it + " please correct.");
983 m->mothurOutEndLine();
987 inputAlignReport.close();
988 goodAlignReportOut.close();
990 if (m->control_pressed) { m->mothurRemove(goodAlignReportFile); return 0; }
995 catch(exception& e) {
996 m->errorOut(e, "ScreenSeqsCommand", "screenAlignReport");
1001 //***************************************************************************************************************
1003 int ScreenSeqsCommand::screenTaxonomy(set<string> badSeqNames){
1006 m->openInputFile(taxonomy, input);
1007 string seqName, tax;
1008 set<string>::iterator it;
1010 string goodTaxFile = outputDir + m->getRootName(m->getSimpleName(taxonomy)) + "good" + m->getExtension(taxonomy);
1011 outputNames.push_back(goodTaxFile); outputTypes["taxonomy"].push_back(goodTaxFile);
1012 ofstream goodTaxOut; m->openOutputFile(goodTaxFile, goodTaxOut);
1014 while(!input.eof()){
1015 if (m->control_pressed) { goodTaxOut.close(); input.close(); m->mothurRemove(goodTaxFile); return 0; }
1017 input >> seqName >> tax;
1018 it = badSeqNames.find(seqName);
1020 if(it != badSeqNames.end()){ badSeqNames.erase(it); }
1022 goodTaxOut << seqName << '\t' << tax << endl;
1027 if (m->control_pressed) { goodTaxOut.close(); input.close(); m->mothurRemove(goodTaxFile); return 0; }
1029 //we were unable to remove some of the bad sequences
1030 if (badSeqNames.size() != 0) {
1031 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
1032 m->mothurOut("Your taxonomy file does not include the sequence " + *it + " please correct.");
1033 m->mothurOutEndLine();
1040 if (m->control_pressed) { m->mothurRemove(goodTaxFile); return 0; }
1045 catch(exception& e) {
1046 m->errorOut(e, "ScreenSeqsCommand", "screenTaxonomy");
1051 //***************************************************************************************************************
1053 int ScreenSeqsCommand::screenQual(set<string> badSeqNames){
1056 m->openInputFile(qualfile, in);
1057 set<string>::iterator it;
1059 string goodQualFile = outputDir + m->getRootName(m->getSimpleName(qualfile)) + "good" + m->getExtension(qualfile);
1060 outputNames.push_back(goodQualFile); outputTypes["qfile"].push_back(goodQualFile);
1061 ofstream goodQual; m->openOutputFile(goodQualFile, goodQual);
1065 if (m->control_pressed) { goodQual.close(); in.close(); m->mothurRemove(goodQualFile); return 0; }
1067 string saveName = "";
1073 if (name.length() != 0) {
1074 saveName = name.substr(1);
1077 if (c == 10 || c == 13){ break; }
1084 char letter= in.get();
1085 if(letter == '>'){ in.putback(letter); break; }
1086 else{ scores += letter; }
1091 it = badSeqNames.find(saveName);
1093 if(it != badSeqNames.end()){
1094 badSeqNames.erase(it);
1096 goodQual << name << endl << scores;
1105 //we were unable to remove some of the bad sequences
1106 if (badSeqNames.size() != 0) {
1107 for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
1108 m->mothurOut("Your qual file does not include the sequence " + *it + " please correct.");
1109 m->mothurOutEndLine();
1113 if (m->control_pressed) { m->mothurRemove(goodQualFile); return 0; }
1118 catch(exception& e) {
1119 m->errorOut(e, "ScreenSeqsCommand", "screenQual");
1124 //**********************************************************************************************************************
1126 int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badAccnosFName, string filename, set<string>& badSeqNames){
1129 m->openOutputFile(goodFName, goodFile);
1131 ofstream badAccnosFile;
1132 m->openOutputFile(badAccnosFName, badAccnosFile);
1135 m->openInputFile(filename, inFASTA);
1137 inFASTA.seekg(filePos->start);
1144 if (m->control_pressed) { return 0; }
1146 Sequence currSeq(inFASTA); m->gobble(inFASTA);
1147 if (currSeq.getName() != "") {
1148 bool goodSeq = 1; // innocent until proven guilty
1149 if(goodSeq == 1 && startPos != -1 && startPos < currSeq.getStartPos()) { goodSeq = 0; }
1150 if(goodSeq == 1 && endPos != -1 && endPos > currSeq.getEndPos()) { goodSeq = 0; }
1151 if(goodSeq == 1 && maxAmbig != -1 && maxAmbig < currSeq.getAmbigBases()) { goodSeq = 0; }
1152 if(goodSeq == 1 && maxHomoP != -1 && maxHomoP < currSeq.getLongHomoPolymer()) { goodSeq = 0; }
1153 if(goodSeq == 1 && minLength != -1 && minLength > currSeq.getNumBases()) { goodSeq = 0; }
1154 if(goodSeq == 1 && maxLength != -1 && maxLength < currSeq.getNumBases()) { goodSeq = 0; }
1157 currSeq.printSequence(goodFile);
1160 badAccnosFile << currSeq.getName() << endl;
1161 badSeqNames.insert(currSeq.getName());
1166 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
1167 unsigned long long pos = inFASTA.tellg();
1168 if ((pos == -1) || (pos >= filePos->end)) { break; }
1170 if (inFASTA.eof()) { break; }
1174 if((count) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); }
1177 if((count) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(count)); m->mothurOutEndLine(); }
1182 badAccnosFile.close();
1186 catch(exception& e) {
1187 m->errorOut(e, "ScreenSeqsCommand", "driver");
1191 //**********************************************************************************************************************
1193 int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& goodFile, MPI_File& badAccnosFile, vector<unsigned long long>& MPIPos, set<string>& badSeqNames){
1195 string outputString = "";
1196 MPI_Status statusGood;
1197 MPI_Status statusBadAccnos;
1200 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
1202 for(int i=0;i<num;i++){
1204 if (m->control_pressed) { return 0; }
1206 //read next sequence
1207 int length = MPIPos[start+i+1] - MPIPos[start+i];
1209 char* buf4 = new char[length];
1210 memcpy(buf4, outputString.c_str(), length);
1212 MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
1214 string tempBuf = buf4; delete buf4;
1215 if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
1216 istringstream iss (tempBuf,istringstream::in);
1218 Sequence currSeq(iss);
1221 if (currSeq.getName() != "") {
1222 bool goodSeq = 1; // innocent until proven guilty
1223 if(goodSeq == 1 && startPos != -1 && startPos < currSeq.getStartPos()) { goodSeq = 0; }
1224 if(goodSeq == 1 && endPos != -1 && endPos > currSeq.getEndPos()) { goodSeq = 0; }
1225 if(goodSeq == 1 && maxAmbig != -1 && maxAmbig < currSeq.getAmbigBases()) { goodSeq = 0; }
1226 if(goodSeq == 1 && maxHomoP != -1 && maxHomoP < currSeq.getLongHomoPolymer()) { goodSeq = 0; }
1227 if(goodSeq == 1 && minLength != -1 && minLength > currSeq.getNumBases()) { goodSeq = 0; }
1228 if(goodSeq == 1 && maxLength != -1 && maxLength < currSeq.getNumBases()) { goodSeq = 0; }
1231 outputString = ">" + currSeq.getName() + "\n" + currSeq.getAligned() + "\n";
1234 length = outputString.length();
1235 char* buf2 = new char[length];
1236 memcpy(buf2, outputString.c_str(), length);
1238 MPI_File_write_shared(goodFile, buf2, length, MPI_CHAR, &statusGood);
1243 badSeqNames.insert(currSeq.getName());
1245 //write to bad accnos file
1246 outputString = currSeq.getName() + "\n";
1248 length = outputString.length();
1249 char* buf3 = new char[length];
1250 memcpy(buf3, outputString.c_str(), length);
1252 MPI_File_write_shared(badAccnosFile, buf3, length, MPI_CHAR, &statusBadAccnos);
1258 if((i) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(i)); m->mothurOutEndLine(); }
1263 catch(exception& e) {
1264 m->errorOut(e, "ScreenSeqsCommand", "driverMPI");
1269 /**************************************************************************************************/
1271 int ScreenSeqsCommand::createProcesses(string goodFileName, string badAccnos, string filename, set<string>& badSeqNames) {
1273 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
1277 //loop through and create all the processes you want
1278 while (process != processors) {
1282 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
1284 }else if (pid == 0){
1285 num = driver(lines[process], goodFileName + toString(getpid()) + ".temp", badAccnos + toString(getpid()) + ".temp", filename, badSeqNames);
1287 //pass numSeqs to parent
1289 string tempFile = filename + toString(getpid()) + ".num.temp";
1290 m->openOutputFile(tempFile, out);
1296 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
1297 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
1302 //force parent to wait until all the processes are done
1303 for (int i=0;i<processors;i++) {
1304 int temp = processIDS[i];
1308 for (int i = 0; i < processIDS.size(); i++) {
1310 string tempFile = filename + toString(processIDS[i]) + ".num.temp";
1311 m->openInputFile(tempFile, in);
1312 if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
1313 in.close(); m->mothurRemove(tempFile);
1319 catch(exception& e) {
1320 m->errorOut(e, "ScreenSeqsCommand", "createProcesses");
1325 //***************************************************************************************************************