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);
626 m->gobble(fileHandle);
628 sabund = new SAbundVector();
629 *sabund = (input->getSAbundVector());
637 catch(exception& e) {
638 m->errorOut(e, "InputData", "getSAbundVector");
642 /***********************************************************************/
643 SAbundVector* InputData::getSAbundVector(string label){
648 m->openInputFile(filename, in);
651 if (format == "list") {
653 while (in.eof() != true) {
655 input = new ListVector(in);
656 thisLabel = input->getLabel();
658 //if you are at the last label
659 if (thisLabel == label) { break; }
660 //so you don't loose this memory
661 else { delete input; }
665 else if (format == "shared") {
667 while (in.eof() != true) {
669 input = new SharedListVector(in);
670 thisLabel = input->getLabel();
672 //if you are at the last label
673 if (thisLabel == label) { break; }
674 //so you don't loose this memory
675 else { delete input; }
680 else if(format == "rabund"){
682 while (in.eof() != true) {
684 input = new RAbundVector(in);
685 thisLabel = input->getLabel();
687 //if you are at the last label
688 if (thisLabel == label) { break; }
689 //so you don't loose this memory
690 else { delete input; }
695 else if(format == "order"){
697 while (in.eof() != true) {
699 input = new OrderVector(in);
700 thisLabel = input->getLabel();
702 //if you are at the last label
703 if (thisLabel == label) { break; }
704 //so you don't loose this memory
705 else { delete input; }
710 else if(format == "sabund"){
712 while (in.eof() != true) {
714 input = new SAbundVector(in);
715 thisLabel = input->getLabel();
717 //if you are at the last label
718 if (thisLabel == label) { break; }
719 //so you don't loose this memory
720 else { delete input; }
729 sabund = new SAbundVector();
730 *sabund = (input->getSAbundVector());
739 catch(exception& e) {
740 m->errorOut(e, "InputData", "getSAbundVector");
745 /***********************************************************************/
746 RAbundVector* InputData::getRAbundVector(){
749 if (format == "list") {
750 input = new ListVector(fileHandle);
752 else if (format == "shared") {
753 input = new SharedListVector(fileHandle);
755 else if(format == "rabund"){
756 input = new RAbundVector(fileHandle);
758 else if(format == "order"){
759 input = new OrderVector(fileHandle);
761 else if(format == "sabund"){
762 input = new SAbundVector(fileHandle);
765 m->gobble(fileHandle);
767 rabund = new RAbundVector();
768 *rabund = (input->getRAbundVector());
776 catch(exception& e) {
777 m->errorOut(e, "InputData", "getRAbundVector");
781 /***********************************************************************/
782 RAbundVector* InputData::getRAbundVector(string label){
787 m->openInputFile(filename, in);
790 if (format == "list") {
792 while (in.eof() != true) {
794 input = new ListVector(in);
795 thisLabel = input->getLabel();
797 //if you are at the last label
798 if (thisLabel == label) { break; }
799 //so you don't loose this memory
800 else { delete input; }
804 else if (format == "shared") {
806 while (in.eof() != true) {
808 input = new SharedListVector(in);
809 thisLabel = input->getLabel();
811 //if you are at the last label
812 if (thisLabel == label) { break; }
813 //so you don't loose this memory
814 else { delete input; }
819 else if(format == "rabund"){
821 while (in.eof() != true) {
823 input = new RAbundVector(in);
824 thisLabel = input->getLabel();
826 //if you are at the last label
827 if (thisLabel == label) { break; }
828 //so you don't loose this memory
829 else { delete input; }
834 else if(format == "order"){
836 while (in.eof() != true) {
838 input = new OrderVector(in);
839 thisLabel = input->getLabel();
841 //if you are at the last label
842 if (thisLabel == label) { break; }
843 //so you don't loose this memory
844 else { delete input; }
849 else if(format == "sabund"){
851 while (in.eof() != true) {
853 input = new SAbundVector(in);
854 thisLabel = input->getLabel();
856 //if you are at the last label
857 if (thisLabel == label) { break; }
858 //so you don't loose this memory
859 else { delete input; }
869 rabund = new RAbundVector();
870 *rabund = (input->getRAbundVector());
878 catch(exception& e) {
879 m->errorOut(e, "InputData", "getRAbundVector");
884 /***********************************************************************/