X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=listvector.cpp;fp=listvector.cpp;h=3af7cfe93f2d2b6dba45ab7b9ae5cd8c17184255;hb=20a2d0350a737a434c89f303662d64a8eeea7b05;hp=0000000000000000000000000000000000000000;hpb=bbb5879a7e566935c23d63d42bb945072424b939;p=mothur.git diff --git a/listvector.cpp b/listvector.cpp new file mode 100644 index 0000000..3af7cfe --- /dev/null +++ b/listvector.cpp @@ -0,0 +1,330 @@ +/* + * list.cpp + * + * + * Created by Pat Schloss on 8/8/08. + * Copyright 2008 Patrick D. Schloss. All rights reserved. + * + */ + +using namespace std; + +#include +#include +#include "sabundvector.hpp" +#include "rabundvector.hpp" +#include "ordervector.hpp" +#include "datavector.hpp" +#include "utilities.hpp" +#include "listvector.hpp" + + +/***********************************************************************/ + +ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}; + +/***********************************************************************/ + +ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){}; + +/***********************************************************************/ + +ListVector::ListVector(string id, vector lv) : DataVector(id), data(lv){ + try { + for(int i=0;i maxRank) { maxRank = binSize; } + numSeqs += binSize; + } + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/**********************************************************************/ + +ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + int hold; + f >> label >> hold; + + data.assign(hold, ""); + string inputData = ""; + + for(int i=0;i> inputData; + set(i, inputData); + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +void ListVector::set(int binNumber, string seqNames){ + try { + int nNames_old = getNumNames(data[binNumber]); + data[binNumber] = seqNames; + int nNames_new = getNumNames(seqNames); + + if(nNames_old == 0) { numBins++; } + if(nNames_new == 0) { numBins--; } + if(nNames_new > maxRank) { maxRank = nNames_new; } + + numSeqs += (nNames_new - nNames_old); + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +string ListVector::get(int index){ + return data[index]; +} + +/***********************************************************************/ + +void ListVector::push_back(string seqNames){ + try { + data.push_back(seqNames); + int nNames = getNumNames(seqNames); + + numBins++; + + if(nNames > maxRank) { maxRank = nNames; } + + numSeqs += nNames; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +void ListVector::resize(int size){ + data.resize(size); +} + +/***********************************************************************/ + +int ListVector::size(){ + return data.size(); +} +/***********************************************************************/ + +void ListVector::clear(){ + numBins = 0; + maxRank = 0; + numSeqs = 0; + return data.clear(); + +} + +/***********************************************************************/ + +void ListVector::print(ostream& output){ + try { + output << label << '\t' << numBins << '\t'; + + for(int i=0;i=0;i--){ + // if(rav.get(i) == 0){ rav.pop_back(); } + // else{ + // break; + // } + // } + rav.setLabel(label); + + return rav; + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/ + +SAbundVector ListVector::getSAbundVector(){ + try { + SAbundVector sav(maxRank+1); + + for(int i=0;igGroupmap; + SharedOrderVector* order; + order = new SharedOrderVector(); + order->setLabel(label); + + for(int i=0;igetGroup(name); + order->push_back(i, binSize, groupName); //i represents what bin you are in + } + //get last name + groupName = groupmap->getGroup(names); + order->push_back(i, binSize, groupName); + } + random_shuffle(order->begin(), order->end()); + return order; +} + +/***********************************************************************/ + +OrderVector ListVector::getOrderVector(map* orderMap = NULL){ + + try { + if(orderMap == NULL){ + OrderVector ov; + + for(int i=0;icount(seqName) == 0){ + cerr << seqName << " not found, check *.names file\n"; + exit(1); + } + + ov.set((*orderMap)[seqName], i); + seqName = ""; + } + } + + if(orderMap->count(seqName) == 0){ + cerr << seqName << " not found, check *.names file\n"; + exit(1); + } + ov.set((*orderMap)[seqName], i); + } + + ov.setLabel(label); + ov.getNumBins(); + + return ov; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/***********************************************************************/