]> git.donarmstrong.com Git - mothur.git/blobdiff - trimseqscommand.cpp
paralellized seq.error and dist.shared added some error checks to libshuff and dist...
[mothur.git] / trimseqscommand.cpp
index dad8b98b64f99026388b32c7d47e60dab33e1fba..dc87fff99489ebe9ebfc29bec6ff2328875d7030 100644 (file)
@@ -240,7 +240,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option)  {
                        
                        temp = validParameter.validFile(parameters, "name", true);      
                        if (temp == "not found")        {       nameFile = "";          }
-                       else if(temp == "not open")     {       abort = true;           }
+                       else if(temp == "not open")     {       nameFile = "";  abort = true;           }
                        else                                            {       nameFile = temp;        }
                        
                        temp = validParameter.validFile(parameters, "qthreshold", false);       if (temp == "not found") { temp = "0"; }
@@ -369,7 +369,7 @@ int TrimSeqsCommand::execute(){
                #endif
                
                if (m->control_pressed) {  return 0; }                  
-       
+       
                if(allFiles){
                        map<string, string> uniqueFastaNames;// so we don't add the same groupfile multiple times
                        map<string, string>::iterator it;
@@ -432,8 +432,9 @@ int TrimSeqsCommand::execute(){
                //output group counts
                m->mothurOutEndLine();
                int total = 0;
+               if (groupCounts.size() != 0) {  m->mothurOut("Group count: \n");  }
                for (map<string, int>::iterator it = groupCounts.begin(); it != groupCounts.end(); it++) {
-                        total += it->second; m->mothurOut("Group " + it->first + " contains " + toString(it->second) + " sequences."); m->mothurOutEndLine(); 
+                        total += it->second; m->mothurOut(it->first + "\t" + toString(it->second)); m->mothurOutEndLine(); 
                }
                if (total != 0) { m->mothurOut("Total of all groups is " + toString(total)); m->mothurOutEndLine(); }
                
@@ -650,6 +651,17 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string
                                                
                                                outGroupsFile << currSeq.getName() << '\t' << thisGroup << endl;
                                                
+                                               if (nameFile != "") {
+                                                       map<string, string>::iterator itName = nameMap.find(currSeq.getName());
+                                                       if (itName != nameMap.end()) { 
+                                                               vector<string> thisSeqsNames; 
+                                                               m->splitAtChar(itName->second, thisSeqsNames, ',');
+                                                               for (int k = 1; k < thisSeqsNames.size(); k++) { //start at 1 to skip self
+                                                                       outGroupsFile << thisSeqsNames[k] << '\t' << thisGroup << endl;
+                                                               }
+                                                       }else { m->mothurOut("[ERROR]: " + currSeq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); }                                                   
+                                               }
+                                               
                                                map<string, int>::iterator it = groupCounts.find(thisGroup);
                                                if (it == groupCounts.end()) {  groupCounts[thisGroup] = 1; }
                                                else { groupCounts[it->first]++; }
@@ -680,6 +692,11 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string
                                        }
                                }
                                else{
+                                       if(nameFile != ""){ //needs to be before the currSeq name is changed
+                                               map<string, string>::iterator itName = nameMap.find(currSeq.getName());
+                                               if (itName != nameMap.end()) {  scrapNameFile << itName->first << '\t' << itName->second << endl; }
+                                               else { m->mothurOut("[ERROR]: " + currSeq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); }
+                                       }
                                        currSeq.setName(currSeq.getName() + '|' + trashCode);
                                        currSeq.setUnaligned(origSeq);
                                        currSeq.setAligned(origSeq);
@@ -687,11 +704,6 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string
                                        if(qFileName != ""){
                                                currQual.printQScores(scrapQualFile);
                                        }
-                                       if(nameFile != ""){
-                                               map<string, string>::iterator itName = nameMap.find(currSeq.getName());
-                                               if (itName != nameMap.end()) {  scrapNameFile << itName->first << '\t' << itName->second << endl; }
-                                                       else { m->mothurOut("[ERROR]: " + currSeq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); }
-                                       }
                                }
                                count++;
                        }
@@ -806,10 +818,14 @@ int TrimSeqsCommand::createProcessesCreateTrim(string filename, string qFileName
                ofstream temp;
                m->openOutputFile(trimFASTAFileName, temp);             temp.close();
                m->openOutputFile(scrapFASTAFileName, temp);    temp.close();
-               m->openOutputFile(trimQualFileName, temp);              temp.close();
-               m->openOutputFile(scrapQualFileName, temp);             temp.close();
-               m->openOutputFile(trimNameFileName, temp);              temp.close();
-               m->openOutputFile(scrapNameFileName, temp);             temp.close();
+               if(qFileName != ""){
+                       m->openOutputFile(trimQualFileName, temp);              temp.close();
+                       m->openOutputFile(scrapQualFileName, temp);             temp.close();
+               }
+               if (nameFile != "") {
+                       m->openOutputFile(trimNameFileName, temp);              temp.close();
+                       m->openOutputFile(scrapNameFileName, temp);             temp.close();
+               }
 
                driverCreateTrim(filename, qFileName, trimFASTAFileName, scrapFASTAFileName, trimQualFileName, scrapQualFileName, trimNameFileName, scrapNameFileName, groupFile, fastaFileNames, qualFileNames, nameFileNames, lines[0], qLines[0]);
                
@@ -1143,7 +1159,7 @@ void TrimSeqsCommand::getOligos(vector<vector<string> >& fastaFileNames, vector<
                                        
                                        if(qFileName != ""){
                                                qualFileName = outputDir + m->getRootName(m->getSimpleName(qFileName)) + comboGroupName + ".qual";
-                                               if (uniqueNames.count(fastaFileName) == 0) {
+                                               if (uniqueNames.count(qualFileName) == 0) {
                                                        outputNames.push_back(qualFileName);
                                                        outputTypes["qfile"].push_back(qualFileName);
                                                }
@@ -1154,7 +1170,7 @@ void TrimSeqsCommand::getOligos(vector<vector<string> >& fastaFileNames, vector<
                                        
                                        if(nameFile != ""){
                                                nameFileName = outputDir + m->getRootName(m->getSimpleName(nameFile)) + comboGroupName + ".names";
-                                               if (uniqueNames.count(fastaFileName) == 0) {
+                                               if (uniqueNames.count(nameFileName) == 0) {
                                                        outputNames.push_back(nameFileName);
                                                        outputTypes["name"].push_back(nameFileName);
                                                }