X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sharedlistvector.cpp;h=8fabc5b605b40f06ea1e7217a766f36bc8bfded9;hp=2cecb5de49d2aca77c33f21b77d584d6c15f893e;hb=b206f634aae1b4ce13978d203247fb64757d5482;hpb=d70a1c2d70c5a516e74880709e3b48cfc1ce0321 diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 2cecb5d..8fabc5b 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -25,25 +25,80 @@ SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0 /***********************************************************************/ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { + groupmap = NULL; countTable = NULL; //set up groupmap for later. if (m->groupMode == "group") { groupmap = new GroupMap(m->getGroupFile()); groupmap->readMap(); }else { countTable = new CountTable(); - countTable->readTable(m->getCountTableFile()); + 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) { @@ -78,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){ @@ -236,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