X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedrabundvector.cpp;h=ca24b91fdc9ffde552be61dbcd09730e32ec9aa5;hb=dc874a77f24b3808775e2ce7e39595c647a07f82;hp=9634613ded396633062188934cab9f1f4a40e9dc;hpb=51cf89e90eef8b300c2786eb1560dd89e6e83445;p=mothur.git diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 9634613..ca24b91 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -13,6 +13,7 @@ using namespace std; #include "sharedrabundvector.h" #include "sabundvector.hpp" #include "ordervector.hpp" +#include "sharedutilities.h" /***********************************************************************/ @@ -56,30 +57,89 @@ SharedRAbundVector::SharedRAbundVector(string id, vector rav) : Data } -/*********************************************************************** - - +/***********************************************************************/ +//reads a shared file SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - int i, num; - string holdLabel, group - individual newGuy; + globaldata = GlobalData::getInstance(); - f >> label >> group >> num; + if (globaldata->gGroupmap == NULL) { groupmap = new GroupMap(); } - //initialize data - for (i=0; i> label >> groupN >> num; + holdLabel = label; + + //add new vector to lookup + SharedRAbundVector* temp = new SharedRAbundVector(); + lookup.push_back(temp); + lookup[0]->setLabel(label); + lookup[0]->setGroup(groupN); + + if (globaldata->gGroupmap == NULL) { + //save group in groupmap + groupmap->namesOfGroups.push_back(groupN); + groupmap->groupIndex[groupN] = 0; } - int inputData; - - for(int i=0;i> inputData; - set(i, inputData); + + lookup[0]->push_back(inputData, i, groupN); //abundance, bin, group + push_back(inputData, i, groupN); + numSeqs += inputData; + numBins++; + if (inputData > maxRank) { maxRank = inputData; } + } + + //save position in file in case next line is a new label. + pos = f.tellg(); + + if (f.eof() != true) { f >> nextLabel; } + + //read the rest of the groups info in + while ((nextLabel == holdLabel) && (f.eof() != true)) { + f >> groupN >> num; + count++; + + if (globaldata->gGroupmap == NULL) { + //save group in groupmap + groupmap->namesOfGroups.push_back(groupN); + groupmap->groupIndex[groupN] = count; + } + + //add new vector to lookup + temp = new SharedRAbundVector(); + lookup.push_back(temp); + lookup[count]->setLabel(label); + lookup[count]->setGroup(groupN); + + //fill vector. + for(int i=0;i> inputData; + lookup[count]->push_back(inputData, i, groupN); //abundance, bin, group + } + + //save position in file in case next line is a new label. + pos = f.tellg(); + + if (f.eof() != true) { f >> nextLabel; } + } + + //put file pointer back since you are now at a new distance label + f.seekg(pos, ios::beg); + + if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; } + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function SharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -93,12 +153,6 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), /***********************************************************************/ -SharedRAbundVector::~SharedRAbundVector() { - -} - -/***********************************************************************/ - void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){ try { int oldBinSize = data[binNumber].abundance; @@ -325,6 +379,34 @@ SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){ return *this; } /***********************************************************************/ +vector SharedRAbundVector::getSharedRAbundVectors(){ + try { + SharedUtil* util; + util = new SharedUtil(); + + util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + + for (int i = 0; i < lookup.size(); i++) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util->isValidGroup(lookup[i]->getGroup(), globaldata->Groups) == false) { + delete lookup[i]; + lookup.erase(lookup.begin()+i); + i--; + } + } + + return lookup; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/***********************************************************************/ RAbundVector SharedRAbundVector::getRAbundVector() { try { @@ -428,6 +510,8 @@ SharedOrderVector SharedRAbundVector::getSharedOrderVector() { random_shuffle(ov.begin(), ov.end()); ov.setLabel(label); + ov.updateStats(); + return ov; } catch(exception& e) {