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 globaldata = GlobalData::getInstance();
20 m->openInputFile(fName, fileHandle);
25 /***********************************************************************/
28 InputData::~InputData(){
30 globaldata = GlobalData::getInstance();
31 globaldata->saveNextLabel = "";
36 /***********************************************************************/
38 InputData::InputData(string fName, string orderFileName, string f) : format(f){
40 m = MothurOut::getInstance();
41 globaldata = GlobalData::getInstance();
43 m->openInputFile(orderFileName, ofHandle);
50 orderMap[name] = count;
56 m->openInputFile(fName, fileHandle);
59 m->errorOut(e, "InputData", "InputData");
63 /***********************************************************************/
65 ListVector* InputData::getListVector(){
67 if(!fileHandle.eof()){
68 if(format == "list") {
69 list = new ListVector(fileHandle);
72 m->gobble(fileHandle);
80 m->errorOut(e, "InputData", "getListVector");
85 /***********************************************************************/
86 ListVector* InputData::getListVector(string label){
90 m->openInputFile(filename, in);
94 if (format == "list") {
96 while (in.eof() != true) {
98 list = new ListVector(in);
99 thisLabel = list->getLabel();
101 //if you are at the last label
102 if (thisLabel == label) { break; }
103 //so you don't loose this memory
104 else { delete list; }
107 }else{ list = NULL; }
116 catch(exception& e) {
117 m->errorOut(e, "InputData", "getListVector");
121 /***********************************************************************/
122 ListVector* InputData::getListVector(string label, bool resetFP){
130 if (format == "list") {
132 while (fileHandle.eof() != true) {
134 list = new ListVector(fileHandle); m->gobble(fileHandle);
135 thisLabel = list->getLabel();
137 //if you are at the last label
138 if (thisLabel == label) { break; }
139 //so you don't loose this memory
140 else { delete list; }
142 }else{ list = NULL; }
150 catch(exception& e) {
151 m->errorOut(e, "InputData", "getListVector");
156 /***********************************************************************/
158 SharedListVector* InputData::getSharedListVector(){
161 if (format == "shared") {
162 SharedList = new SharedListVector(fileHandle);
163 }else{ SharedList = NULL; }
165 m->gobble(fileHandle);
172 catch(exception& e) {
173 m->errorOut(e, "InputData", "getSharedListVector");
177 /***********************************************************************/
179 SharedListVector* InputData::getSharedListVector(string label){
183 m->openInputFile(filename, in);
187 if (format == "shared") {
189 while (in.eof() != true) {
191 SharedList = new SharedListVector(in);
192 thisLabel = SharedList->getLabel();
194 //if you are at the last label
195 if (thisLabel == label) { break; }
196 //so you don't loose this memory
197 else { delete SharedList; }
201 }else{ SharedList = NULL; }
210 catch(exception& e) {
211 m->errorOut(e, "InputData", "getSharedListVector");
218 /***********************************************************************/
220 SharedOrderVector* InputData::getSharedOrderVector(){
223 if (format == "sharedfile") {
224 SharedOrder = new SharedOrderVector(fileHandle);
225 }else{ SharedOrder = NULL; }
227 m->gobble(fileHandle);
234 catch(exception& e) {
235 m->errorOut(e, "InputData", "getSharedOrderVector");
240 /***********************************************************************/
242 SharedOrderVector* InputData::getSharedOrderVector(string label){
246 m->openInputFile(filename, in);
250 if (format == "sharedfile") {
252 while (in.eof() != true) {
254 SharedOrder = new SharedOrderVector(in);
255 thisLabel = SharedOrder->getLabel();
257 //if you are at the last label
258 if (thisLabel == label) { break; }
259 //so you don't loose this memory
260 else { delete SharedOrder; }
264 }else{ SharedOrder = NULL; }
273 catch(exception& e) {
274 m->errorOut(e, "InputData", "getSharedOrderVector");
281 /***********************************************************************/
283 OrderVector* InputData::getOrderVector(){
286 if((format == "list") || (format == "listorder")) {
287 input = new ListVector(fileHandle);
289 else if (format == "shared") {
290 input = new SharedListVector(fileHandle);
292 else if(format == "rabund"){
293 input = new RAbundVector(fileHandle);
295 else if(format == "order"){
296 input = new OrderVector(fileHandle);
298 else if(format == "sabund"){
299 input = new SAbundVector(fileHandle);
302 m->gobble(fileHandle);
304 output = new OrderVector();
305 *output = (input->getOrderVector());
313 catch(exception& e) {
314 m->errorOut(e, "InputData", "getOrderVector");
319 /***********************************************************************/
320 OrderVector* InputData::getOrderVector(string label){
325 m->openInputFile(filename, in);
328 if((format == "list") || (format == "listorder")) {
330 while (in.eof() != true) {
332 input = new ListVector(in);
333 thisLabel = input->getLabel();
335 //if you are at the last label
336 if (thisLabel == label) { break; }
337 //so you don't loose this memory
338 else { delete input; }
342 else if (format == "shared") {
344 while (in.eof() != true) {
346 input = new SharedListVector(in);
347 thisLabel = input->getLabel();
349 //if you are at the last label
350 if (thisLabel == label) { break; }
351 //so you don't loose this memory
352 else { delete input; }
357 else if(format == "rabund"){
359 while (in.eof() != true) {
361 input = new RAbundVector(in);
362 thisLabel = input->getLabel();
364 //if you are at the last label
365 if (thisLabel == label) { break; }
366 //so you don't loose this memory
367 else { delete input; }
372 else if(format == "order"){
374 while (in.eof() != true) {
376 input = new OrderVector(in);
377 thisLabel = input->getLabel();
379 //if you are at the last label
380 if (thisLabel == label) { break; }
381 //so you don't loose this memory
382 else { delete input; }
387 else if(format == "sabund"){
389 while (in.eof() != true) {
391 input = new SAbundVector(in);
392 thisLabel = input->getLabel();
394 //if you are at the last label
395 if (thisLabel == label) { break; }
396 //so you don't loose this memory
397 else { delete input; }
406 output = new OrderVector();
407 *output = (input->getOrderVector());
416 catch(exception& e) {
417 m->errorOut(e, "InputData", "getOrderVector");
422 /***********************************************************************/
423 //this is used when you don't need the order vector
424 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
427 if (format == "sharedfile") {
428 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
429 if (SharedRAbund != NULL) {
430 return SharedRAbund->getSharedRAbundVectors();
432 }else if (format == "shared") {
433 SharedList = new SharedListVector(fileHandle);
434 if (SharedList != NULL) {
435 return SharedList->getSharedRAbundVector();
438 m->gobble(fileHandle);
441 //this is created to signal to calling function that the input file is at eof
442 vector<SharedRAbundVector*> null; null.push_back(NULL);
446 catch(exception& e) {
447 m->errorOut(e, "InputData", "getSharedRAbundVectors");
451 /***********************************************************************/
452 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
457 m->openInputFile(filename, in);
458 globaldata->saveNextLabel = "";
461 if (format == "sharedfile") {
462 while (in.eof() != true) {
464 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
465 if (SharedRAbund != NULL) {
466 thisLabel = SharedRAbund->getLabel();
468 //if you are at the last label
469 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
471 //so you don't loose this memory
472 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
473 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
480 }else if (format == "shared") {
481 while (in.eof() != true) {
483 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 globaldata->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);
631 m->gobble(fileHandle);
633 sabund = new SAbundVector();
634 *sabund = (input->getSAbundVector());
642 catch(exception& e) {
643 m->errorOut(e, "InputData", "getSAbundVector");
647 /***********************************************************************/
648 SAbundVector* InputData::getSAbundVector(string label){
653 m->openInputFile(filename, in);
656 if (format == "list") {
658 while (in.eof() != true) {
660 input = new ListVector(in);
661 thisLabel = input->getLabel();
663 //if you are at the last label
664 if (thisLabel == label) { break; }
665 //so you don't loose this memory
666 else { delete input; }
670 else if (format == "shared") {
672 while (in.eof() != true) {
674 input = new SharedListVector(in);
675 thisLabel = input->getLabel();
677 //if you are at the last label
678 if (thisLabel == label) { break; }
679 //so you don't loose this memory
680 else { delete input; }
685 else if(format == "rabund"){
687 while (in.eof() != true) {
689 input = new RAbundVector(in);
690 thisLabel = input->getLabel();
692 //if you are at the last label
693 if (thisLabel == label) { break; }
694 //so you don't loose this memory
695 else { delete input; }
700 else if(format == "order"){
702 while (in.eof() != true) {
704 input = new OrderVector(in);
705 thisLabel = input->getLabel();
707 //if you are at the last label
708 if (thisLabel == label) { break; }
709 //so you don't loose this memory
710 else { delete input; }
715 else if(format == "sabund"){
717 while (in.eof() != true) {
719 input = new SAbundVector(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; }
734 sabund = new SAbundVector();
735 *sabund = (input->getSAbundVector());
744 catch(exception& e) {
745 m->errorOut(e, "InputData", "getSAbundVector");
750 /***********************************************************************/
751 RAbundVector* InputData::getRAbundVector(){
754 if (format == "list") {
755 input = new ListVector(fileHandle);
757 else if (format == "shared") {
758 input = new SharedListVector(fileHandle);
760 else if(format == "rabund"){
761 input = new RAbundVector(fileHandle);
763 else if(format == "order"){
764 input = new OrderVector(fileHandle);
766 else if(format == "sabund"){
767 input = new SAbundVector(fileHandle);
770 m->gobble(fileHandle);
772 rabund = new RAbundVector();
773 *rabund = (input->getRAbundVector());
781 catch(exception& e) {
782 m->errorOut(e, "InputData", "getRAbundVector");
786 /***********************************************************************/
787 RAbundVector* InputData::getRAbundVector(string label){
792 m->openInputFile(filename, in);
795 if (format == "list") {
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") {
811 while (in.eof() != true) {
813 input = new SharedListVector(in);
814 thisLabel = input->getLabel();
816 //if you are at the last label
817 if (thisLabel == label) { break; }
818 //so you don't loose this memory
819 else { delete input; }
824 else if(format == "rabund"){
826 while (in.eof() != true) {
828 input = new RAbundVector(in);
829 thisLabel = input->getLabel();
831 //if you are at the last label
832 if (thisLabel == label) { break; }
833 //so you don't loose this memory
834 else { delete input; }
839 else if(format == "order"){
841 while (in.eof() != true) {
843 input = new OrderVector(in);
844 thisLabel = input->getLabel();
846 //if you are at the last label
847 if (thisLabel == label) { break; }
848 //so you don't loose this memory
849 else { delete input; }
854 else if(format == "sabund"){
856 while (in.eof() != true) {
858 input = new SAbundVector(in);
859 thisLabel = input->getLabel();
861 //if you are at the last label
862 if (thisLabel == label) { break; }
863 //so you don't loose this memory
864 else { delete input; }
873 rabund = new RAbundVector();
874 *rabund = (input->getRAbundVector());
882 catch(exception& e) {
883 m->errorOut(e, "InputData", "getRAbundVector");
888 /***********************************************************************/