5 * Created by Pat Schloss on 8/8/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
14 #include "sabundvector.hpp"
15 #include "rabundvector.hpp"
16 #include "ordervector.hpp"
17 #include "datavector.hpp"
18 #include "utilities.hpp"
19 #include "listvector.hpp"
22 /***********************************************************************/
24 ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
26 /***********************************************************************/
28 ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){};
30 /***********************************************************************/
32 ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
34 for(int i=0;i<data.size();i++){
36 int binSize = getNumNames(data[i]);
38 if(binSize > maxRank) { maxRank = binSize; }
44 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
48 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53 /**********************************************************************/
55 ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
60 data.assign(hold, "");
61 string inputData = "";
63 for(int i=0;i<hold;i++){
69 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
78 /***********************************************************************/
80 void ListVector::set(int binNumber, string seqNames){
82 int nNames_old = getNumNames(data[binNumber]);
83 data[binNumber] = seqNames;
84 int nNames_new = getNumNames(seqNames);
86 if(nNames_old == 0) { numBins++; }
87 if(nNames_new == 0) { numBins--; }
88 if(nNames_new > maxRank) { maxRank = nNames_new; }
90 numSeqs += (nNames_new - nNames_old);
93 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97 cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
102 /***********************************************************************/
104 string ListVector::get(int index){
108 /***********************************************************************/
110 void ListVector::push_back(string seqNames){
112 data.push_back(seqNames);
113 int nNames = getNumNames(seqNames);
117 if(nNames > maxRank) { maxRank = nNames; }
121 catch(exception& e) {
122 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 cout << "An unknown error has occurred in the ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 /***********************************************************************/
133 void ListVector::resize(int size){
137 /***********************************************************************/
139 int ListVector::size(){
142 /***********************************************************************/
144 void ListVector::clear(){
152 /***********************************************************************/
154 void ListVector::print(ostream& output){
156 output << label << '\t' << numBins << '\t';
158 for(int i=0;i<data.size();i++){
160 output << data[i] << '\t';
165 catch(exception& e) {
166 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
170 cout << "An unknown error has occurred in the ListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 /***********************************************************************/
178 RAbundVector ListVector::getRAbundVector(){
182 for(int i=0;i<data.size();i++){
183 int binSize = getNumNames(data[i]);
184 rav.push_back(binSize);
187 // This was here before to output data in a nice format, but it screws up the name mapping steps
188 // sort(rav.rbegin(), rav.rend());
190 // for(int i=data.size()-1;i>=0;i--){
191 // if(rav.get(i) == 0){ rav.pop_back(); }
200 catch(exception& e) {
201 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
205 cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
210 /***********************************************************************/
212 SAbundVector ListVector::getSAbundVector(){
214 SAbundVector sav(maxRank+1);
216 for(int i=0;i<data.size();i++){
217 int binSize = getNumNames(data[i]);
218 sav.set(binSize, sav.get(binSize) + 1);
225 catch(exception& e) {
226 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
230 cout << "An unknown error has occurred in the ListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 /***********************************************************************/
236 SharedOrderVector* ListVector::getSharedOrderVector(){
237 globaldata = GlobalData::getInstance();
238 string groupName, names, name;
239 groupmap = globaldata->gGroupmap;
240 SharedOrderVector* order;
241 order = new SharedOrderVector();
242 order->setLabel(label);
244 for(int i=0;i<numBins;i++){
245 int binSize = getNumNames(get(i)); //find number of individual in given bin
247 while (names.find_first_of(',') != -1) {
248 name = names.substr(0,names.find_first_of(','));
249 names = names.substr(names.find_first_of(',')+1, names.length());
250 groupName = groupmap->getGroup(name);
251 order->push_back(i, binSize, groupName); //i represents what bin you are in
254 groupName = groupmap->getGroup(names);
255 order->push_back(i, binSize, groupName);
257 random_shuffle(order->begin(), order->end());
261 /***********************************************************************/
263 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
266 if(orderMap == NULL){
269 for(int i=0;i<data.size();i++){
270 int binSize = getNumNames(data[i]);
271 for(int j=0;j<binSize;j++){
275 random_shuffle(ov.begin(), ov.end());
283 OrderVector ov(numSeqs);
285 for(int i=0;i<data.size();i++){
286 string listOTU = data[i];
287 int length = listOTU.size();
291 for(int j=0;j<length;j++){
293 if(listOTU[j] != ','){
294 seqName += listOTU[j];
297 if(orderMap->count(seqName) == 0){
298 cerr << seqName << " not found, check *.names file\n";
302 ov.set((*orderMap)[seqName], i);
307 if(orderMap->count(seqName) == 0){
308 cerr << seqName << " not found, check *.names file\n";
311 ov.set((*orderMap)[seqName], i);
320 catch(exception& e) {
321 cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
325 cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
330 /***********************************************************************/