X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedlistvector.cpp;fp=sharedlistvector.cpp;h=8fabc5b605b40f06ea1e7217a766f36bc8bfded9;hb=499f4ac6e321f9f03d4c3aa25c3b6880892c8b83;hp=2ce250ba908b4b45fa200b845275af22c3ca3be6;hpb=a935b75dd890da5ae7f09e5e6179f90ab2955348;p=mothur.git diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 2ce250b..8fabc5b 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -35,16 +35,70 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB countTable->readTable(m->getCountTableFile(), true, false); } - int hold; - string inputData; - f >> label >> hold; - - data.assign(hold, ""); + int hold; + + //are we at the beginning of the file?? + if (m->saveNextLabel == "") { + f >> label; + + //is this a shared file that has headers + if (label == "label") { + + //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->listBinLabelsInFile.clear(); + while(!iStringStream.eof()){ + if (m->control_pressed) { break; } + string temp; + iStringStream >> temp; m->gobble(iStringStream); + + m->listBinLabelsInFile.push_back(temp); + } + + f >> label >> hold; + }else { + //read in first row + f >> hold; + + //make binlabels because we don't have any + string snumBins = toString(hold); + m->listBinLabelsInFile.clear(); + for (int i = 0; i < hold; i++) { + //if there is a bin label use it otherwise make one + 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; + m->listBinLabelsInFile.push_back(binLabel); + } + } + m->saveNextLabel = label; + }else { + f >> label >> hold; + m->saveNextLabel = label; + } + + binLabels.assign(m->listBinLabelsInFile.begin(), m->listBinLabelsInFile.begin()+hold); + data.assign(hold, ""); + string inputData = ""; + for(int i=0;i> inputData; set(i, inputData); } + m->gobble(f); + + if (f.eof()) { m->saveNextLabel = ""; } } catch(exception& e) { @@ -79,7 +133,59 @@ void SharedListVector::set(int binNumber, string seqNames){ string SharedListVector::get(int index){ return data[index]; } +/***********************************************************************/ + +void SharedListVector::setLabels(vector labels){ + try { + binLabels = labels; + } + catch(exception& e) { + m->errorOut(e, "SharedListVector", "setLabels"); + exit(1); + } +} +/***********************************************************************/ +//could potentially end up with duplicate binlabel names with code below. +//we don't currently use them in a way that would do that. +//if you had a listfile that had been subsampled and then added to it, dup names would be possible. +vector SharedListVector::getLabels(){ + try { + string tagHeader = "Otu"; + if (m->sharedHeaderMode == "tax") { tagHeader = "PhyloType"; } + + if (binLabels.size() < data.size()) { + string snumBins = toString(numBins); + + for (int i = 0; i < numBins; i++) { + string binLabel = tagHeader; + + if (i < binLabels.size()) { //label exists, check leading zeros length + string sbinNumber = m->getSimpleLabel(binLabels[i]); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + binLabels[i] = binLabel; + }else{ + 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; + binLabels.push_back(binLabel); + } + } + } + return binLabels; + } + catch(exception& e) { + m->errorOut(e, "SharedListVector", "getLabels"); + exit(1); + } +} /***********************************************************************/ void SharedListVector::push_back(string seqNames){ @@ -237,6 +343,8 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ /***********************************************************************/ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { try { + m->currentSharedBinLabels = binLabels; + SharedRAbundVector rav(data.size()); for(int i=0;i SharedListVector::getSharedRAbundVector() { try { + m->currentSharedBinLabels = binLabels; + SharedUtil* util; util = new SharedUtil(); vector lookup; //contains just the groups the user selected