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){
18 m = MothurOut::getInstance();
19 m->openInputFile(fName, fileHandle);
21 m->saveNextLabel = "";
25 /***********************************************************************/
27 InputData::~InputData(){
29 m->saveNextLabel = "";
33 /***********************************************************************/
35 InputData::InputData(string fName, string orderFileName, string f) : format(f){
37 m = MothurOut::getInstance();
39 m->openInputFile(orderFileName, ofHandle);
46 orderMap[name] = count;
52 m->openInputFile(fName, fileHandle);
53 m->saveNextLabel = "";
56 m->errorOut(e, "InputData", "InputData");
60 /***********************************************************************/
62 ListVector* InputData::getListVector(){
64 if(!fileHandle.eof()){
65 if(format == "list") {
66 list = new ListVector(fileHandle);
69 m->gobble(fileHandle);
77 m->errorOut(e, "InputData", "getListVector");
82 /***********************************************************************/
83 ListVector* InputData::getListVector(string label){
87 m->openInputFile(filename, in);
91 if (format == "list") {
93 while (in.eof() != true) {
95 list = new ListVector(in);
96 thisLabel = list->getLabel();
98 //if you are at the last label
99 if (thisLabel == label) { break; }
100 //so you don't loose this memory
101 else { delete list; }
104 }else{ list = NULL; }
113 catch(exception& e) {
114 m->errorOut(e, "InputData", "getListVector");
118 /***********************************************************************/
119 ListVector* InputData::getListVector(string label, bool resetFP){
127 if (format == "list") {
129 while (fileHandle.eof() != true) {
131 list = new ListVector(fileHandle); m->gobble(fileHandle);
132 thisLabel = list->getLabel();
134 //if you are at the last label
135 if (thisLabel == label) { break; }
136 //so you don't loose this memory
137 else { delete list; }
139 }else{ list = NULL; }
147 catch(exception& e) {
148 m->errorOut(e, "InputData", "getListVector");
153 /***********************************************************************/
155 SharedListVector* InputData::getSharedListVector(){
158 if (format == "shared") {
159 SharedList = new SharedListVector(fileHandle);
160 }else{ SharedList = NULL; }
162 m->gobble(fileHandle);
169 catch(exception& e) {
170 m->errorOut(e, "InputData", "getSharedListVector");
174 /***********************************************************************/
176 SharedListVector* InputData::getSharedListVector(string label){
180 m->openInputFile(filename, in);
184 if (format == "shared") {
186 while (in.eof() != true) {
188 SharedList = new SharedListVector(in);
189 thisLabel = SharedList->getLabel();
191 //if you are at the last label
192 if (thisLabel == label) { break; }
193 //so you don't loose this memory
194 else { delete SharedList; }
198 }else{ SharedList = NULL; }
207 catch(exception& e) {
208 m->errorOut(e, "InputData", "getSharedListVector");
215 /***********************************************************************/
217 SharedOrderVector* InputData::getSharedOrderVector(){
220 if (format == "sharedfile") {
221 SharedOrder = new SharedOrderVector(fileHandle);
222 }else{ SharedOrder = NULL; }
224 m->gobble(fileHandle);
231 catch(exception& e) {
232 m->errorOut(e, "InputData", "getSharedOrderVector");
237 /***********************************************************************/
239 SharedOrderVector* InputData::getSharedOrderVector(string label){
243 m->openInputFile(filename, in);
247 if (format == "sharedfile") {
249 while (in.eof() != true) {
251 SharedOrder = new SharedOrderVector(in);
252 thisLabel = SharedOrder->getLabel();
254 //if you are at the last label
255 if (thisLabel == label) { break; }
256 //so you don't loose this memory
257 else { delete SharedOrder; }
261 }else{ SharedOrder = NULL; }
270 catch(exception& e) {
271 m->errorOut(e, "InputData", "getSharedOrderVector");
278 /***********************************************************************/
280 OrderVector* InputData::getOrderVector(){
283 if((format == "list") || (format == "listorder")) {
284 input = new ListVector(fileHandle);
286 else if (format == "shared") {
287 input = new SharedListVector(fileHandle);
289 else if(format == "rabund"){
290 input = new RAbundVector(fileHandle);
292 else if(format == "order"){
293 input = new OrderVector(fileHandle);
295 else if(format == "sabund"){
296 input = new SAbundVector(fileHandle);
299 m->gobble(fileHandle);
301 output = new OrderVector();
302 *output = (input->getOrderVector());
310 catch(exception& e) {
311 m->errorOut(e, "InputData", "getOrderVector");
316 /***********************************************************************/
317 OrderVector* InputData::getOrderVector(string label){
322 m->openInputFile(filename, in);
325 if((format == "list") || (format == "listorder")) {
327 while (in.eof() != true) {
329 input = new ListVector(in);
330 thisLabel = input->getLabel();
332 //if you are at the last label
333 if (thisLabel == label) { break; }
334 //so you don't loose this memory
335 else { delete input; }
339 else if (format == "shared") {
341 while (in.eof() != true) {
343 input = new SharedListVector(in);
344 thisLabel = input->getLabel();
346 //if you are at the last label
347 if (thisLabel == label) { break; }
348 //so you don't loose this memory
349 else { delete input; }
354 else if(format == "rabund"){
356 while (in.eof() != true) {
358 input = new RAbundVector(in);
359 thisLabel = input->getLabel();
361 //if you are at the last label
362 if (thisLabel == label) { break; }
363 //so you don't loose this memory
364 else { delete input; }
369 else if(format == "order"){
371 while (in.eof() != true) {
373 input = new OrderVector(in);
374 thisLabel = input->getLabel();
376 //if you are at the last label
377 if (thisLabel == label) { break; }
378 //so you don't loose this memory
379 else { delete input; }
384 else if(format == "sabund"){
386 while (in.eof() != true) {
388 input = new SAbundVector(in);
389 thisLabel = input->getLabel();
391 //if you are at the last label
392 if (thisLabel == label) { break; }
393 //so you don't loose this memory
394 else { delete input; }
403 output = new OrderVector();
404 *output = (input->getOrderVector());
413 catch(exception& e) {
414 m->errorOut(e, "InputData", "getOrderVector");
419 /***********************************************************************/
420 //this is used when you don't need the order vector
421 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
424 if (format == "sharedfile") {
425 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
426 if (SharedRAbund != NULL) {
427 return SharedRAbund->getSharedRAbundVectors();
429 }else if (format == "shared") {
430 SharedList = new SharedListVector(fileHandle);
432 if (SharedList != NULL) {
433 return SharedList->getSharedRAbundVector();
436 m->gobble(fileHandle);
439 //this is created to signal to calling function that the input file is at eof
440 vector<SharedRAbundVector*> null; null.push_back(NULL);
444 catch(exception& e) {
445 m->errorOut(e, "InputData", "getSharedRAbundVectors");
449 /***********************************************************************/
450 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
455 m->openInputFile(filename, in);
456 m->saveNextLabel = "";
459 if (format == "sharedfile") {
460 while (in.eof() != true) {
462 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
463 if (SharedRAbund != NULL) {
464 thisLabel = SharedRAbund->getLabel();
466 //if you are at the last label
467 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
469 //so you don't loose this memory
470 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
471 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
478 }else if (format == "shared") {
479 while (in.eof() != true) {
481 SharedList = new SharedListVector(in);
483 if (SharedList != NULL) {
484 thisLabel = SharedList->getLabel();
485 //if you are at the last label
486 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
488 //so you don't loose this memory
499 //this is created to signal to calling function that the input file is at eof
500 vector<SharedRAbundVector*> null; null.push_back(NULL);
505 catch(exception& e) {
506 m->errorOut(e, "InputData", "getSharedRAbundVectors");
511 /***********************************************************************/
512 //this is used when you don't need the order vector
513 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
516 if (format == "relabund") {
517 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle);
518 if (SharedRelAbund != NULL) {
519 return SharedRelAbund->getSharedRAbundFloatVectors();
521 }else if (format == "sharedfile") {
522 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
523 if (SharedRAbund != NULL) {
524 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
525 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
526 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
531 m->gobble(fileHandle);
534 //this is created to signal to calling function that the input file is at eof
535 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
539 catch(exception& e) {
540 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
544 /***********************************************************************/
545 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
550 m->openInputFile(filename, in);
551 m->saveNextLabel = "";
554 if (format == "relabund") {
555 while (in.eof() != true) {
557 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
558 if (SharedRelAbund != NULL) {
559 thisLabel = SharedRelAbund->getLabel();
560 //if you are at the last label
561 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
563 //so you don't loose this memory
564 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
565 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
566 delete SharedRelAbund;
571 }else if (format == "sharedfile") {
572 while (in.eof() != true) {
574 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
575 if (SharedRAbund != NULL) {
576 thisLabel = SharedRAbund->getLabel();
578 //if you are at the last label
579 if (thisLabel == label) {
581 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
582 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
583 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
586 //so you don't loose this memory
587 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
588 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
598 //this is created to signal to calling function that the input file is at eof
599 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
604 catch(exception& e) {
605 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
609 /***********************************************************************/
611 SAbundVector* InputData::getSAbundVector(){
614 if (format == "list") {
615 input = new ListVector(fileHandle);
617 else if (format == "shared") {
618 input = new SharedListVector(fileHandle);
620 else if(format == "rabund"){
621 input = new RAbundVector(fileHandle);
623 else if(format == "order"){
624 input = new OrderVector(fileHandle);
626 else if(format == "sabund"){
627 input = new SAbundVector(fileHandle);
629 m->gobble(fileHandle);
631 sabund = new SAbundVector();
632 *sabund = (input->getSAbundVector());
640 catch(exception& e) {
641 m->errorOut(e, "InputData", "getSAbundVector");
645 /***********************************************************************/
646 SAbundVector* InputData::getSAbundVector(string label){
651 m->openInputFile(filename, in);
654 if (format == "list") {
656 while (in.eof() != true) {
658 input = new ListVector(in);
659 thisLabel = input->getLabel();
661 //if you are at the last label
662 if (thisLabel == label) { break; }
663 //so you don't loose this memory
664 else { delete input; }
668 else if (format == "shared") {
670 while (in.eof() != true) {
672 input = new SharedListVector(in);
673 thisLabel = input->getLabel();
675 //if you are at the last label
676 if (thisLabel == label) { break; }
677 //so you don't loose this memory
678 else { delete input; }
683 else if(format == "rabund"){
685 while (in.eof() != true) {
687 input = new RAbundVector(in);
688 thisLabel = input->getLabel();
690 //if you are at the last label
691 if (thisLabel == label) { break; }
692 //so you don't loose this memory
693 else { delete input; }
698 else if(format == "order"){
700 while (in.eof() != true) {
702 input = new OrderVector(in);
703 thisLabel = input->getLabel();
705 //if you are at the last label
706 if (thisLabel == label) { break; }
707 //so you don't loose this memory
708 else { delete input; }
713 else if(format == "sabund"){
715 while (in.eof() != true) {
717 input = new SAbundVector(in);
718 thisLabel = input->getLabel();
720 //if you are at the last label
721 if (thisLabel == label) { break; }
722 //so you don't loose this memory
723 else { delete input; }
732 sabund = new SAbundVector();
733 *sabund = (input->getSAbundVector());
742 catch(exception& e) {
743 m->errorOut(e, "InputData", "getSAbundVector");
748 /***********************************************************************/
749 RAbundVector* InputData::getRAbundVector(){
752 if (format == "list") {
753 input = new ListVector(fileHandle);
755 else if (format == "shared") {
756 input = new SharedListVector(fileHandle);
758 else if(format == "rabund"){
759 input = new RAbundVector(fileHandle);
761 else if(format == "order"){
762 input = new OrderVector(fileHandle);
764 else if(format == "sabund"){
765 input = new SAbundVector(fileHandle);
768 m->gobble(fileHandle);
770 rabund = new RAbundVector();
771 *rabund = (input->getRAbundVector());
779 catch(exception& e) {
780 m->errorOut(e, "InputData", "getRAbundVector");
784 /***********************************************************************/
785 RAbundVector* InputData::getRAbundVector(string label){
790 m->openInputFile(filename, in);
793 if (format == "list") {
795 while (in.eof() != true) {
797 input = new ListVector(in);
798 thisLabel = input->getLabel();
800 //if you are at the last label
801 if (thisLabel == label) { break; }
802 //so you don't loose this memory
803 else { delete input; }
807 else if (format == "shared") {
809 while (in.eof() != true) {
811 input = new SharedListVector(in);
812 thisLabel = input->getLabel();
814 //if you are at the last label
815 if (thisLabel == label) { break; }
816 //so you don't loose this memory
817 else { delete input; }
822 else if(format == "rabund"){
824 while (in.eof() != true) {
826 input = new RAbundVector(in);
827 thisLabel = input->getLabel();
829 //if you are at the last label
830 if (thisLabel == label) { break; }
831 //so you don't loose this memory
832 else { delete input; }
837 else if(format == "order"){
839 while (in.eof() != true) {
841 input = new OrderVector(in);
842 thisLabel = input->getLabel();
844 //if you are at the last label
845 if (thisLabel == label) { break; }
846 //so you don't loose this memory
847 else { delete input; }
852 else if(format == "sabund"){
854 while (in.eof() != true) {
856 input = new SAbundVector(in);
857 thisLabel = input->getLabel();
859 //if you are at the last label
860 if (thisLabel == label) { break; }
861 //so you don't loose this memory
862 else { delete input; }
872 rabund = new RAbundVector();
873 *rabund = (input->getRAbundVector());
881 catch(exception& e) {
882 m->errorOut(e, "InputData", "getRAbundVector");
887 /***********************************************************************/