]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed trim.seqs group counts by adding back in the primer group
authorwestcott <westcott>
Tue, 22 Mar 2011 13:23:30 +0000 (13:23 +0000)
committerwestcott <westcott>
Tue, 22 Mar 2011 13:23:30 +0000 (13:23 +0000)
trimseqscommand.cpp
trimseqscommand.h

index 0e0ed587343e1a02288f7a49b9af18c8dcf846c5..0734a887837e547be9978619b4b6f3923c33f905 100644 (file)
@@ -405,13 +405,13 @@ int TrimSeqsCommand::execute(){
 
                //output group counts
                m->mothurOutEndLine();
-               //int total = 0;
-//             for (int i = 0; i < barcodeNameVector.size(); i++) {
-//                     if ((barcodeNameVector[i] != "") && (groupCounts[i] != 0)) { total += groupCounts[i]; m->mothurOut("Group " + barcodeNameVector[i] + " contains " + toString(groupCounts[i]) + " sequences."); m->mothurOutEndLine(); }
-//             }
-//             if (total != 0) { m->mothurOut("Total of all groups is " + toString(total)); m->mothurOutEndLine(); }
+               int total = 0;
+               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(); 
+               }
+               if (total != 0) { m->mothurOut("Total of all groups is " + toString(total)); m->mothurOutEndLine(); }
                
-                       if (m->control_pressed) {       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } return 0;     }
+               if (m->control_pressed) {       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str()); } return 0;     }
 
                //set fasta file as new current fastafile
                string current = "";
@@ -596,8 +596,15 @@ int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string
                                        }
                                        
                                        if(barcodes.size() != 0){
-                                               outGroupsFile << currSeq.getName() << '\t' << barcodeNameVector[barcodeIndex] << endl;
-                                               groupCounts[barcodeIndex]++;
+                                               string thisGroup = barcodeNameVector[barcodeIndex];
+                                               if (primers.size() != 0) { thisGroup += "." + primerNameVector[primerIndex]; }
+                                               
+                                               outGroupsFile << currSeq.getName() << '\t' << thisGroup << endl;
+                                               
+                                               map<string, int>::iterator it = groupCounts.find(thisGroup);
+                                               if (it == groupCounts.end()) {  groupCounts[thisGroup] = 1; }
+                                               else { groupCounts[it->first]++; }
+                                                       
                                        }
                                        
                                        
@@ -710,8 +717,8 @@ int TrimSeqsCommand::createProcessesCreateTrim(string filename, string qFileName
                                ofstream out;
                                string tempFile = filename + toString(getpid()) + ".num.temp";
                                m->openOutputFile(tempFile, out);
-                               for(int i = 0; i < groupCounts.size(); i++) {
-                                       out << groupCounts[i] << endl;
+                               for (map<string, int>::iterator it = groupCounts.begin(); it != groupCounts.end(); it++) {
+                                       out << it->first << '\t' << it->second << endl;
                                }
                                out.close();
                                
@@ -778,12 +785,14 @@ int TrimSeqsCommand::createProcessesCreateTrim(string filename, string qFileName
                        ifstream in;
                        string tempFile =  filename + toString(processIDS[i]) + ".num.temp";
                        m->openInputFile(tempFile, in);
-                       int count = 0; 
                        int tempNum;
+                       string group;
                        while (!in.eof()) { 
-                               in >> tempNum; m->gobble(in);
-                               groupCounts[count] += tempNum; 
-                               count++;
+                               in >> group >> tempNum; m->gobble(in);
+                               
+                               map<string, int>::iterator it = groupCounts.find(group);
+                               if (it == groupCounts.end()) {  groupCounts[group] = tempNum; }
+                               else { groupCounts[it->first] += tempNum; }
                        }
                        in.close(); remove(tempFile.c_str());
                        
@@ -1022,7 +1031,6 @@ void TrimSeqsCommand::getOligos(vector<vector<string> >& fastaFileNames, vector<
                }
                numFPrimers = primers.size();
                numRPrimers = revPrimer.size();
-               groupCounts.resize(barcodeNameVector.size(), 0);
 
        }
        catch(exception& e) {
index c5cbd3da1b0044467e8558a5619dc651434bcffe..d40cfe3c5604d66009ba22b568b0df71f3688faa 100644 (file)
@@ -69,7 +69,7 @@ private:
        map<string, int> groupToIndex;
        vector<string> primerNameVector;        //needed here?
        vector<string> barcodeNameVector;       //needed here?
-       vector<int> groupCounts;  //same order as barcodeNameVector
+       map<string, int> groupCounts;  
 
        vector<int> processIDS;   //processid
        vector<linePair*> lines;