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();
523 m->gobble(fileHandle);
526 //this is created to signal to calling function that the input file is at eof
527 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
531 catch(exception& e) {
532 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
536 /***********************************************************************/
537 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
542 m->openInputFile(filename, in);
543 globaldata->saveNextLabel = "";
546 if (format == "sharedfile") {
547 while (in.eof() != true) {
549 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
550 if (SharedRelAbund != NULL) {
551 thisLabel = SharedRelAbund->getLabel();
552 //if you are at the last label
553 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
555 //so you don't loose this memory
556 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
557 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
558 delete SharedRelAbund;
566 //this is created to signal to calling function that the input file is at eof
567 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
572 catch(exception& e) {
573 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
577 /***********************************************************************/
579 SAbundVector* InputData::getSAbundVector(){
582 if (format == "list") {
583 input = new ListVector(fileHandle);
585 else if (format == "shared") {
586 input = new SharedListVector(fileHandle);
588 else if(format == "rabund"){
589 input = new RAbundVector(fileHandle);
591 else if(format == "order"){
592 input = new OrderVector(fileHandle);
594 else if(format == "sabund"){
595 input = new SAbundVector(fileHandle);
598 m->gobble(fileHandle);
600 sabund = new SAbundVector();
601 *sabund = (input->getSAbundVector());
609 catch(exception& e) {
610 m->errorOut(e, "InputData", "getSAbundVector");
614 /***********************************************************************/
615 SAbundVector* InputData::getSAbundVector(string label){
620 m->openInputFile(filename, in);
623 if (format == "list") {
625 while (in.eof() != true) {
627 input = new ListVector(in);
628 thisLabel = input->getLabel();
630 //if you are at the last label
631 if (thisLabel == label) { break; }
632 //so you don't loose this memory
633 else { delete input; }
637 else if (format == "shared") {
639 while (in.eof() != true) {
641 input = new SharedListVector(in);
642 thisLabel = input->getLabel();
644 //if you are at the last label
645 if (thisLabel == label) { break; }
646 //so you don't loose this memory
647 else { delete input; }
652 else if(format == "rabund"){
654 while (in.eof() != true) {
656 input = new RAbundVector(in);
657 thisLabel = input->getLabel();
659 //if you are at the last label
660 if (thisLabel == label) { break; }
661 //so you don't loose this memory
662 else { delete input; }
667 else if(format == "order"){
669 while (in.eof() != true) {
671 input = new OrderVector(in);
672 thisLabel = input->getLabel();
674 //if you are at the last label
675 if (thisLabel == label) { break; }
676 //so you don't loose this memory
677 else { delete input; }
682 else if(format == "sabund"){
684 while (in.eof() != true) {
686 input = new SAbundVector(in);
687 thisLabel = input->getLabel();
689 //if you are at the last label
690 if (thisLabel == label) { break; }
691 //so you don't loose this memory
692 else { delete input; }
701 sabund = new SAbundVector();
702 *sabund = (input->getSAbundVector());
711 catch(exception& e) {
712 m->errorOut(e, "InputData", "getSAbundVector");
717 /***********************************************************************/
718 RAbundVector* InputData::getRAbundVector(){
721 if (format == "list") {
722 input = new ListVector(fileHandle);
724 else if (format == "shared") {
725 input = new SharedListVector(fileHandle);
727 else if(format == "rabund"){
728 input = new RAbundVector(fileHandle);
730 else if(format == "order"){
731 input = new OrderVector(fileHandle);
733 else if(format == "sabund"){
734 input = new SAbundVector(fileHandle);
737 m->gobble(fileHandle);
739 rabund = new RAbundVector();
740 *rabund = (input->getRAbundVector());
748 catch(exception& e) {
749 m->errorOut(e, "InputData", "getRAbundVector");
753 /***********************************************************************/
754 RAbundVector* InputData::getRAbundVector(string label){
759 m->openInputFile(filename, in);
762 if (format == "list") {
764 while (in.eof() != true) {
766 input = new ListVector(in);
767 thisLabel = input->getLabel();
769 //if you are at the last label
770 if (thisLabel == label) { break; }
771 //so you don't loose this memory
772 else { delete input; }
776 else if (format == "shared") {
778 while (in.eof() != true) {
780 input = new SharedListVector(in);
781 thisLabel = input->getLabel();
783 //if you are at the last label
784 if (thisLabel == label) { break; }
785 //so you don't loose this memory
786 else { delete input; }
791 else if(format == "rabund"){
793 while (in.eof() != true) {
795 input = new RAbundVector(in);
796 thisLabel = input->getLabel();
798 //if you are at the last label
799 if (thisLabel == label) { break; }
800 //so you don't loose this memory
801 else { delete input; }
806 else if(format == "order"){
808 while (in.eof() != true) {
810 input = new OrderVector(in);
811 thisLabel = input->getLabel();
813 //if you are at the last label
814 if (thisLabel == label) { break; }
815 //so you don't loose this memory
816 else { delete input; }
821 else if(format == "sabund"){
823 while (in.eof() != true) {
825 input = new SAbundVector(in);
826 thisLabel = input->getLabel();
828 //if you are at the last label
829 if (thisLabel == label) { break; }
830 //so you don't loose this memory
831 else { delete input; }
840 rabund = new RAbundVector();
841 *rabund = (input->getRAbundVector());
849 catch(exception& e) {
850 m->errorOut(e, "InputData", "getRAbundVector");
855 /***********************************************************************/