+int SeqErrorCommand::createProcesses(string filename, string qFileName, string rFileName, string summaryFileName, string errorOutputFileName, string chimeraOutputFileName) {
+ try {
+ int process = 1;
+ processIDS.clear();
+ map<char, vector<int> >::iterator it;
+ int num = 0;
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+
+ //loop through and create all the processes you want
+ while (process != processors) {
+ int pid = fork();
+
+ if (pid > 0) {
+ processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
+ process++;
+ }else if (pid == 0){
+
+ num = driver(filename, qFileName, rFileName, summaryFileName + toString(getpid()) + ".temp", errorOutputFileName+ toString(getpid()) + ".temp", chimeraOutputFileName + toString(getpid()) + ".temp", lines[process], qLines[process], rLines[process]);
+
+ //pass groupCounts to parent
+ ofstream out;
+ string tempFile = filename + toString(getpid()) + ".info.temp";
+ m->openOutputFile(tempFile, out);
+
+ //output totalBases and totalMatches
+ out << num << '\t' << totalBases << '\t' << totalMatches << endl << endl;
+
+ //output substitutionMatrix
+ for(int i = 0; i < substitutionMatrix.size(); i++) {
+ for (int j = 0; j < substitutionMatrix[i].size(); j++) {
+ out << substitutionMatrix[i][j] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output qScoreErrorMap
+ for (it = qScoreErrorMap.begin(); it != qScoreErrorMap.end(); it++) {
+ vector<int> thisScoreErrorMap = it->second;
+ out << it->first << '\t';
+ for (int i = 0; i < thisScoreErrorMap.size(); i++) {
+ out << thisScoreErrorMap[i] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output qualForwardMap
+ for(int i = 0; i < qualForwardMap.size(); i++) {
+ for (int j = 0; j < qualForwardMap[i].size(); j++) {
+ out << qualForwardMap[i][j] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output qualReverseMap
+ for(int i = 0; i < qualReverseMap.size(); i++) {
+ for (int j = 0; j < qualReverseMap[i].size(); j++) {
+ out << qualReverseMap[i][j] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+
+ //output errorForward
+ for (it = errorForward.begin(); it != errorForward.end(); it++) {
+ vector<int> thisErrorForward = it->second;
+ out << it->first << '\t';
+ for (int i = 0; i < thisErrorForward.size(); i++) {
+ out << thisErrorForward[i] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output errorReverse
+ for (it = errorReverse.begin(); it != errorReverse.end(); it++) {
+ vector<int> thisErrorReverse = it->second;
+ out << it->first << '\t';
+ for (int i = 0; i < thisErrorReverse.size(); i++) {
+ out << thisErrorReverse[i] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output misMatchCounts
+ out << misMatchCounts.size() << endl;
+ for (int j = 0; j < misMatchCounts.size(); j++) {
+ out << misMatchCounts[j] << '\t';
+ }
+ out << endl;
+
+
+ //output megaAlignVector
+ for (int j = 0; j < megaAlignVector.size(); j++) {
+ out << megaAlignVector[j] << endl;
+ }
+ out << endl;
+
+ out.close();
+
+ exit(0);
+ }else {
+ m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
+ for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
+ exit(0);
+ }
+ }
+
+ //do my part
+ num = driver(filename, qFileName, rFileName, summaryFileName, errorOutputFileName, chimeraOutputFileName, lines[0], qLines[0], rLines[0]);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<processIDS.size();i++) {
+ int temp = processIDS[i];
+ wait(&temp);
+ }
+
+ //append files
+ for(int i=0;i<processIDS.size();i++){
+
+ m->mothurOut("Appending files from process " + toString(processIDS[i])); m->mothurOutEndLine();
+
+ m->appendFiles((summaryFileName + toString(processIDS[i]) + ".temp"), summaryFileName);
+ m->mothurRemove((summaryFileName + toString(processIDS[i]) + ".temp"));
+ m->appendFiles((errorOutputFileName + toString(processIDS[i]) + ".temp"), errorOutputFileName);
+ m->mothurRemove((errorOutputFileName + toString(processIDS[i]) + ".temp"));
+ m->appendFiles((chimeraOutputFileName + toString(processIDS[i]) + ".temp"), chimeraOutputFileName);
+ m->mothurRemove((chimeraOutputFileName + toString(processIDS[i]) + ".temp"));
+
+ ifstream in;
+ string tempFile = filename + toString(processIDS[i]) + ".info.temp";
+ m->openInputFile(tempFile, in);
+
+ //input totalBases and totalMatches
+ int tempBases, tempMatches, tempNumSeqs;
+ in >> tempNumSeqs >> tempBases >> tempMatches; m->gobble(in);
+ totalBases += tempBases; totalMatches += tempMatches; num += tempNumSeqs;
+
+ //input substitutionMatrix
+ int tempNum;
+ for(int i = 0; i < substitutionMatrix.size(); i++) {
+ for (int j = 0; j < substitutionMatrix[i].size(); j++) {
+ in >> tempNum; substitutionMatrix[i][j] += tempNum;
+ }
+ m->gobble(in);
+ }
+ m->gobble(in);
+
+ //input qScoreErrorMap
+ char first;
+ for (int i = 0; i < qScoreErrorMap.size(); i++) {
+ in >> first;
+ vector<int> thisScoreErrorMap = qScoreErrorMap[first];
+
+ for (int i = 0; i < thisScoreErrorMap.size(); i++) {
+ in >> tempNum; thisScoreErrorMap[i] += tempNum;
+ }
+ qScoreErrorMap[first] = thisScoreErrorMap;
+ m->gobble(in);
+ }
+ m->gobble(in);
+
+ //input qualForwardMap
+ for(int i = 0; i < qualForwardMap.size(); i++) {
+ for (int j = 0; j < qualForwardMap[i].size(); j++) {
+ in >> tempNum; qualForwardMap[i][j] += tempNum;
+ }
+ m->gobble(in);
+ }
+ m->gobble(in);
+
+ //input qualReverseMap
+ for(int i = 0; i < qualReverseMap.size(); i++) {
+ for (int j = 0; j < qualReverseMap[i].size(); j++) {
+ in >> tempNum; qualReverseMap[i][j] += tempNum;
+ }
+ m->gobble(in);
+ }
+ m->gobble(in);
+
+ //input errorForward
+ for (int i = 0; i < errorForward.size(); i++) {
+ in >> first;
+ vector<int> thisErrorForward = errorForward[first];
+
+ for (int i = 0; i < thisErrorForward.size(); i++) {
+ in >> tempNum; thisErrorForward[i] += tempNum;
+ }
+ errorForward[first] = thisErrorForward;
+ m->gobble(in);
+ }
+ m->gobble(in);
+
+ //input errorReverse
+ for (int i = 0; i < errorReverse.size(); i++) {
+ in >> first;
+ vector<int> thisErrorReverse = errorReverse[first];
+
+ for (int i = 0; i < thisErrorReverse.size(); i++) {
+ in >> tempNum; thisErrorReverse[i] += tempNum;
+ }
+ errorReverse[first] = thisErrorReverse;
+ m->gobble(in);
+ }
+ m->gobble(in);
+
+ //input misMatchCounts
+ int misMatchSize;
+ in >> misMatchSize; m->gobble(in);
+ if (misMatchSize > misMatchCounts.size()) { misMatchCounts.resize(misMatchSize, 0); }
+ for (int j = 0; j < misMatchSize; j++) {
+ in >> tempNum; misMatchCounts[j] += tempNum;
+ }
+ m->gobble(in);
+
+ //input megaAlignVector
+ string thisLine;
+ for (int j = 0; j < megaAlignVector.size(); j++) {
+ thisLine = m->getline(in); m->gobble(in); megaAlignVector[j] += thisLine + '\n';
+ }
+ m->gobble(in);
+
+ in.close(); m->mothurRemove(tempFile);
+
+ }
+#endif
+ return num;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SeqErrorCommand", "createProcesses");
+ exit(1);
+ }