+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+ ifstream inFASTA;
+ int numSeqs;
+ openInputFile(fastaFile, inFASTA);
+ getNumSeqs(inFASTA, numSeqs);
+ inFASTA.close();
+
+ lines.push_back(new linePair(0, numSeqs));
+
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], lines[0]);
+
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(getpid()) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+ if(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ rename((qualFileNames[j] + toString(getpid()) + ".temp").c_str(), qualFileNames[j].c_str());
+ }
+ }
+
+ }else{
+ setLines(fastaFile, lines);
+ if(qFileName == "") { qLines = lines; }
+
+ createProcessesCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames);
+
+ 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());
+
+ if(qFileName != ""){
+ rename((trimQualFile + toString(processIDS[0]) + ".temp").c_str(), trimQualFile.c_str());
+ rename((scrapQualFile + toString(processIDS[0]) + ".temp").c_str(), scrapQualFile.c_str());
+ }
+
+
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(processIDS[0]) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+ if(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ rename((qualFileNames[j] + toString(getpid()) + ".temp").c_str(), qualFileNames[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((trimQualFile + toString(processIDS[i]) + ".temp"), trimQualFile);
+ remove((trimQualFile + toString(processIDS[i]) + ".temp").c_str());
+ appendFiles((scrapQualFile + toString(processIDS[i]) + ".temp"), scrapQualFile);
+ remove((scrapQualFile + 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(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ appendFiles((qualFileNames[j] + toString(processIDS[i]) + ".temp"), qualFileNames[j]);
+ remove((qualFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
+ }
+ }
+
+
+ }
+ }
+
+ if (m->control_pressed) { return 0; }
+ #else
+ ifstream inFASTA;
+ int numSeqs;
+ openInputFile(fastaFile, inFASTA);
+ getNumSeqs(inFASTA, numSeqs);
+ inFASTA.close();
+ qFile.close();
+ lines.push_back(new linePair(0, numSeqs));
+
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], lines[0]);
+
+ if (m->control_pressed) { return 0; }
+ #endif
+
+
+ for(int i=0;i<fastaFileNames.size();i++){
+ if (isBlank(fastaFileNames[i])) { remove(fastaFileNames[i].c_str()); }
+ else if (filesToRemove.count(fastaFileNames[i]) > 0) { remove(fastaFileNames[i].c_str()); }
+ else {
+ ifstream inFASTA;
+ string seqName;
+ openInputFile(fastaFileNames[i], inFASTA);
+ ofstream outGroups;
+ string outGroupFilename = outputDir + getRootName(getSimpleName(fastaFileNames[i])) + "groups";
+ openOutputFile(outGroupFilename, outGroups);
+ outputNames.push_back(outGroupFilename);
+
+ string thisGroup = "";
+ if (i > comboStarts) {
+ map<string, int>::iterator itCombo;
+ for(itCombo=combos.begin();itCombo!=combos.end(); itCombo++){
+ if(itCombo->second == i){ thisGroup = itCombo->first; combos.erase(itCombo); break; }
+ }
+ }else{ thisGroup = groupVector[i]; }
+
+ while(!inFASTA.eof()){
+ if(inFASTA.get() == '>'){
+ inFASTA >> seqName;
+ outGroups << seqName << '\t' << thisGroup << endl;
+ }
+ while (!inFASTA.eof()) { char c = inFASTA.get(); if (c == 10 || c == 13){ break; } }
+ }
+ outGroups.close();
+ inFASTA.close();
+ }
+ }
+
+ if(qFileName != ""){
+ for(int i=0;i<qualFileNames.size();i++){
+ if (isBlank(qualFileNames[i])) { remove(qualFileNames[i].c_str()); }
+ else if (filesToRemove.count(qualFileNames[i]) > 0) { remove(qualFileNames[i].c_str()); }
+ else {
+ ifstream inQual;
+ string seqName;
+ openInputFile(qualFileNames[i], inQual);
+// ofstream outGroups;
+//
+// string thisGroup = "";
+// if (i > comboStarts) {
+// map<string, int>::iterator itCombo;
+// for(itCombo=combos.begin();itCombo!=combos.end(); itCombo++){
+// if(itCombo->second == i){ thisGroup = itCombo->first; combos.erase(itCombo); break; }
+// }
+// }
+// else{ thisGroup = groupVector[i]; }
+
+ inQual.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 trimQFile, string scrapQFile, string groupFile, vector<string> fastaNames, vector<string> qualNames, linePair* line, linePair* qline) {
+
+ try {