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 = "";
23 /***********************************************************************/
25 InputData::~InputData(){
27 m->saveNextLabel = "";
30 /***********************************************************************/
32 InputData::InputData(string fName, string orderFileName, string f) : format(f){
34 m = MothurOut::getInstance();
36 m->openInputFile(orderFileName, ofHandle);
43 orderMap[name] = count;
49 m->openInputFile(fName, fileHandle);
50 m->saveNextLabel = "";
54 m->errorOut(e, "InputData", "InputData");
58 /***********************************************************************/
60 ListVector* InputData::getListVector(){
62 if(!fileHandle.eof()){
63 if(format == "list") {
64 list = new ListVector(fileHandle);
67 m->gobble(fileHandle);
75 m->errorOut(e, "InputData", "getListVector");
80 /***********************************************************************/
81 ListVector* InputData::getListVector(string label){
85 m->openInputFile(filename, in);
86 m->saveNextLabel = "";
90 if (format == "list") {
92 while (in.eof() != true) {
94 list = new ListVector(in);
95 thisLabel = list->getLabel();
97 //if you are at the last label
98 if (thisLabel == label) { break; }
99 //so you don't loose this memory
100 else { delete list; }
103 }else{ list = NULL; }
112 catch(exception& e) {
113 m->errorOut(e, "InputData", "getListVector");
117 /***********************************************************************/
118 ListVector* InputData::getListVector(string label, bool resetFP){
123 m->saveNextLabel = "";
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);
244 m->saveNextLabel = "";
248 if (format == "sharedfile") {
250 while (in.eof() != true) {
252 SharedOrder = new SharedOrderVector(in);
253 thisLabel = SharedOrder->getLabel();
255 //if you are at the last label
256 if (thisLabel == label) { break; }
257 //so you don't loose this memory
258 else { delete SharedOrder; }
262 }else{ SharedOrder = NULL; }
271 catch(exception& e) {
272 m->errorOut(e, "InputData", "getSharedOrderVector");
279 /***********************************************************************/
281 OrderVector* InputData::getOrderVector(){
284 if((format == "list") || (format == "listorder")) {
285 input = new ListVector(fileHandle);
287 else if (format == "shared") {
288 input = new SharedListVector(fileHandle);
290 else if(format == "rabund"){
291 input = new RAbundVector(fileHandle);
293 else if(format == "order"){
294 input = new OrderVector(fileHandle);
296 else if(format == "sabund"){
297 input = new SAbundVector(fileHandle);
300 m->gobble(fileHandle);
302 output = new OrderVector();
303 *output = (input->getOrderVector());
311 catch(exception& e) {
312 m->errorOut(e, "InputData", "getOrderVector");
317 /***********************************************************************/
318 OrderVector* InputData::getOrderVector(string label){
323 m->openInputFile(filename, in);
326 if((format == "list") || (format == "listorder")) {
327 m->saveNextLabel = "";
328 while (in.eof() != true) {
330 input = new ListVector(in);
331 thisLabel = input->getLabel();
333 //if you are at the last label
334 if (thisLabel == label) { break; }
335 //so you don't loose this memory
336 else { delete input; }
340 else if (format == "shared") {
341 m->saveNextLabel = "";
342 while (in.eof() != true) {
344 input = new SharedListVector(in);
345 thisLabel = input->getLabel();
347 //if you are at the last label
348 if (thisLabel == label) { break; }
349 //so you don't loose this memory
350 else { delete input; }
355 else if(format == "rabund"){
357 while (in.eof() != true) {
359 input = new RAbundVector(in);
360 thisLabel = input->getLabel();
362 //if you are at the last label
363 if (thisLabel == label) { break; }
364 //so you don't loose this memory
365 else { delete input; }
370 else if(format == "order"){
372 while (in.eof() != true) {
374 input = new OrderVector(in);
375 thisLabel = input->getLabel();
377 //if you are at the last label
378 if (thisLabel == label) { break; }
379 //so you don't loose this memory
380 else { delete input; }
385 else if(format == "sabund"){
387 while (in.eof() != true) {
389 input = new SAbundVector(in);
390 thisLabel = input->getLabel();
392 //if you are at the last label
393 if (thisLabel == label) { break; }
394 //so you don't loose this memory
395 else { delete input; }
404 output = new OrderVector();
405 *output = (input->getOrderVector());
414 catch(exception& e) {
415 m->errorOut(e, "InputData", "getOrderVector");
420 /***********************************************************************/
421 //this is used when you don't need the order vector
422 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
425 if (format == "sharedfile") {
426 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
427 if (SharedRAbund != NULL) {
428 return SharedRAbund->getSharedRAbundVectors();
430 }else if (format == "shared") {
431 SharedList = new SharedListVector(fileHandle);
433 if (SharedList != NULL) {
434 return SharedList->getSharedRAbundVector();
437 m->gobble(fileHandle);
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 m->errorOut(e, "InputData", "getSharedRAbundVectors");
450 /***********************************************************************/
451 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
456 m->openInputFile(filename, in);
457 m->saveNextLabel = "";
460 if (format == "sharedfile") {
461 while (in.eof() != true) {
463 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
464 if (SharedRAbund != NULL) {
465 thisLabel = SharedRAbund->getLabel();
467 //if you are at the last label
468 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
470 //so you don't loose this memory
471 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
472 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
479 }else if (format == "shared") {
480 while (in.eof() != true) {
482 SharedList = new SharedListVector(in);
484 if (SharedList != NULL) {
485 thisLabel = SharedList->getLabel();
486 //if you are at the last label
487 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
489 //so you don't loose this memory
500 //this is created to signal to calling function that the input file is at eof
501 vector<SharedRAbundVector*> null; null.push_back(NULL);
506 catch(exception& e) {
507 m->errorOut(e, "InputData", "getSharedRAbundVectors");
512 /***********************************************************************/
513 //this is used when you don't need the order vector
514 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
517 if (format == "relabund") {
518 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle);
519 if (SharedRelAbund != NULL) {
520 return SharedRelAbund->getSharedRAbundFloatVectors();
522 }else if (format == "sharedfile") {
523 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
524 if (SharedRAbund != NULL) {
525 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
526 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
527 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
532 m->gobble(fileHandle);
535 //this is created to signal to calling function that the input file is at eof
536 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
540 catch(exception& e) {
541 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
545 /***********************************************************************/
546 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
551 m->openInputFile(filename, in);
552 m->saveNextLabel = "";
555 if (format == "relabund") {
556 while (in.eof() != true) {
558 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
559 if (SharedRelAbund != NULL) {
560 thisLabel = SharedRelAbund->getLabel();
561 //if you are at the last label
562 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
564 //so you don't loose this memory
565 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
566 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
567 delete SharedRelAbund;
572 }else if (format == "sharedfile") {
573 while (in.eof() != true) {
575 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
576 if (SharedRAbund != NULL) {
577 thisLabel = SharedRAbund->getLabel();
579 //if you are at the last label
580 if (thisLabel == label) {
582 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
583 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
584 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
587 //so you don't loose this memory
588 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
589 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
599 //this is created to signal to calling function that the input file is at eof
600 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
605 catch(exception& e) {
606 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
610 /***********************************************************************/
612 SAbundVector* InputData::getSAbundVector(){
615 if (format == "list") {
616 input = new ListVector(fileHandle);
618 else if (format == "shared") {
619 input = new SharedListVector(fileHandle);
621 else if(format == "rabund"){
622 input = new RAbundVector(fileHandle);
624 else if(format == "order"){
625 input = new OrderVector(fileHandle);
627 else if(format == "sabund"){
628 input = new SAbundVector(fileHandle);
630 m->gobble(fileHandle);
632 sabund = new SAbundVector();
633 *sabund = (input->getSAbundVector());
641 catch(exception& e) {
642 m->errorOut(e, "InputData", "getSAbundVector");
646 /***********************************************************************/
647 SAbundVector* InputData::getSAbundVector(string label){
652 m->openInputFile(filename, in);
655 if (format == "list") {
656 m->saveNextLabel = "";
657 while (in.eof() != true) {
659 input = new ListVector(in);
660 thisLabel = input->getLabel();
662 //if you are at the last label
663 if (thisLabel == label) { break; }
664 //so you don't loose this memory
665 else { delete input; }
669 else if (format == "shared") {
670 m->saveNextLabel = "";
671 while (in.eof() != true) {
673 input = new SharedListVector(in);
674 thisLabel = input->getLabel();
676 //if you are at the last label
677 if (thisLabel == label) { break; }
678 //so you don't loose this memory
679 else { delete input; }
684 else if(format == "rabund"){
686 while (in.eof() != true) {
688 input = new RAbundVector(in);
689 thisLabel = input->getLabel();
691 //if you are at the last label
692 if (thisLabel == label) { break; }
693 //so you don't loose this memory
694 else { delete input; }
699 else if(format == "order"){
701 while (in.eof() != true) {
703 input = new OrderVector(in);
704 thisLabel = input->getLabel();
706 //if you are at the last label
707 if (thisLabel == label) { break; }
708 //so you don't loose this memory
709 else { delete input; }
714 else if(format == "sabund"){
716 while (in.eof() != true) {
718 input = new SAbundVector(in);
719 thisLabel = input->getLabel();
721 //if you are at the last label
722 if (thisLabel == label) { break; }
723 //so you don't loose this memory
724 else { delete input; }
733 sabund = new SAbundVector();
734 *sabund = (input->getSAbundVector());
743 catch(exception& e) {
744 m->errorOut(e, "InputData", "getSAbundVector");
749 /***********************************************************************/
750 RAbundVector* InputData::getRAbundVector(){
753 if (format == "list") {
754 input = new ListVector(fileHandle);
756 else if (format == "shared") {
757 input = new SharedListVector(fileHandle);
759 else if(format == "rabund"){
760 input = new RAbundVector(fileHandle);
762 else if(format == "order"){
763 input = new OrderVector(fileHandle);
765 else if(format == "sabund"){
766 input = new SAbundVector(fileHandle);
769 m->gobble(fileHandle);
771 rabund = new RAbundVector();
772 *rabund = (input->getRAbundVector());
780 catch(exception& e) {
781 m->errorOut(e, "InputData", "getRAbundVector");
785 /***********************************************************************/
786 RAbundVector* InputData::getRAbundVector(string label){
791 m->openInputFile(filename, in);
794 if (format == "list") {
795 m->saveNextLabel = "";
797 while (in.eof() != true) {
799 input = new ListVector(in);
800 thisLabel = input->getLabel();
802 //if you are at the last label
803 if (thisLabel == label) { break; }
804 //so you don't loose this memory
805 else { delete input; }
809 else if (format == "shared") {
810 m->saveNextLabel = "";
812 while (in.eof() != true) {
814 input = new SharedListVector(in);
815 thisLabel = input->getLabel();
817 //if you are at the last label
818 if (thisLabel == label) { break; }
819 //so you don't loose this memory
820 else { delete input; }
825 else if(format == "rabund"){
827 while (in.eof() != true) {
829 input = new RAbundVector(in);
830 thisLabel = input->getLabel();
832 //if you are at the last label
833 if (thisLabel == label) { break; }
834 //so you don't loose this memory
835 else { delete input; }
840 else if(format == "order"){
842 while (in.eof() != true) {
844 input = new OrderVector(in);
845 thisLabel = input->getLabel();
847 //if you are at the last label
848 if (thisLabel == label) { break; }
849 //so you don't loose this memory
850 else { delete input; }
855 else if(format == "sabund"){
857 while (in.eof() != true) {
859 input = new SAbundVector(in);
860 thisLabel = input->getLabel();
862 //if you are at the last label
863 if (thisLabel == label) { break; }
864 //so you don't loose this memory
865 else { delete input; }
875 rabund = new RAbundVector();
876 *rabund = (input->getRAbundVector());
884 catch(exception& e) {
885 m->errorOut(e, "InputData", "getRAbundVector");
890 /***********************************************************************/