X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedrabundvector.cpp;h=386017d9367f7eed2e5bfd984ffedb775a26a31a;hb=6f9dc7ca71d7b8ed4aba2824f76ae6b29da89f3b;hp=846f9cdb705c7a801097feaeca59272d4001d361;hpb=eb1c88346fb246e95a6b38935b103f95e38b82ca;p=mothur.git diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 846f9cd..386017d 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -11,10 +11,9 @@ using namespace std; #include "sharedrabundvector.h" -#include "utilities.hpp" #include "sabundvector.hpp" #include "ordervector.hpp" -#include +#include "sharedutilities.h" /***********************************************************************/ @@ -58,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"; @@ -188,8 +246,64 @@ void SharedRAbundVector::push_back(int binSize, int otu, string groupName){ /***********************************************************************/ -void SharedRAbundVector::pop_back(){ +void SharedRAbundVector::insert(int binSize, int otu, string groupName){ + try { + individual newGuy; + newGuy.abundance = binSize; + newGuy.group = groupName; + newGuy.bin = otu; + + data.insert(data.begin()+otu, newGuy); + numBins++; + + if(binSize > maxRank){ + maxRank = binSize; + } + + numSeqs += binSize; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedRAbundVector class function insert. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +void SharedRAbundVector::push_front(int binSize, int otu, string groupName){ + try { + individual newGuy; + newGuy.abundance = binSize; + newGuy.group = groupName; + newGuy.bin = otu; + + data.insert(data.begin(), newGuy); + numBins++; + + if(binSize > maxRank){ + maxRank = binSize; + } + + numSeqs += binSize; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedRAbundVector class function push_front. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundVector::pop_back(){ + numSeqs -= data[data.size()-1].abundance; + numBins--; return data.pop_back(); } @@ -223,7 +337,7 @@ void SharedRAbundVector::print(ostream& output){ try { output << numBins << '\t'; - for(int i=0;i 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 { @@ -374,6 +516,8 @@ SharedOrderVector SharedRAbundVector::getSharedOrderVector() { random_shuffle(ov.begin(), ov.end()); ov.setLabel(label); + ov.updateStats(); + return ov; } catch(exception& e) {