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 openInputFile(fName, fileHandle);
24 /***********************************************************************/
27 InputData::~InputData(){
33 /***********************************************************************/
35 InputData::InputData(string fName, string orderFileName, string f) : format(f){
37 m = MothurOut::getInstance();
39 openInputFile(orderFileName, ofHandle);
46 orderMap[name] = count;
52 openInputFile(fName, fileHandle);
55 m->errorOut(e, "InputData", "InputData");
59 /***********************************************************************/
61 ListVector* InputData::getListVector(){
63 if(!fileHandle.eof()){
64 if(format == "list") {
65 list = new ListVector(fileHandle);
76 m->errorOut(e, "InputData", "getListVector");
81 /***********************************************************************/
82 ListVector* InputData::getListVector(string label){
86 openInputFile(filename, in);
90 if (format == "list") {
92 while (in.eof() != true) {
94 list = new ListVector(in);
95 thisLabel = list->getLabel();
97 //if you are at the last label
98 if (thisLabel == label) { break; }
99 //so you don't loose this memory
100 else { delete list; }
103 }else{ list = NULL; }
112 catch(exception& e) {
113 m->errorOut(e, "InputData", "getListVector");
117 /***********************************************************************/
118 ListVector* InputData::getListVector(string label, bool resetFP){
126 if (format == "list") {
128 while (fileHandle.eof() != true) {
130 list = new ListVector(fileHandle); gobble(fileHandle);
131 thisLabel = list->getLabel();
133 //if you are at the last label
134 if (thisLabel == label) { break; }
135 //so you don't loose this memory
136 else { delete list; }
138 }else{ list = NULL; }
146 catch(exception& e) {
147 m->errorOut(e, "InputData", "getListVector");
152 /***********************************************************************/
154 SharedListVector* InputData::getSharedListVector(){
157 if (format == "shared") {
158 SharedList = new SharedListVector(fileHandle);
159 }else{ SharedList = NULL; }
168 catch(exception& e) {
169 m->errorOut(e, "InputData", "getSharedListVector");
173 /***********************************************************************/
175 SharedListVector* InputData::getSharedListVector(string label){
179 openInputFile(filename, in);
183 if (format == "shared") {
185 while (in.eof() != true) {
187 SharedList = new SharedListVector(in);
188 thisLabel = SharedList->getLabel();
190 //if you are at the last label
191 if (thisLabel == label) { break; }
192 //so you don't loose this memory
193 else { delete SharedList; }
197 }else{ SharedList = NULL; }
206 catch(exception& e) {
207 m->errorOut(e, "InputData", "getSharedListVector");
214 /***********************************************************************/
216 SharedOrderVector* InputData::getSharedOrderVector(){
219 if (format == "sharedfile") {
220 SharedOrder = new SharedOrderVector(fileHandle);
221 }else{ SharedOrder = NULL; }
230 catch(exception& e) {
231 m->errorOut(e, "InputData", "getSharedOrderVector");
236 /***********************************************************************/
238 SharedOrderVector* InputData::getSharedOrderVector(string label){
242 openInputFile(filename, in);
246 if (format == "sharedfile") {
248 while (in.eof() != true) {
250 SharedOrder = new SharedOrderVector(in);
251 thisLabel = SharedOrder->getLabel();
253 //if you are at the last label
254 if (thisLabel == label) { break; }
255 //so you don't loose this memory
256 else { delete SharedOrder; }
260 }else{ SharedOrder = NULL; }
269 catch(exception& e) {
270 m->errorOut(e, "InputData", "getSharedOrderVector");
277 /***********************************************************************/
279 OrderVector* InputData::getOrderVector(){
282 if((format == "list") || (format == "listorder")) {
283 input = new ListVector(fileHandle);
285 else if (format == "shared") {
286 input = new SharedListVector(fileHandle);
288 else if(format == "rabund"){
289 input = new RAbundVector(fileHandle);
291 else if(format == "order"){
292 input = new OrderVector(fileHandle);
294 else if(format == "sabund"){
295 input = new SAbundVector(fileHandle);
300 output = new OrderVector();
301 *output = (input->getOrderVector());
309 catch(exception& e) {
310 m->errorOut(e, "InputData", "getOrderVector");
315 /***********************************************************************/
316 OrderVector* InputData::getOrderVector(string label){
321 openInputFile(filename, in);
324 if((format == "list") || (format == "listorder")) {
326 while (in.eof() != true) {
328 input = new ListVector(in);
329 thisLabel = input->getLabel();
331 //if you are at the last label
332 if (thisLabel == label) { break; }
333 //so you don't loose this memory
334 else { delete input; }
338 else if (format == "shared") {
340 while (in.eof() != true) {
342 input = new SharedListVector(in);
343 thisLabel = input->getLabel();
345 //if you are at the last label
346 if (thisLabel == label) { break; }
347 //so you don't loose this memory
348 else { delete input; }
353 else if(format == "rabund"){
355 while (in.eof() != true) {
357 input = new RAbundVector(in);
358 thisLabel = input->getLabel();
360 //if you are at the last label
361 if (thisLabel == label) { break; }
362 //so you don't loose this memory
363 else { delete input; }
368 else if(format == "order"){
370 while (in.eof() != true) {
372 input = new OrderVector(in);
373 thisLabel = input->getLabel();
375 //if you are at the last label
376 if (thisLabel == label) { break; }
377 //so you don't loose this memory
378 else { delete input; }
383 else if(format == "sabund"){
385 while (in.eof() != true) {
387 input = new SAbundVector(in);
388 thisLabel = input->getLabel();
390 //if you are at the last label
391 if (thisLabel == label) { break; }
392 //so you don't loose this memory
393 else { delete input; }
402 output = new OrderVector();
403 *output = (input->getOrderVector());
412 catch(exception& e) {
413 m->errorOut(e, "InputData", "getOrderVector");
418 /***********************************************************************/
419 //this is used when you don't need the order vector
420 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
423 if (format == "sharedfile") {
424 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
425 if (SharedRAbund != NULL) {
426 return SharedRAbund->getSharedRAbundVectors();
428 }else if (format == "shared") {
429 SharedList = new SharedListVector(fileHandle);
430 if (SharedList != NULL) {
431 return SharedList->getSharedRAbundVector();
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 openInputFile(filename, in);
456 if (format == "sharedfile") {
457 while (in.eof() != true) {
459 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
460 if (SharedRAbund != NULL) {
461 thisLabel = SharedRAbund->getLabel();
462 //if you are at the last label
463 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
465 //so you don't loose this memory
466 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
467 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
474 }else if (format == "shared") {
475 while (in.eof() != true) {
477 SharedList = new SharedListVector(in);
478 if (SharedList != NULL) {
479 thisLabel = SharedList->getLabel();
480 //if you are at the last label
481 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
483 //so you don't loose this memory
494 //this is created to signal to calling function that the input file is at eof
495 vector<SharedRAbundVector*> null; null.push_back(NULL);
500 catch(exception& e) {
501 m->errorOut(e, "InputData", "getSharedRAbundVectors");
507 /***********************************************************************/
509 SAbundVector* InputData::getSAbundVector(){
512 if (format == "list") {
513 input = new ListVector(fileHandle);
515 else if (format == "shared") {
516 input = new SharedListVector(fileHandle);
518 else if(format == "rabund"){
519 input = new RAbundVector(fileHandle);
521 else if(format == "order"){
522 input = new OrderVector(fileHandle);
524 else if(format == "sabund"){
525 input = new SAbundVector(fileHandle);
530 sabund = new SAbundVector();
531 *sabund = (input->getSAbundVector());
539 catch(exception& e) {
540 m->errorOut(e, "InputData", "getSAbundVector");
544 /***********************************************************************/
545 SAbundVector* InputData::getSAbundVector(string label){
550 openInputFile(filename, in);
553 if (format == "list") {
555 while (in.eof() != true) {
557 input = new ListVector(in);
558 thisLabel = input->getLabel();
560 //if you are at the last label
561 if (thisLabel == label) { break; }
562 //so you don't loose this memory
563 else { delete input; }
567 else if (format == "shared") {
569 while (in.eof() != true) {
571 input = new SharedListVector(in);
572 thisLabel = input->getLabel();
574 //if you are at the last label
575 if (thisLabel == label) { break; }
576 //so you don't loose this memory
577 else { delete input; }
582 else if(format == "rabund"){
584 while (in.eof() != true) {
586 input = new RAbundVector(in);
587 thisLabel = input->getLabel();
589 //if you are at the last label
590 if (thisLabel == label) { break; }
591 //so you don't loose this memory
592 else { delete input; }
597 else if(format == "order"){
599 while (in.eof() != true) {
601 input = new OrderVector(in);
602 thisLabel = input->getLabel();
604 //if you are at the last label
605 if (thisLabel == label) { break; }
606 //so you don't loose this memory
607 else { delete input; }
612 else if(format == "sabund"){
614 while (in.eof() != true) {
616 input = new SAbundVector(in);
617 thisLabel = input->getLabel();
619 //if you are at the last label
620 if (thisLabel == label) { break; }
621 //so you don't loose this memory
622 else { delete input; }
631 sabund = new SAbundVector();
632 *sabund = (input->getSAbundVector());
641 catch(exception& e) {
642 m->errorOut(e, "InputData", "getSAbundVector");
647 /***********************************************************************/
648 RAbundVector* InputData::getRAbundVector(){
651 if (format == "list") {
652 input = new ListVector(fileHandle);
654 else if (format == "shared") {
655 input = new SharedListVector(fileHandle);
657 else if(format == "rabund"){
658 input = new RAbundVector(fileHandle);
660 else if(format == "order"){
661 input = new OrderVector(fileHandle);
663 else if(format == "sabund"){
664 input = new SAbundVector(fileHandle);
669 rabund = new RAbundVector();
670 *rabund = (input->getRAbundVector());
678 catch(exception& e) {
679 m->errorOut(e, "InputData", "getRAbundVector");
683 /***********************************************************************/
684 RAbundVector* InputData::getRAbundVector(string label){
689 openInputFile(filename, in);
692 if (format == "list") {
694 while (in.eof() != true) {
696 input = new ListVector(in);
697 thisLabel = input->getLabel();
699 //if you are at the last label
700 if (thisLabel == label) { break; }
701 //so you don't loose this memory
702 else { delete input; }
706 else if (format == "shared") {
708 while (in.eof() != true) {
710 input = new SharedListVector(in);
711 thisLabel = input->getLabel();
713 //if you are at the last label
714 if (thisLabel == label) { break; }
715 //so you don't loose this memory
716 else { delete input; }
721 else if(format == "rabund"){
723 while (in.eof() != true) {
725 input = new RAbundVector(in);
726 thisLabel = input->getLabel();
728 //if you are at the last label
729 if (thisLabel == label) { break; }
730 //so you don't loose this memory
731 else { delete input; }
736 else if(format == "order"){
738 while (in.eof() != true) {
740 input = new OrderVector(in);
741 thisLabel = input->getLabel();
743 //if you are at the last label
744 if (thisLabel == label) { break; }
745 //so you don't loose this memory
746 else { delete input; }
751 else if(format == "sabund"){
753 while (in.eof() != true) {
755 input = new SAbundVector(in);
756 thisLabel = input->getLabel();
758 //if you are at the last label
759 if (thisLabel == label) { break; }
760 //so you don't loose this memory
761 else { delete input; }
770 rabund = new RAbundVector();
771 *rabund = (input->getRAbundVector());
779 catch(exception& e) {
780 m->errorOut(e, "InputData", "getRAbundVector");
785 /***********************************************************************/