]> git.donarmstrong.com Git - mothur.git/blobdiff - subsamplecommand.cpp
added sequence name to error string in fastq.info. Changed np_shannon to npshannon.
[mothur.git] / subsamplecommand.cpp
index 28cfc3493e5b2ac6ac790445a4acaa397405b2ad..c352feb099a83879bae9e1aca0f35d5bfe56e691 100644 (file)
@@ -234,7 +234,7 @@ SubSampleCommand::SubSampleCommand(string option) {
                        }
                        
                        string temp = validParameter.validFile(parameters, "size", false);              if (temp == "not found"){       temp = "0";             }
-                       convert(temp, size);  
+                       m->mothurConvert(temp, size);  
                        
                        temp = validParameter.validFile(parameters, "persample", false);                if (temp == "not found"){       temp = "f";             }
                        persample = m->isTrue(temp);
@@ -255,6 +255,10 @@ SubSampleCommand::SubSampleCommand(string option) {
                        if ((groupfile != "") && ((fastafile != "") && (listfile != ""))) { 
                                m->mothurOut("A new group file can only be made from the subsample of a listfile or fastafile, not both. Please correct."); m->mothurOutEndLine(); abort = true; }
                        
+                       if ((fastafile != "") && (namefile == "")) {
+                               vector<string> files; files.push_back(fastafile);
+                               parser.getNameFile(files);
+                       }
                }
 
        }
@@ -426,6 +430,7 @@ int SubSampleCommand::getSubSampleFasta() {
                if (persample) {
                        //initialize counts
                        map<string, int> groupCounts;
+                       map<string, int>::iterator itGroupCounts;
                        for (int i = 0; i < Groups.size(); i++) { groupCounts[Groups[i]] = 0; }
                        
                        for (int j = 0; j < names.size(); j++) {
@@ -435,7 +440,10 @@ int SubSampleCommand::getSubSampleFasta() {
                                string group = groupMap->getGroup(names[j]);
                                if (group == "not found") { m->mothurOut("[ERROR]: " + names[j] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
                                else{
-                                       if (groupCounts[group] < size) {        subset.insert(names[j]);        }
+                                       itGroupCounts = groupCounts.find(group);
+                                       if (itGroupCounts != groupCounts.end()) {
+                                               if (groupCounts[group] < size) {        subset.insert(names[j]);        groupCounts[group]++; }
+                                       }
                                }                               
                        }
                }else {
@@ -1025,6 +1033,7 @@ int SubSampleCommand::getSubSampleList() {
                if (persample) {
                        //initialize counts
                        map<string, int> groupCounts;
+                       map<string, int>::iterator itGroupCounts;
                        for (int i = 0; i < Groups.size(); i++) { groupCounts[Groups[i]] = 0; }
                        
                        for (int j = 0; j < names.size(); j++) {
@@ -1034,7 +1043,10 @@ int SubSampleCommand::getSubSampleList() {
                                string group = groupMap->getGroup(names[j]);
                                if (group == "not found") { m->mothurOut("[ERROR]: " + names[j] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
                                else{
-                                       if (groupCounts[group] < size) {        subset.insert(names[j]);        }
+                                       itGroupCounts = groupCounts.find(group);
+                                       if (itGroupCounts != groupCounts.end()) {
+                                               if (groupCounts[group] < size) {        subset.insert(names[j]);        groupCounts[group]++; }
+                                       }
                                }                               
                        }
                }else{
@@ -1522,6 +1534,7 @@ int SubSampleCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup)
                
                //for each bin
                vector<string> newBinLabels;
+               string snumBins = toString(thislookup[0]->getNumBins());
                for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
                        if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) {  delete newLookup[j];  } return 0; }
                        
@@ -1537,7 +1550,13 @@ int SubSampleCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup)
                                        newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
                                }
                                //if there is a bin label use it otherwise make one
-                               string binLabel = "Otu" + toString(i+1);
+                               string binLabel = "Otu";
+                               string sbinNumber = toString(i+1);
+                               if (sbinNumber.length() < snumBins.length()) { 
+                                       int diff = snumBins.length() - sbinNumber.length();
+                                       for (int h = 0; h < diff; h++) { binLabel += "0"; }
+                               }
+                               binLabel += sbinNumber; 
                                if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
                                
                                newBinLabels.push_back(binLabel);