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 = "";
24 /***********************************************************************/
26 InputData::~InputData(){
28 m->saveNextLabel = "";
31 /***********************************************************************/
33 InputData::InputData(string fName, string orderFileName, string f) : format(f){
35 m = MothurOut::getInstance();
37 m->openInputFile(orderFileName, ofHandle);
44 orderMap[name] = count;
50 m->openInputFile(fName, fileHandle);
53 m->errorOut(e, "InputData", "InputData");
57 /***********************************************************************/
59 ListVector* InputData::getListVector(){
61 if(!fileHandle.eof()){
62 if(format == "list") {
63 list = new ListVector(fileHandle);
66 m->gobble(fileHandle);
74 m->errorOut(e, "InputData", "getListVector");
79 /***********************************************************************/
80 ListVector* InputData::getListVector(string label){
84 m->openInputFile(filename, in);
88 if (format == "list") {
90 while (in.eof() != true) {
92 list = new ListVector(in);
93 thisLabel = list->getLabel();
95 //if you are at the last label
96 if (thisLabel == label) { break; }
97 //so you don't loose this memory
101 }else{ list = NULL; }
110 catch(exception& e) {
111 m->errorOut(e, "InputData", "getListVector");
115 /***********************************************************************/
116 ListVector* InputData::getListVector(string label, bool resetFP){
124 if (format == "list") {
126 while (fileHandle.eof() != true) {
128 list = new ListVector(fileHandle); m->gobble(fileHandle);
129 thisLabel = list->getLabel();
131 //if you are at the last label
132 if (thisLabel == label) { break; }
133 //so you don't loose this memory
134 else { delete list; }
136 }else{ list = NULL; }
144 catch(exception& e) {
145 m->errorOut(e, "InputData", "getListVector");
150 /***********************************************************************/
152 SharedListVector* InputData::getSharedListVector(){
155 if (format == "shared") {
156 SharedList = new SharedListVector(fileHandle);
157 }else{ SharedList = NULL; }
159 m->gobble(fileHandle);
166 catch(exception& e) {
167 m->errorOut(e, "InputData", "getSharedListVector");
171 /***********************************************************************/
173 SharedListVector* InputData::getSharedListVector(string label){
177 m->openInputFile(filename, in);
181 if (format == "shared") {
183 while (in.eof() != true) {
185 SharedList = new SharedListVector(in);
186 thisLabel = SharedList->getLabel();
188 //if you are at the last label
189 if (thisLabel == label) { break; }
190 //so you don't loose this memory
191 else { delete SharedList; }
195 }else{ SharedList = NULL; }
204 catch(exception& e) {
205 m->errorOut(e, "InputData", "getSharedListVector");
212 /***********************************************************************/
214 SharedOrderVector* InputData::getSharedOrderVector(){
217 if (format == "sharedfile") {
218 SharedOrder = new SharedOrderVector(fileHandle);
219 }else{ SharedOrder = NULL; }
221 m->gobble(fileHandle);
228 catch(exception& e) {
229 m->errorOut(e, "InputData", "getSharedOrderVector");
234 /***********************************************************************/
236 SharedOrderVector* InputData::getSharedOrderVector(string label){
240 m->openInputFile(filename, in);
244 if (format == "sharedfile") {
246 while (in.eof() != true) {
248 SharedOrder = new SharedOrderVector(in);
249 thisLabel = SharedOrder->getLabel();
251 //if you are at the last label
252 if (thisLabel == label) { break; }
253 //so you don't loose this memory
254 else { delete SharedOrder; }
258 }else{ SharedOrder = NULL; }
267 catch(exception& e) {
268 m->errorOut(e, "InputData", "getSharedOrderVector");
275 /***********************************************************************/
277 OrderVector* InputData::getOrderVector(){
280 if((format == "list") || (format == "listorder")) {
281 input = new ListVector(fileHandle);
283 else if (format == "shared") {
284 input = new SharedListVector(fileHandle);
286 else if(format == "rabund"){
287 input = new RAbundVector(fileHandle);
289 else if(format == "order"){
290 input = new OrderVector(fileHandle);
292 else if(format == "sabund"){
293 input = new SAbundVector(fileHandle);
296 m->gobble(fileHandle);
298 output = new OrderVector();
299 *output = (input->getOrderVector());
307 catch(exception& e) {
308 m->errorOut(e, "InputData", "getOrderVector");
313 /***********************************************************************/
314 OrderVector* InputData::getOrderVector(string label){
319 m->openInputFile(filename, in);
322 if((format == "list") || (format == "listorder")) {
324 while (in.eof() != true) {
326 input = new ListVector(in);
327 thisLabel = input->getLabel();
329 //if you are at the last label
330 if (thisLabel == label) { break; }
331 //so you don't loose this memory
332 else { delete input; }
336 else if (format == "shared") {
338 while (in.eof() != true) {
340 input = new SharedListVector(in);
341 thisLabel = input->getLabel();
343 //if you are at the last label
344 if (thisLabel == label) { break; }
345 //so you don't loose this memory
346 else { delete input; }
351 else if(format == "rabund"){
353 while (in.eof() != true) {
355 input = new RAbundVector(in);
356 thisLabel = input->getLabel();
358 //if you are at the last label
359 if (thisLabel == label) { break; }
360 //so you don't loose this memory
361 else { delete input; }
366 else if(format == "order"){
368 while (in.eof() != true) {
370 input = new OrderVector(in);
371 thisLabel = input->getLabel();
373 //if you are at the last label
374 if (thisLabel == label) { break; }
375 //so you don't loose this memory
376 else { delete input; }
381 else if(format == "sabund"){
383 while (in.eof() != true) {
385 input = new SAbundVector(in);
386 thisLabel = input->getLabel();
388 //if you are at the last label
389 if (thisLabel == label) { break; }
390 //so you don't loose this memory
391 else { delete input; }
400 output = new OrderVector();
401 *output = (input->getOrderVector());
410 catch(exception& e) {
411 m->errorOut(e, "InputData", "getOrderVector");
416 /***********************************************************************/
417 //this is used when you don't need the order vector
418 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
421 if (format == "sharedfile") {
422 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
423 if (SharedRAbund != NULL) {
424 return SharedRAbund->getSharedRAbundVectors();
426 }else if (format == "shared") {
427 SharedList = new SharedListVector(fileHandle);
429 if (SharedList != NULL) {
430 return SharedList->getSharedRAbundVector();
433 m->gobble(fileHandle);
436 //this is created to signal to calling function that the input file is at eof
437 vector<SharedRAbundVector*> null; null.push_back(NULL);
441 catch(exception& e) {
442 m->errorOut(e, "InputData", "getSharedRAbundVectors");
446 /***********************************************************************/
447 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
452 m->openInputFile(filename, in);
453 m->saveNextLabel = "";
456 if (format == "sharedfile") {
457 while (in.eof() != true) {
459 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
460 if (SharedRAbund != NULL) {
461 thisLabel = SharedRAbund->getLabel();
463 //if you are at the last label
464 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
466 //so you don't loose this memory
467 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
468 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
475 }else if (format == "shared") {
476 while (in.eof() != true) {
478 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();
518 }else if (format == "sharedfile") {
519 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
520 if (SharedRAbund != NULL) {
521 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
522 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
523 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
528 m->gobble(fileHandle);
531 //this is created to signal to calling function that the input file is at eof
532 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
536 catch(exception& e) {
537 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
541 /***********************************************************************/
542 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
547 m->openInputFile(filename, in);
548 m->saveNextLabel = "";
551 if (format == "relabund") {
552 while (in.eof() != true) {
554 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
555 if (SharedRelAbund != NULL) {
556 thisLabel = SharedRelAbund->getLabel();
557 //if you are at the last label
558 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
560 //so you don't loose this memory
561 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
562 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
563 delete SharedRelAbund;
568 }else if (format == "sharedfile") {
569 while (in.eof() != true) {
571 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
572 if (SharedRAbund != NULL) {
573 thisLabel = SharedRAbund->getLabel();
575 //if you are at the last label
576 if (thisLabel == label) {
578 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
579 vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup);
580 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
583 //so you don't loose this memory
584 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
585 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
595 //this is created to signal to calling function that the input file is at eof
596 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
601 catch(exception& e) {
602 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
606 /***********************************************************************/
608 SAbundVector* InputData::getSAbundVector(){
611 if (format == "list") {
612 input = new ListVector(fileHandle);
614 else if (format == "shared") {
615 input = new SharedListVector(fileHandle);
617 else if(format == "rabund"){
618 input = new RAbundVector(fileHandle);
620 else if(format == "order"){
621 input = new OrderVector(fileHandle);
623 else if(format == "sabund"){
624 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; }
869 rabund = new RAbundVector();
870 *rabund = (input->getRAbundVector());
878 catch(exception& e) {
879 m->errorOut(e, "InputData", "getRAbundVector");
884 /***********************************************************************/