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);
89 if (format == "list") {
91 while (in.eof() != true) {
93 list = new ListVector(in);
94 thisLabel = list->getLabel();
96 //if you are at the last label
97 if (thisLabel == label) { break; }
98 //so you don't loose this memory
102 }else{ list = NULL; }
111 catch(exception& e) {
112 m->errorOut(e, "InputData", "getListVector");
116 /***********************************************************************/
117 ListVector* InputData::getListVector(string label, bool resetFP){
125 if (format == "list") {
127 while (fileHandle.eof() != true) {
129 list = new ListVector(fileHandle); m->gobble(fileHandle);
130 thisLabel = list->getLabel();
132 //if you are at the last label
133 if (thisLabel == label) { break; }
134 //so you don't loose this memory
135 else { delete list; }
137 }else{ list = NULL; }
145 catch(exception& e) {
146 m->errorOut(e, "InputData", "getListVector");
151 /***********************************************************************/
153 SharedListVector* InputData::getSharedListVector(){
156 if (format == "shared") {
157 SharedList = new SharedListVector(fileHandle);
158 }else{ SharedList = NULL; }
160 m->gobble(fileHandle);
167 catch(exception& e) {
168 m->errorOut(e, "InputData", "getSharedListVector");
172 /***********************************************************************/
174 SharedListVector* InputData::getSharedListVector(string label){
178 m->openInputFile(filename, in);
182 if (format == "shared") {
184 while (in.eof() != true) {
186 SharedList = new SharedListVector(in);
187 thisLabel = SharedList->getLabel();
189 //if you are at the last label
190 if (thisLabel == label) { break; }
191 //so you don't loose this memory
192 else { delete SharedList; }
196 }else{ SharedList = NULL; }
205 catch(exception& e) {
206 m->errorOut(e, "InputData", "getSharedListVector");
213 /***********************************************************************/
215 SharedOrderVector* InputData::getSharedOrderVector(){
218 if (format == "sharedfile") {
219 SharedOrder = new SharedOrderVector(fileHandle);
220 }else{ SharedOrder = NULL; }
222 m->gobble(fileHandle);
229 catch(exception& e) {
230 m->errorOut(e, "InputData", "getSharedOrderVector");
235 /***********************************************************************/
237 SharedOrderVector* InputData::getSharedOrderVector(string label){
241 m->openInputFile(filename, in);
245 if (format == "sharedfile") {
247 while (in.eof() != true) {
249 SharedOrder = new SharedOrderVector(in);
250 thisLabel = SharedOrder->getLabel();
252 //if you are at the last label
253 if (thisLabel == label) { break; }
254 //so you don't loose this memory
255 else { delete SharedOrder; }
259 }else{ SharedOrder = NULL; }
268 catch(exception& e) {
269 m->errorOut(e, "InputData", "getSharedOrderVector");
276 /***********************************************************************/
278 OrderVector* InputData::getOrderVector(){
281 if((format == "list") || (format == "listorder")) {
282 input = new ListVector(fileHandle);
284 else if (format == "shared") {
285 input = new SharedListVector(fileHandle);
287 else if(format == "rabund"){
288 input = new RAbundVector(fileHandle);
290 else if(format == "order"){
291 input = new OrderVector(fileHandle);
293 else if(format == "sabund"){
294 input = new SAbundVector(fileHandle);
297 m->gobble(fileHandle);
299 output = new OrderVector();
300 *output = (input->getOrderVector());
308 catch(exception& e) {
309 m->errorOut(e, "InputData", "getOrderVector");
314 /***********************************************************************/
315 OrderVector* InputData::getOrderVector(string label){
320 m->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 m->errorOut(e, "InputData", "getOrderVector");
417 /***********************************************************************/
418 //this is used when you don't need the order vector
419 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
422 if (format == "sharedfile") {
423 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
424 if (SharedRAbund != NULL) {
425 return SharedRAbund->getSharedRAbundVectors();
427 }else if (format == "shared") {
428 SharedList = new SharedListVector(fileHandle);
430 if (SharedList != NULL) {
431 return SharedList->getSharedRAbundVector();
434 m->gobble(fileHandle);
437 //this is created to signal to calling function that the input file is at eof
438 vector<SharedRAbundVector*> null; null.push_back(NULL);
442 catch(exception& e) {
443 m->errorOut(e, "InputData", "getSharedRAbundVectors");
447 /***********************************************************************/
448 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
453 m->openInputFile(filename, in);
454 m->saveNextLabel = "";
457 if (format == "sharedfile") {
458 while (in.eof() != true) {
460 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
461 if (SharedRAbund != NULL) {
462 thisLabel = SharedRAbund->getLabel();
464 //if you are at the last label
465 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
467 //so you don't loose this memory
468 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
469 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
476 }else if (format == "shared") {
477 while (in.eof() != true) {
479 SharedList = new SharedListVector(in);
481 if (SharedList != NULL) {
482 thisLabel = SharedList->getLabel();
483 //if you are at the last label
484 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
486 //so you don't loose this memory
497 //this is created to signal to calling function that the input file is at eof
498 vector<SharedRAbundVector*> null; null.push_back(NULL);
503 catch(exception& e) {
504 m->errorOut(e, "InputData", "getSharedRAbundVectors");
509 /***********************************************************************/
510 //this is used when you don't need the order vector
511 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
514 if (format == "relabund") {
515 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle);
516 if (SharedRelAbund != NULL) {
517 return SharedRelAbund->getSharedRAbundFloatVectors();
519 }else if (format == "sharedfile") {
520 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
521 if (SharedRAbund != NULL) {
522 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
523 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
524 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
529 m->gobble(fileHandle);
532 //this is created to signal to calling function that the input file is at eof
533 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
537 catch(exception& e) {
538 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
542 /***********************************************************************/
543 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
548 m->openInputFile(filename, in);
549 m->saveNextLabel = "";
552 if (format == "relabund") {
553 while (in.eof() != true) {
555 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
556 if (SharedRelAbund != NULL) {
557 thisLabel = SharedRelAbund->getLabel();
558 //if you are at the last label
559 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
561 //so you don't loose this memory
562 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
563 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
564 delete SharedRelAbund;
569 }else if (format == "sharedfile") {
570 while (in.eof() != true) {
572 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
573 if (SharedRAbund != NULL) {
574 thisLabel = SharedRAbund->getLabel();
576 //if you are at the last label
577 if (thisLabel == label) {
579 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
580 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
581 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
584 //so you don't loose this memory
585 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
586 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
596 //this is created to signal to calling function that the input file is at eof
597 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
602 catch(exception& e) {
603 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
607 /***********************************************************************/
609 SAbundVector* InputData::getSAbundVector(){
612 if (format == "list") {
613 input = new ListVector(fileHandle);
615 else if (format == "shared") {
616 input = new SharedListVector(fileHandle);
618 else if(format == "rabund"){
619 input = new RAbundVector(fileHandle);
621 else if(format == "order"){
622 input = new OrderVector(fileHandle);
624 else if(format == "sabund"){
625 input = new SAbundVector(fileHandle);
627 m->gobble(fileHandle);
629 sabund = new SAbundVector();
630 *sabund = (input->getSAbundVector());
638 catch(exception& e) {
639 m->errorOut(e, "InputData", "getSAbundVector");
643 /***********************************************************************/
644 SAbundVector* InputData::getSAbundVector(string label){
649 m->openInputFile(filename, in);
652 if (format == "list") {
654 while (in.eof() != true) {
656 input = new ListVector(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; }
666 else if (format == "shared") {
668 while (in.eof() != true) {
670 input = new SharedListVector(in);
671 thisLabel = input->getLabel();
673 //if you are at the last label
674 if (thisLabel == label) { break; }
675 //so you don't loose this memory
676 else { delete input; }
681 else if(format == "rabund"){
683 while (in.eof() != true) {
685 input = new RAbundVector(in);
686 thisLabel = input->getLabel();
688 //if you are at the last label
689 if (thisLabel == label) { break; }
690 //so you don't loose this memory
691 else { delete input; }
696 else if(format == "order"){
698 while (in.eof() != true) {
700 input = new OrderVector(in);
701 thisLabel = input->getLabel();
703 //if you are at the last label
704 if (thisLabel == label) { break; }
705 //so you don't loose this memory
706 else { delete input; }
711 else if(format == "sabund"){
713 while (in.eof() != true) {
715 input = new SAbundVector(in);
716 thisLabel = input->getLabel();
718 //if you are at the last label
719 if (thisLabel == label) { break; }
720 //so you don't loose this memory
721 else { delete input; }
730 sabund = new SAbundVector();
731 *sabund = (input->getSAbundVector());
740 catch(exception& e) {
741 m->errorOut(e, "InputData", "getSAbundVector");
746 /***********************************************************************/
747 RAbundVector* InputData::getRAbundVector(){
750 if (format == "list") {
751 input = new ListVector(fileHandle);
753 else if (format == "shared") {
754 input = new SharedListVector(fileHandle);
756 else if(format == "rabund"){
757 input = new RAbundVector(fileHandle);
759 else if(format == "order"){
760 input = new OrderVector(fileHandle);
762 else if(format == "sabund"){
763 input = new SAbundVector(fileHandle);
766 m->gobble(fileHandle);
768 rabund = new RAbundVector();
769 *rabund = (input->getRAbundVector());
777 catch(exception& e) {
778 m->errorOut(e, "InputData", "getRAbundVector");
782 /***********************************************************************/
783 RAbundVector* InputData::getRAbundVector(string label){
788 m->openInputFile(filename, in);
791 if (format == "list") {
793 while (in.eof() != true) {
795 input = new ListVector(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; }
805 else if (format == "shared") {
807 while (in.eof() != true) {
809 input = new SharedListVector(in);
810 thisLabel = input->getLabel();
812 //if you are at the last label
813 if (thisLabel == label) { break; }
814 //so you don't loose this memory
815 else { delete input; }
820 else if(format == "rabund"){
822 while (in.eof() != true) {
824 input = new RAbundVector(in);
825 thisLabel = input->getLabel();
827 //if you are at the last label
828 if (thisLabel == label) { break; }
829 //so you don't loose this memory
830 else { delete input; }
835 else if(format == "order"){
837 while (in.eof() != true) {
839 input = new OrderVector(in);
840 thisLabel = input->getLabel();
842 //if you are at the last label
843 if (thisLabel == label) { break; }
844 //so you don't loose this memory
845 else { delete input; }
850 else if(format == "sabund"){
852 while (in.eof() != true) {
854 input = new SAbundVector(in);
855 thisLabel = input->getLabel();
857 //if you are at the last label
858 if (thisLabel == label) { break; }
859 //so you don't loose this memory
860 else { delete input; }
870 rabund = new RAbundVector();
871 *rabund = (input->getRAbundVector());
879 catch(exception& e) {
880 m->errorOut(e, "InputData", "getRAbundVector");
885 /***********************************************************************/