]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedrabundfloatvector.cpp
changed normalize.shared and sub.sample commands to fix bug in normalize.shared and...
[mothur.git] / sharedrabundfloatvector.cpp
index e7ab22565431d61a34d875322663ac107c9e21af..8d91d7ede187510f66b63b25c7488ce822aba966 100644 (file)
@@ -50,12 +50,33 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma
                        
                        //is this a shared file that has headers
                        if (label == "label") { 
+                               //gets "group"
+                               f >> label; m->gobble(f);
+                               
+                               //gets "numOtus"
+                               f >> label; m->gobble(f);
+                               
                                //eat rest of line
                                label = m->getline(f); m->gobble(f);
+                               
+                               //parse labels to save
+                               istringstream iStringStream(label);
+                               m->binLabelsInFile.clear();
+                               while(!iStringStream.eof()){
+                                       if (m->control_pressed) { break; }
+                                       string temp;
+                                       iStringStream >> temp;  m->gobble(iStringStream);
+                                       
+                                       m->binLabelsInFile.push_back(temp);
+                               }
+                               
                                f >> label;
                        }
                }else { label = m->saveNextLabel; }
                
+               //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling
+               m->currentBinLabels = m-> binLabelsInFile;
+               
                //read in first row since you know there is at least 1 group.
                f >> groupN >> num;
 
@@ -231,12 +252,27 @@ void SharedRAbundFloatVector::printHeaders(ostream& output){
        try {
                output << "label\tGroup\tnumOtus\t";
                if (m->sharedHeaderMode == "tax") {
-                       for (int i = 0; i < numBins; i++) {  output << "PhyloType" << (i+1) << '\t'; }
+                       for (int i = 0; i < numBins; i++) {  
+                               
+                               //if there is a bin label use it otherwise make one
+                               string binLabel = "PhyloType" + toString(i+1);
+                               if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
+                               
+                               output << binLabel << '\t'; 
+                       }
                        output << endl;
                }else {
-                       for (int i = 0; i < numBins; i++) {  output << "Otu" << (i+1) << '\t'; }
+                       for (int i = 0; i < numBins; i++) {  
+                               //if there is a bin label use it otherwise make one
+                               string binLabel = "Otu" + toString(i+1);
+                               if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
+                               
+                               output << binLabel << '\t'; 
+                       }
+                       
                        output << endl;
                }
+               
                m->printedHeaders = true;
        }
        catch(exception& e) {
@@ -442,6 +478,7 @@ int SharedRAbundFloatVector::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>&
                }
                
                //for each bin
+               vector<string> newBinLabels;
                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; }
                        
@@ -456,12 +493,18 @@ int SharedRAbundFloatVector::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>&
                                for (int j = 0; j < thislookup.size(); j++) {
                                        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" + (i+1);
+                               if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
+                               
+                               newBinLabels.push_back(binLabel);
                        }
                }
                
                for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
                
                thislookup = newLookup;
+               m->currentBinLabels = newBinLabels;
                
                return 0;