X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedrabundfloatvector.cpp;h=8d91d7ede187510f66b63b25c7488ce822aba966;hb=1bf53bca7e26bf091588bc8ca6e68cbfae1df6fe;hp=e7ab22565431d61a34d875322663ac107c9e21af;hpb=19fcbbdba99658f5eca244803280f9ee7f9f6607;p=mothur.git diff --git a/sharedrabundfloatvector.cpp b/sharedrabundfloatvector.cpp index e7ab225..8d91d7e 100644 --- a/sharedrabundfloatvector.cpp +++ b/sharedrabundfloatvector.cpp @@ -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& } //for each bin + vector 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& 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;