5 * Created by Sarah Westcott on 11/18/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "inputdata.h"
11 #include "ordervector.hpp"
12 #include "listvector.hpp"
13 #include "rabundvector.hpp"
15 /***********************************************************************/
17 InputData::InputData(string fName, string f) : format(f){
19 openInputFile(fName, fileHandle);
24 /***********************************************************************/
27 InputData::~InputData(){
33 /***********************************************************************/
35 InputData::InputData(string fName, string orderFileName, string f) : format(f){
39 openInputFile(orderFileName, ofHandle);
46 orderMap[name] = count;
52 openInputFile(fName, fileHandle);
55 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59 cout << "An unknown error has occurred in the InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 /***********************************************************************/
65 ListVector* InputData::getListVector(){
68 if(format == "list") {
69 list = new ListVector(fileHandle);
80 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
84 cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89 /***********************************************************************/
91 ListVector* InputData::getListVector(string label){
95 openInputFile(filename, in);
99 if (format == "list") {
101 while (in.eof() != true) {
103 list = new ListVector(in);
104 thisLabel = list->getLabel();
106 //if you are at the last label
107 if (thisLabel == label) { break; }
108 //so you don't loose this memory
109 else { delete list; }
121 catch(exception& e) {
122 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 /***********************************************************************/
134 SharedListVector* InputData::getSharedListVector(){
137 if (format == "shared") {
138 SharedList = new SharedListVector(fileHandle);
148 catch(exception& e) {
149 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
153 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
157 /***********************************************************************/
159 SharedListVector* InputData::getSharedListVector(string label){
163 openInputFile(filename, in);
167 if (format == "shared") {
169 while (in.eof() != true) {
171 SharedList = new SharedListVector(in);
172 thisLabel = SharedList->getLabel();
174 //if you are at the last label
175 if (thisLabel == label) { break; }
176 //so you don't loose this memory
177 else { delete SharedList; }
190 catch(exception& e) {
191 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
195 cout << "An unknown error has occurred in the InputData class function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 /***********************************************************************/
204 SharedOrderVector* InputData::getSharedOrderVector(){
207 if (format == "sharedfile") {
208 SharedOrder = new SharedOrderVector(fileHandle);
218 catch(exception& e) {
219 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
223 cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
228 /***********************************************************************/
230 SharedOrderVector* InputData::getSharedOrderVector(string label){
234 openInputFile(filename, in);
238 if (format == "sharedfile") {
240 while (in.eof() != true) {
242 SharedOrder = new SharedOrderVector(in);
243 thisLabel = SharedOrder->getLabel();
245 //if you are at the last label
246 if (thisLabel == label) { break; }
247 //so you don't loose this memory
248 else { delete SharedOrder; }
261 catch(exception& e) {
262 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
266 cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
273 /***********************************************************************/
275 OrderVector* InputData::getOrderVector(){
278 if((format == "list") || (format == "listorder")) {
279 input = new ListVector(fileHandle);
281 else if (format == "shared") {
282 input = new SharedListVector(fileHandle);
284 else if(format == "rabund"){
285 input = new RAbundVector(fileHandle);
287 else if(format == "order"){
288 input = new OrderVector(fileHandle);
290 else if(format == "sabund"){
291 input = new SAbundVector(fileHandle);
295 output = new OrderVector();
296 *output = (input->getOrderVector());
304 catch(exception& e) {
305 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
309 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
314 /***********************************************************************/
315 OrderVector* InputData::getOrderVector(string label){
320 openInputFile(filename, in);
323 if((format == "list") || (format == "listorder")) {
325 while (in.eof() != true) {
327 input = new ListVector(in);
328 thisLabel = input->getLabel();
330 //if you are at the last label
331 if (thisLabel == label) { break; }
332 //so you don't loose this memory
333 else { delete input; }
337 else if (format == "shared") {
339 while (in.eof() != true) {
341 input = new SharedListVector(in);
342 thisLabel = input->getLabel();
344 //if you are at the last label
345 if (thisLabel == label) { break; }
346 //so you don't loose this memory
347 else { delete input; }
352 else if(format == "rabund"){
354 while (in.eof() != true) {
356 input = new RAbundVector(in);
357 thisLabel = input->getLabel();
359 //if you are at the last label
360 if (thisLabel == label) { break; }
361 //so you don't loose this memory
362 else { delete input; }
367 else if(format == "order"){
369 while (in.eof() != true) {
371 input = new OrderVector(in);
372 thisLabel = input->getLabel();
374 //if you are at the last label
375 if (thisLabel == label) { break; }
376 //so you don't loose this memory
377 else { delete input; }
382 else if(format == "sabund"){
384 while (in.eof() != true) {
386 input = new SAbundVector(in);
387 thisLabel = input->getLabel();
389 //if you are at the last label
390 if (thisLabel == label) { break; }
391 //so you don't loose this memory
392 else { delete input; }
401 output = new OrderVector();
402 *output = (input->getOrderVector());
411 catch(exception& e) {
412 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
416 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
421 /***********************************************************************/
422 //this is used when you don't need the order vector
423 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
426 if (format == "sharedfile") {
427 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
428 if (SharedRAbund != NULL) {
429 return SharedRAbund->getSharedRAbundVectors();
431 }else if (format == "shared") {
432 SharedList = new SharedListVector(fileHandle);
433 if (SharedList != NULL) {
434 return SharedList->getSharedRAbundVector();
440 //this is created to signal to calling function that the input file is at eof
441 vector<SharedRAbundVector*> null; null.push_back(NULL);
445 catch(exception& e) {
446 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
450 cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
454 /***********************************************************************/
455 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
460 openInputFile(filename, in);
463 if (format == "sharedfile") {
464 while (in.eof() != true) {
466 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
467 if (SharedRAbund != NULL) {
468 thisLabel = SharedRAbund->getLabel();
469 //if you are at the last label
470 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
472 //so you don't loose this memory
473 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
474 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
481 }else if (format == "shared") {
482 while (in.eof() != true) {
484 SharedList = new SharedListVector(in);
485 if (SharedList != NULL) {
486 thisLabel = SharedList->getLabel();
487 //if you are at the last label
488 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
490 //so you don't loose this memory
501 //this is created to signal to calling function that the input file is at eof
502 vector<SharedRAbundVector*> null; null.push_back(NULL);
507 catch(exception& e) {
508 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
512 cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
518 /***********************************************************************/
520 SAbundVector* InputData::getSAbundVector(){
523 if (format == "list") {
524 input = new ListVector(fileHandle);
526 else if (format == "shared") {
527 input = new SharedListVector(fileHandle);
529 else if(format == "rabund"){
530 input = new RAbundVector(fileHandle);
532 else if(format == "order"){
533 input = new OrderVector(fileHandle);
535 else if(format == "sabund"){
536 input = new SAbundVector(fileHandle);
541 sabund = new SAbundVector();
542 *sabund = (input->getSAbundVector());
550 catch(exception& e) {
551 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
555 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
559 /***********************************************************************/
560 SAbundVector* InputData::getSAbundVector(string label){
565 openInputFile(filename, in);
568 if (format == "list") {
570 while (in.eof() != true) {
572 input = new ListVector(in);
573 thisLabel = input->getLabel();
575 //if you are at the last label
576 if (thisLabel == label) { break; }
577 //so you don't loose this memory
578 else { delete input; }
582 else if (format == "shared") {
584 while (in.eof() != true) {
586 input = new SharedListVector(in);
587 thisLabel = input->getLabel();
589 //if you are at the last label
590 if (thisLabel == label) { break; }
591 //so you don't loose this memory
592 else { delete input; }
597 else if(format == "rabund"){
599 while (in.eof() != true) {
601 input = new RAbundVector(in);
602 thisLabel = input->getLabel();
604 //if you are at the last label
605 if (thisLabel == label) { break; }
606 //so you don't loose this memory
607 else { delete input; }
612 else if(format == "order"){
614 while (in.eof() != true) {
616 input = new OrderVector(in);
617 thisLabel = input->getLabel();
619 //if you are at the last label
620 if (thisLabel == label) { break; }
621 //so you don't loose this memory
622 else { delete input; }
627 else if(format == "sabund"){
629 while (in.eof() != true) {
631 input = new SAbundVector(in);
632 thisLabel = input->getLabel();
634 //if you are at the last label
635 if (thisLabel == label) { break; }
636 //so you don't loose this memory
637 else { delete input; }
646 sabund = new SAbundVector();
647 *sabund = (input->getSAbundVector());
656 catch(exception& e) {
657 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
661 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
666 /***********************************************************************/
667 RAbundVector* InputData::getRAbundVector(){
670 if (format == "list") {
671 input = new ListVector(fileHandle);
673 else if (format == "shared") {
674 input = new SharedListVector(fileHandle);
676 else if(format == "rabund"){
677 input = new RAbundVector(fileHandle);
679 else if(format == "order"){
680 input = new OrderVector(fileHandle);
682 else if(format == "sabund"){
683 input = new SAbundVector(fileHandle);
688 rabund = new RAbundVector();
689 *rabund = (input->getRAbundVector());
697 catch(exception& e) {
698 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
702 cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
706 /***********************************************************************/
707 RAbundVector* InputData::getRAbundVector(string label){
712 openInputFile(filename, in);
715 if (format == "list") {
717 while (in.eof() != true) {
719 input = new ListVector(in);
720 thisLabel = input->getLabel();
722 //if you are at the last label
723 if (thisLabel == label) { break; }
724 //so you don't loose this memory
725 else { delete input; }
729 else if (format == "shared") {
731 while (in.eof() != true) {
733 input = new SharedListVector(in);
734 thisLabel = input->getLabel();
736 //if you are at the last label
737 if (thisLabel == label) { break; }
738 //so you don't loose this memory
739 else { delete input; }
744 else if(format == "rabund"){
746 while (in.eof() != true) {
748 input = new RAbundVector(in);
749 thisLabel = input->getLabel();
751 //if you are at the last label
752 if (thisLabel == label) { break; }
753 //so you don't loose this memory
754 else { delete input; }
759 else if(format == "order"){
761 while (in.eof() != true) {
763 input = new OrderVector(in);
764 thisLabel = input->getLabel();
766 //if you are at the last label
767 if (thisLabel == label) { break; }
768 //so you don't loose this memory
769 else { delete input; }
774 else if(format == "sabund"){
776 while (in.eof() != true) {
778 input = new SAbundVector(in);
779 thisLabel = input->getLabel();
781 //if you are at the last label
782 if (thisLabel == label) { break; }
783 //so you don't loose this memory
784 else { delete input; }
793 rabund = new RAbundVector();
794 *rabund = (input->getRAbundVector());
802 catch(exception& e) {
803 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
807 cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
812 /***********************************************************************/