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 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++){
60 errorOut(e, "ListVector", "ListVector");
65 /***********************************************************************/
67 void ListVector::set(int binNumber, string seqNames){
69 int nNames_old = getNumNames(data[binNumber]);
70 data[binNumber] = seqNames;
71 int nNames_new = getNumNames(seqNames);
73 if(nNames_old == 0) { numBins++; }
74 if(nNames_new == 0) { numBins--; }
75 if(nNames_new > maxRank) { maxRank = nNames_new; }
77 numSeqs += (nNames_new - nNames_old);
80 errorOut(e, "ListVector", "set");
85 /***********************************************************************/
87 string ListVector::get(int index){
91 /***********************************************************************/
93 void ListVector::push_back(string seqNames){
95 data.push_back(seqNames);
96 int nNames = getNumNames(seqNames);
100 if(nNames > maxRank) { maxRank = nNames; }
104 catch(exception& e) {
105 errorOut(e, "ListVector", "push_back");
110 /***********************************************************************/
112 void ListVector::resize(int size){
116 /***********************************************************************/
118 int ListVector::size(){
121 /***********************************************************************/
123 void ListVector::clear(){
131 /***********************************************************************/
133 void ListVector::print(ostream& output){
135 output << label << '\t' << numBins << '\t';
137 for(int i=0;i<data.size();i++){
139 output << data[i] << '\t';
144 catch(exception& e) {
145 errorOut(e, "ListVector", "print");
151 /***********************************************************************/
153 RAbundVector ListVector::getRAbundVector(){
157 for(int i=0;i<data.size();i++){
158 int binSize = getNumNames(data[i]);
159 rav.push_back(binSize);
162 // This was here before to output data in a nice format, but it screws up the name mapping steps
163 // sort(rav.rbegin(), rav.rend());
165 // for(int i=data.size()-1;i>=0;i--){
166 // if(rav.get(i) == 0){ rav.pop_back(); }
175 catch(exception& e) {
176 errorOut(e, "ListVector", "getRAbundVector");
181 /***********************************************************************/
183 SAbundVector ListVector::getSAbundVector(){
185 SAbundVector sav(maxRank+1);
187 for(int i=0;i<data.size();i++){
188 int binSize = getNumNames(data[i]);
189 sav.set(binSize, sav.get(binSize) + 1);
196 catch(exception& e) {
197 errorOut(e, "ListVector", "getSAbundVector");
202 /***********************************************************************/
204 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
207 if(orderMap == NULL){
210 for(int i=0;i<data.size();i++){
211 int binSize = getNumNames(data[i]);
212 for(int j=0;j<binSize;j++){
216 random_shuffle(ov.begin(), ov.end());
224 OrderVector ov(numSeqs);
226 for(int i=0;i<data.size();i++){
227 string listOTU = data[i];
228 int length = listOTU.size();
232 for(int j=0;j<length;j++){
234 if(listOTU[j] != ','){
235 seqName += listOTU[j];
238 if(orderMap->count(seqName) == 0){
239 mothurOut(seqName + " not found, check *.names file\n");
243 ov.set((*orderMap)[seqName], i);
248 if(orderMap->count(seqName) == 0){
249 mothurOut(seqName + " not found, check *.names file\n");
252 ov.set((*orderMap)[seqName], i);
261 catch(exception& e) {
262 errorOut(e, "ListVector", "getOrderVector");
267 /***********************************************************************/