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 "utilities.hpp"
17 #include "listvector.hpp"
20 /***********************************************************************/
22 ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
24 /***********************************************************************/
26 ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){};
28 /***********************************************************************/
30 ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
32 for(int i=0;i<data.size();i++){
34 int binSize = getNumNames(data[i]);
36 if(binSize > maxRank) { maxRank = binSize; }
42 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
46 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51 /**********************************************************************/
53 ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
58 data.assign(hold, "");
59 string inputData = "";
61 for(int i=0;i<hold;i++){
67 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76 /***********************************************************************/
78 void ListVector::set(int binNumber, string seqNames){
80 int nNames_old = getNumNames(data[binNumber]);
81 data[binNumber] = seqNames;
82 int nNames_new = getNumNames(seqNames);
84 if(nNames_old == 0) { numBins++; }
85 if(nNames_new == 0) { numBins--; }
86 if(nNames_new > maxRank) { maxRank = nNames_new; }
88 numSeqs += (nNames_new - nNames_old);
91 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95 cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 /***********************************************************************/
102 string ListVector::get(int index){
106 /***********************************************************************/
108 void ListVector::push_back(string seqNames){
110 data.push_back(seqNames);
111 int nNames = getNumNames(seqNames);
115 if(nNames > maxRank) { maxRank = nNames; }
119 catch(exception& e) {
120 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 cout << "An unknown error has occurred in the ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 /***********************************************************************/
131 void ListVector::resize(int size){
135 /***********************************************************************/
137 int ListVector::size(){
140 /***********************************************************************/
142 void ListVector::clear(){
150 /***********************************************************************/
152 void ListVector::print(ostream& output){
154 output << label << '\t' << numBins << '\t';
156 for(int i=0;i<data.size();i++){
158 output << data[i] << '\t';
163 catch(exception& e) {
164 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
168 cout << "An unknown error has occurred in the ListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
174 /***********************************************************************/
176 RAbundVector ListVector::getRAbundVector(){
180 for(int i=0;i<data.size();i++){
181 int binSize = getNumNames(data[i]);
182 rav.push_back(binSize);
185 // This was here before to output data in a nice format, but it screws up the name mapping steps
186 // sort(rav.rbegin(), rav.rend());
188 // for(int i=data.size()-1;i>=0;i--){
189 // if(rav.get(i) == 0){ rav.pop_back(); }
198 catch(exception& e) {
199 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203 cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
208 /***********************************************************************/
210 SAbundVector ListVector::getSAbundVector(){
212 SAbundVector sav(maxRank+1);
214 for(int i=0;i<data.size();i++){
215 int binSize = getNumNames(data[i]);
216 sav.set(binSize, sav.get(binSize) + 1);
223 catch(exception& e) {
224 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
228 cout << "An unknown error has occurred in the ListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
233 /***********************************************************************/
235 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
238 if(orderMap == NULL){
241 for(int i=0;i<data.size();i++){
242 int binSize = getNumNames(data[i]);
243 for(int j=0;j<binSize;j++){
247 random_shuffle(ov.begin(), ov.end());
255 OrderVector ov(numSeqs);
257 for(int i=0;i<data.size();i++){
258 string listOTU = data[i];
259 int length = listOTU.size();
263 for(int j=0;j<length;j++){
265 if(listOTU[j] != ','){
266 seqName += listOTU[j];
269 if(orderMap->count(seqName) == 0){
270 cerr << seqName << " not found, check *.names file\n";
274 ov.set((*orderMap)[seqName], i);
279 if(orderMap->count(seqName) == 0){
280 cerr << seqName << " not found, check *.names file\n";
283 ov.set((*orderMap)[seqName], i);
292 catch(exception& e) {
293 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
297 cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
302 /***********************************************************************/