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);
24 /***********************************************************************/
27 InputData::~InputData(){
29 globaldata = GlobalData::getInstance();
30 globaldata->saveNextLabel = "";
35 /***********************************************************************/
37 InputData::InputData(string fName, string orderFileName, string f) : format(f){
39 m = MothurOut::getInstance();
41 m->openInputFile(orderFileName, ofHandle);
48 orderMap[name] = count;
54 m->openInputFile(fName, fileHandle);
57 m->errorOut(e, "InputData", "InputData");
61 /***********************************************************************/
63 ListVector* InputData::getListVector(){
65 if(!fileHandle.eof()){
66 if(format == "list") {
67 list = new ListVector(fileHandle);
70 m->gobble(fileHandle);
78 m->errorOut(e, "InputData", "getListVector");
83 /***********************************************************************/
84 ListVector* InputData::getListVector(string label){
88 m->openInputFile(filename, in);
92 if (format == "list") {
94 while (in.eof() != true) {
96 list = new ListVector(in);
97 thisLabel = list->getLabel();
99 //if you are at the last label
100 if (thisLabel == label) { break; }
101 //so you don't loose this memory
102 else { delete list; }
105 }else{ list = NULL; }
114 catch(exception& e) {
115 m->errorOut(e, "InputData", "getListVector");
119 /***********************************************************************/
120 ListVector* InputData::getListVector(string label, bool resetFP){
128 if (format == "list") {
130 while (fileHandle.eof() != true) {
132 list = new ListVector(fileHandle); m->gobble(fileHandle);
133 thisLabel = list->getLabel();
135 //if you are at the last label
136 if (thisLabel == label) { break; }
137 //so you don't loose this memory
138 else { delete list; }
140 }else{ list = NULL; }
148 catch(exception& e) {
149 m->errorOut(e, "InputData", "getListVector");
154 /***********************************************************************/
156 SharedListVector* InputData::getSharedListVector(){
159 if (format == "shared") {
160 SharedList = new SharedListVector(fileHandle);
161 }else{ SharedList = NULL; }
163 m->gobble(fileHandle);
170 catch(exception& e) {
171 m->errorOut(e, "InputData", "getSharedListVector");
175 /***********************************************************************/
177 SharedListVector* InputData::getSharedListVector(string label){
181 m->openInputFile(filename, in);
185 if (format == "shared") {
187 while (in.eof() != true) {
189 SharedList = new SharedListVector(in);
190 thisLabel = SharedList->getLabel();
192 //if you are at the last label
193 if (thisLabel == label) { break; }
194 //so you don't loose this memory
195 else { delete SharedList; }
199 }else{ SharedList = NULL; }
208 catch(exception& e) {
209 m->errorOut(e, "InputData", "getSharedListVector");
216 /***********************************************************************/
218 SharedOrderVector* InputData::getSharedOrderVector(){
221 if (format == "sharedfile") {
222 SharedOrder = new SharedOrderVector(fileHandle);
223 }else{ SharedOrder = NULL; }
225 m->gobble(fileHandle);
232 catch(exception& e) {
233 m->errorOut(e, "InputData", "getSharedOrderVector");
238 /***********************************************************************/
240 SharedOrderVector* InputData::getSharedOrderVector(string label){
244 m->openInputFile(filename, in);
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")) {
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") {
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);
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);
458 if (format == "sharedfile") {
459 while (in.eof() != true) {
461 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
462 if (SharedRAbund != NULL) {
463 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);
480 if (SharedList != NULL) {
481 thisLabel = SharedList->getLabel();
482 //if you are at the last label
483 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
485 //so you don't loose this memory
496 //this is created to signal to calling function that the input file is at eof
497 vector<SharedRAbundVector*> null; null.push_back(NULL);
502 catch(exception& e) {
503 m->errorOut(e, "InputData", "getSharedRAbundVectors");
508 /***********************************************************************/
509 //this is used when you don't need the order vector
510 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
513 if (format == "relabund") {
514 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle);
515 if (SharedRelAbund != NULL) {
516 return SharedRelAbund->getSharedRAbundFloatVectors();
519 m->gobble(fileHandle);
522 //this is created to signal to calling function that the input file is at eof
523 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
527 catch(exception& e) {
528 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
532 /***********************************************************************/
533 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
538 m->openInputFile(filename, in);
541 if (format == "sharedfile") {
542 while (in.eof() != true) {
544 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
545 if (SharedRelAbund != NULL) {
546 thisLabel = SharedRelAbund->getLabel();
547 //if you are at the last label
548 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
550 //so you don't loose this memory
551 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
552 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
553 delete SharedRelAbund;
561 //this is created to signal to calling function that the input file is at eof
562 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
567 catch(exception& e) {
568 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
572 /***********************************************************************/
574 SAbundVector* InputData::getSAbundVector(){
577 if (format == "list") {
578 input = new ListVector(fileHandle);
580 else if (format == "shared") {
581 input = new SharedListVector(fileHandle);
583 else if(format == "rabund"){
584 input = new RAbundVector(fileHandle);
586 else if(format == "order"){
587 input = new OrderVector(fileHandle);
589 else if(format == "sabund"){
590 input = new SAbundVector(fileHandle);
593 m->gobble(fileHandle);
595 sabund = new SAbundVector();
596 *sabund = (input->getSAbundVector());
604 catch(exception& e) {
605 m->errorOut(e, "InputData", "getSAbundVector");
609 /***********************************************************************/
610 SAbundVector* InputData::getSAbundVector(string label){
615 m->openInputFile(filename, in);
618 if (format == "list") {
620 while (in.eof() != true) {
622 input = new ListVector(in);
623 thisLabel = input->getLabel();
625 //if you are at the last label
626 if (thisLabel == label) { break; }
627 //so you don't loose this memory
628 else { delete input; }
632 else if (format == "shared") {
634 while (in.eof() != true) {
636 input = new SharedListVector(in);
637 thisLabel = input->getLabel();
639 //if you are at the last label
640 if (thisLabel == label) { break; }
641 //so you don't loose this memory
642 else { delete input; }
647 else if(format == "rabund"){
649 while (in.eof() != true) {
651 input = new RAbundVector(in);
652 thisLabel = input->getLabel();
654 //if you are at the last label
655 if (thisLabel == label) { break; }
656 //so you don't loose this memory
657 else { delete input; }
662 else if(format == "order"){
664 while (in.eof() != true) {
666 input = new OrderVector(in);
667 thisLabel = input->getLabel();
669 //if you are at the last label
670 if (thisLabel == label) { break; }
671 //so you don't loose this memory
672 else { delete input; }
677 else if(format == "sabund"){
679 while (in.eof() != true) {
681 input = new SAbundVector(in);
682 thisLabel = input->getLabel();
684 //if you are at the last label
685 if (thisLabel == label) { break; }
686 //so you don't loose this memory
687 else { delete input; }
696 sabund = new SAbundVector();
697 *sabund = (input->getSAbundVector());
706 catch(exception& e) {
707 m->errorOut(e, "InputData", "getSAbundVector");
712 /***********************************************************************/
713 RAbundVector* InputData::getRAbundVector(){
716 if (format == "list") {
717 input = new ListVector(fileHandle);
719 else if (format == "shared") {
720 input = new SharedListVector(fileHandle);
722 else if(format == "rabund"){
723 input = new RAbundVector(fileHandle);
725 else if(format == "order"){
726 input = new OrderVector(fileHandle);
728 else if(format == "sabund"){
729 input = new SAbundVector(fileHandle);
732 m->gobble(fileHandle);
734 rabund = new RAbundVector();
735 *rabund = (input->getRAbundVector());
743 catch(exception& e) {
744 m->errorOut(e, "InputData", "getRAbundVector");
748 /***********************************************************************/
749 RAbundVector* InputData::getRAbundVector(string label){
754 m->openInputFile(filename, in);
757 if (format == "list") {
759 while (in.eof() != true) {
761 input = new ListVector(in);
762 thisLabel = input->getLabel();
764 //if you are at the last label
765 if (thisLabel == label) { break; }
766 //so you don't loose this memory
767 else { delete input; }
771 else if (format == "shared") {
773 while (in.eof() != true) {
775 input = new SharedListVector(in);
776 thisLabel = input->getLabel();
778 //if you are at the last label
779 if (thisLabel == label) { break; }
780 //so you don't loose this memory
781 else { delete input; }
786 else if(format == "rabund"){
788 while (in.eof() != true) {
790 input = new RAbundVector(in);
791 thisLabel = input->getLabel();
793 //if you are at the last label
794 if (thisLabel == label) { break; }
795 //so you don't loose this memory
796 else { delete input; }
801 else if(format == "order"){
803 while (in.eof() != true) {
805 input = new OrderVector(in);
806 thisLabel = input->getLabel();
808 //if you are at the last label
809 if (thisLabel == label) { break; }
810 //so you don't loose this memory
811 else { delete input; }
816 else if(format == "sabund"){
818 while (in.eof() != true) {
820 input = new SAbundVector(in);
821 thisLabel = input->getLabel();
823 //if you are at the last label
824 if (thisLabel == label) { break; }
825 //so you don't loose this memory
826 else { delete input; }
835 rabund = new RAbundVector();
836 *rabund = (input->getRAbundVector());
844 catch(exception& e) {
845 m->errorOut(e, "InputData", "getRAbundVector");
850 /***********************************************************************/