5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
11 #include "sabundvector.hpp"
12 #include "rabundvector.hpp"
13 #include "ordervector.hpp"
14 #include "listvector.hpp"
17 /***********************************************************************/
19 ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
21 /***********************************************************************/
23 ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){}
25 /***********************************************************************/
27 ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
29 for(int i=0;i<data.size();i++){
31 int binSize = getNumNames(data[i]);
33 if(binSize > maxRank) { maxRank = binSize; }
39 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
43 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
48 /**********************************************************************/
50 ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
55 data.assign(hold, "");
56 string inputData = "";
58 for(int i=0;i<hold;i++){
64 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 /***********************************************************************/
75 void ListVector::set(int binNumber, string seqNames){
77 int nNames_old = getNumNames(data[binNumber]);
78 data[binNumber] = seqNames;
79 int nNames_new = getNumNames(seqNames);
81 if(nNames_old == 0) { numBins++; }
82 if(nNames_new == 0) { numBins--; }
83 if(nNames_new > maxRank) { maxRank = nNames_new; }
85 numSeqs += (nNames_new - nNames_old);
88 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
92 cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97 /***********************************************************************/
99 string ListVector::get(int index){
103 /***********************************************************************/
105 void ListVector::push_back(string seqNames){
107 data.push_back(seqNames);
108 int nNames = getNumNames(seqNames);
112 if(nNames > maxRank) { maxRank = nNames; }
116 catch(exception& e) {
117 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 cout << "An unknown error has occurred in the ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 /***********************************************************************/
128 void ListVector::resize(int size){
132 /***********************************************************************/
134 int ListVector::size(){
137 /***********************************************************************/
139 void ListVector::clear(){
147 /***********************************************************************/
149 void ListVector::print(ostream& output){
151 output << label << '\t' << numBins << '\t';
153 for(int i=0;i<data.size();i++){
155 output << data[i] << '\t';
160 catch(exception& e) {
161 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165 cout << "An unknown error has occurred in the ListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
171 /***********************************************************************/
173 RAbundVector ListVector::getRAbundVector(){
177 for(int i=0;i<data.size();i++){
178 int binSize = getNumNames(data[i]);
179 rav.push_back(binSize);
182 // This was here before to output data in a nice format, but it screws up the name mapping steps
183 // sort(rav.rbegin(), rav.rend());
185 // for(int i=data.size()-1;i>=0;i--){
186 // if(rav.get(i) == 0){ rav.pop_back(); }
195 catch(exception& e) {
196 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
200 cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
205 /***********************************************************************/
207 SAbundVector ListVector::getSAbundVector(){
209 SAbundVector sav(maxRank+1);
211 for(int i=0;i<data.size();i++){
212 int binSize = getNumNames(data[i]);
213 sav.set(binSize, sav.get(binSize) + 1);
220 catch(exception& e) {
221 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
225 cout << "An unknown error has occurred in the ListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
230 /***********************************************************************/
232 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
235 if(orderMap == NULL){
238 for(int i=0;i<data.size();i++){
239 int binSize = getNumNames(data[i]);
240 for(int j=0;j<binSize;j++){
244 random_shuffle(ov.begin(), ov.end());
252 OrderVector ov(numSeqs);
254 for(int i=0;i<data.size();i++){
255 string listOTU = data[i];
256 int length = listOTU.size();
260 for(int j=0;j<length;j++){
262 if(listOTU[j] != ','){
263 seqName += listOTU[j];
266 if(orderMap->count(seqName) == 0){
267 cerr << seqName << " not found, check *.names file\n";
271 ov.set((*orderMap)[seqName], i);
276 if(orderMap->count(seqName) == 0){
277 cerr << seqName << " not found, check *.names file\n";
280 ov.set((*orderMap)[seqName], i);
289 catch(exception& e) {
290 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
294 cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
299 /***********************************************************************/