5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
13 #include "sabundvector.hpp"
14 #include "rabundvector.hpp"
15 #include "ordervector.hpp"
16 #include "listvector.hpp"
19 /***********************************************************************/
21 ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
23 /***********************************************************************/
25 ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){};
27 /***********************************************************************/
29 ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
31 for(int i=0;i<data.size();i++){
33 int binSize = getNumNames(data[i]);
35 if(binSize > maxRank) { maxRank = binSize; }
41 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
45 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50 /**********************************************************************/
52 ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
57 data.assign(hold, "");
58 string inputData = "";
60 for(int i=0;i<hold;i++){
66 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
75 /***********************************************************************/
77 void ListVector::set(int binNumber, string seqNames){
79 int nNames_old = getNumNames(data[binNumber]);
80 data[binNumber] = seqNames;
81 int nNames_new = getNumNames(seqNames);
83 if(nNames_old == 0) { numBins++; }
84 if(nNames_new == 0) { numBins--; }
85 if(nNames_new > maxRank) { maxRank = nNames_new; }
87 numSeqs += (nNames_new - nNames_old);
90 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
99 /***********************************************************************/
101 string ListVector::get(int index){
105 /***********************************************************************/
107 void ListVector::push_back(string seqNames){
109 data.push_back(seqNames);
110 int nNames = getNumNames(seqNames);
114 if(nNames > maxRank) { maxRank = nNames; }
118 catch(exception& e) {
119 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 cout << "An unknown error has occurred in the ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 /***********************************************************************/
130 void ListVector::resize(int size){
134 /***********************************************************************/
136 int ListVector::size(){
139 /***********************************************************************/
141 void ListVector::clear(){
149 /***********************************************************************/
151 void ListVector::print(ostream& output){
153 output << label << '\t' << numBins << '\t';
155 for(int i=0;i<data.size();i++){
157 output << data[i] << '\t';
162 catch(exception& e) {
163 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
167 cout << "An unknown error has occurred in the ListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
173 /***********************************************************************/
175 RAbundVector ListVector::getRAbundVector(){
179 for(int i=0;i<data.size();i++){
180 int binSize = getNumNames(data[i]);
181 rav.push_back(binSize);
184 // This was here before to output data in a nice format, but it screws up the name mapping steps
185 // sort(rav.rbegin(), rav.rend());
187 // for(int i=data.size()-1;i>=0;i--){
188 // if(rav.get(i) == 0){ rav.pop_back(); }
197 catch(exception& e) {
198 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
207 /***********************************************************************/
209 SAbundVector ListVector::getSAbundVector(){
211 SAbundVector sav(maxRank+1);
213 for(int i=0;i<data.size();i++){
214 int binSize = getNumNames(data[i]);
215 sav.set(binSize, sav.get(binSize) + 1);
222 catch(exception& e) {
223 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
227 cout << "An unknown error has occurred in the ListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
232 /***********************************************************************/
234 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
237 if(orderMap == NULL){
240 for(int i=0;i<data.size();i++){
241 int binSize = getNumNames(data[i]);
242 for(int j=0;j<binSize;j++){
246 random_shuffle(ov.begin(), ov.end());
254 OrderVector ov(numSeqs);
256 for(int i=0;i<data.size();i++){
257 string listOTU = data[i];
258 int length = listOTU.size();
262 for(int j=0;j<length;j++){
264 if(listOTU[j] != ','){
265 seqName += listOTU[j];
268 if(orderMap->count(seqName) == 0){
269 cerr << seqName << " not found, check *.names file\n";
273 ov.set((*orderMap)[seqName], i);
278 if(orderMap->count(seqName) == 0){
279 cerr << seqName << " not found, check *.names file\n";
282 ov.set((*orderMap)[seqName], i);
291 catch(exception& e) {
292 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
296 cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
301 /***********************************************************************/