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 = m->getNumNames(data[i]);
33 if(binSize > maxRank) { maxRank = binSize; }
39 m->errorOut(e, "ListVector", "ListVector");
44 /**********************************************************************/
46 ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
51 data.assign(hold, "");
52 string inputData = "";
54 for(int i=0;i<hold;i++){
61 m->errorOut(e, "ListVector", "ListVector");
66 /***********************************************************************/
68 void ListVector::set(int binNumber, string seqNames){
70 int nNames_old = m->getNumNames(data[binNumber]);
71 data[binNumber] = seqNames;
72 int nNames_new = m->getNumNames(seqNames);
74 if(nNames_old == 0) { numBins++; }
75 if(nNames_new == 0) { numBins--; }
76 if(nNames_new > maxRank) { maxRank = nNames_new; }
78 numSeqs += (nNames_new - nNames_old);
81 m->errorOut(e, "ListVector", "set");
86 /***********************************************************************/
88 string ListVector::get(int index){
92 /***********************************************************************/
94 void ListVector::push_back(string seqNames){
96 data.push_back(seqNames);
97 int nNames = m->getNumNames(seqNames);
101 if(nNames > maxRank) { maxRank = nNames; }
105 catch(exception& e) {
106 m->errorOut(e, "ListVector", "push_back");
111 /***********************************************************************/
113 void ListVector::resize(int size){
117 /***********************************************************************/
119 int ListVector::size(){
122 /***********************************************************************/
124 void ListVector::clear(){
132 /***********************************************************************/
134 void ListVector::print(ostream& output){
136 output << label << '\t' << numBins << '\t';
138 for(int i=0;i<data.size();i++){
140 output << data[i] << '\t';
145 catch(exception& e) {
146 m->errorOut(e, "ListVector", "print");
152 /***********************************************************************/
154 RAbundVector ListVector::getRAbundVector(){
158 for(int i=0;i<data.size();i++){
159 int binSize = m->getNumNames(data[i]);
160 rav.push_back(binSize);
163 // This was here before to output data in a nice format, but it screws up the name mapping steps
164 // sort(rav.rbegin(), rav.rend());
166 // for(int i=data.size()-1;i>=0;i--){
167 // if(rav.get(i) == 0){ rav.pop_back(); }
176 catch(exception& e) {
177 m->errorOut(e, "ListVector", "getRAbundVector");
182 /***********************************************************************/
184 SAbundVector ListVector::getSAbundVector(){
186 SAbundVector sav(maxRank+1);
188 for(int i=0;i<data.size();i++){
189 int binSize = m->getNumNames(data[i]);
190 sav.set(binSize, sav.get(binSize) + 1);
197 catch(exception& e) {
198 m->errorOut(e, "ListVector", "getSAbundVector");
203 /***********************************************************************/
205 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
208 if(orderMap == NULL){
211 for(int i=0;i<data.size();i++){
212 int binSize = m->getNumNames(data[i]);
213 for(int j=0;j<binSize;j++){
217 random_shuffle(ov.begin(), ov.end());
225 OrderVector ov(numSeqs);
227 for(int i=0;i<data.size();i++){
228 string listOTU = data[i];
229 int length = listOTU.size();
233 for(int j=0;j<length;j++){
235 if(listOTU[j] != ','){
236 seqName += listOTU[j];
239 if(orderMap->count(seqName) == 0){
240 m->mothurOut(seqName + " not found, check *.names file\n");
244 ov.set((*orderMap)[seqName], i);
249 if(orderMap->count(seqName) == 0){
250 m->mothurOut(seqName + " not found, check *.names file\n");
253 ov.set((*orderMap)[seqName], i);
262 catch(exception& e) {
263 m->errorOut(e, "ListVector", "getOrderVector");
268 /***********************************************************************/