+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+ ifstream inFASTA;
+ openInputFile(fastaFile, inFASTA);
+ int numSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ inFASTA.close();
+
+ lines.push_back(new linePair(0, numSeqs));
+
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, groupFile, fastaFileNames, lines[0], lines[0]);
+
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(getpid()) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+
+ }else{
+ setLines(fastaFile, lines);
+ if(qFileName == "") { qLines = lines; }
+
+ createProcessesCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, groupFile, fastaFileNames);
+
+ rename((trimSeqFile + toString(processIDS[0]) + ".temp").c_str(), trimSeqFile.c_str());
+ rename((scrapSeqFile + toString(processIDS[0]) + ".temp").c_str(), scrapSeqFile.c_str());
+ rename((groupFile + toString(processIDS[0]) + ".temp").c_str(), groupFile.c_str());
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(processIDS[0]) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+ //append files
+ for(int i=1;i<processors;i++){
+ appendFiles((trimSeqFile + toString(processIDS[i]) + ".temp"), trimSeqFile);
+ remove((trimSeqFile + toString(processIDS[i]) + ".temp").c_str());
+ appendFiles((scrapSeqFile + toString(processIDS[i]) + ".temp"), scrapSeqFile);
+ remove((scrapSeqFile + toString(processIDS[i]) + ".temp").c_str());
+ appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile);
+ remove((groupFile + toString(processIDS[i]) + ".temp").c_str());
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ appendFiles((fastaFileNames[j] + toString(processIDS[i]) + ".temp"), fastaFileNames[j]);
+ remove((fastaFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
+ }
+ }
+ }
+
+ if (m->control_pressed) { return 0; }
+ #else
+ ifstream inFASTA;
+ openInputFile(fastaFile, inFASTA);
+ int numSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ inFASTA.close();
+
+ lines.push_back(new linePair(0, numSeqs));
+
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, groupFile, fastaFileNames, lines[0], lines[0]);
+
+ if (m->control_pressed) { return 0; }
+ #endif
+
+
+ for(int i=0;i<fastaFileNames.size();i++){
+ ifstream inFASTA;
+ string seqName;
+ openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA);
+ ofstream outGroups;
+ openOutputFile(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups", outGroups);
+ outputNames.push_back(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups");
+
+ while(!inFASTA.eof()){
+ if(inFASTA.get() == '>'){
+ inFASTA >> seqName;
+ outGroups << seqName << '\t' << groupVector[i] << endl;
+ }
+ while (!inFASTA.eof()) { char c = inFASTA.get(); if (c == 10 || c == 13){ break; } }
+ }
+ outGroups.close();
+ inFASTA.close();
+ }
+
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;
+ }
+
+ m->mothurOutEndLine();
+ m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOutEndLine();
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "TrimSeqsCommand", "execute");
+ exit(1);
+ }
+}
+
+/**************************************************************************************/
+int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string trimFile, string scrapFile, string groupFile, vector<string> fastaNames, linePair* line, linePair* qline) {
+ try {