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(){
33 /***********************************************************************/
35 InputData::InputData(string fName, string orderFileName, string f) : format(f){
37 m = MothurOut::getInstance();
39 m->openInputFile(orderFileName, ofHandle);
46 orderMap[name] = count;
52 m->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);
68 m->gobble(fileHandle);
76 m->errorOut(e, "InputData", "getListVector");
81 /***********************************************************************/
82 ListVector* InputData::getListVector(string label){
86 m->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); m->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; }
161 m->gobble(fileHandle);
168 catch(exception& e) {
169 m->errorOut(e, "InputData", "getSharedListVector");
173 /***********************************************************************/
175 SharedListVector* InputData::getSharedListVector(string label){
179 m->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; }
223 m->gobble(fileHandle);
230 catch(exception& e) {
231 m->errorOut(e, "InputData", "getSharedOrderVector");
236 /***********************************************************************/
238 SharedOrderVector* InputData::getSharedOrderVector(string label){
242 m->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);
298 m->gobble(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 m->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();
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);
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");
506 /***********************************************************************/
507 //this is used when you don't need the order vector
508 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
511 if (format == "relabund") {
512 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle);
513 if (SharedRelAbund != NULL) {
514 return SharedRelAbund->getSharedRAbundFloatVectors();
517 m->gobble(fileHandle);
520 //this is created to signal to calling function that the input file is at eof
521 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
525 catch(exception& e) {
526 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
530 /***********************************************************************/
531 vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
536 m->openInputFile(filename, in);
539 if (format == "sharedfile") {
540 while (in.eof() != true) {
542 SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
543 if (SharedRelAbund != NULL) {
544 thisLabel = SharedRelAbund->getLabel();
545 //if you are at the last label
546 if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); }
548 //so you don't loose this memory
549 vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors();
550 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
551 delete SharedRelAbund;
559 //this is created to signal to calling function that the input file is at eof
560 vector<SharedRAbundFloatVector*> null; null.push_back(NULL);
565 catch(exception& e) {
566 m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
570 /***********************************************************************/
572 SAbundVector* InputData::getSAbundVector(){
575 if (format == "list") {
576 input = new ListVector(fileHandle);
578 else if (format == "shared") {
579 input = new SharedListVector(fileHandle);
581 else if(format == "rabund"){
582 input = new RAbundVector(fileHandle);
584 else if(format == "order"){
585 input = new OrderVector(fileHandle);
587 else if(format == "sabund"){
588 input = new SAbundVector(fileHandle);
591 m->gobble(fileHandle);
593 sabund = new SAbundVector();
594 *sabund = (input->getSAbundVector());
602 catch(exception& e) {
603 m->errorOut(e, "InputData", "getSAbundVector");
607 /***********************************************************************/
608 SAbundVector* InputData::getSAbundVector(string label){
613 m->openInputFile(filename, in);
616 if (format == "list") {
618 while (in.eof() != true) {
620 input = new ListVector(in);
621 thisLabel = input->getLabel();
623 //if you are at the last label
624 if (thisLabel == label) { break; }
625 //so you don't loose this memory
626 else { delete input; }
630 else if (format == "shared") {
632 while (in.eof() != true) {
634 input = new SharedListVector(in);
635 thisLabel = input->getLabel();
637 //if you are at the last label
638 if (thisLabel == label) { break; }
639 //so you don't loose this memory
640 else { delete input; }
645 else if(format == "rabund"){
647 while (in.eof() != true) {
649 input = new RAbundVector(in);
650 thisLabel = input->getLabel();
652 //if you are at the last label
653 if (thisLabel == label) { break; }
654 //so you don't loose this memory
655 else { delete input; }
660 else if(format == "order"){
662 while (in.eof() != true) {
664 input = new OrderVector(in);
665 thisLabel = input->getLabel();
667 //if you are at the last label
668 if (thisLabel == label) { break; }
669 //so you don't loose this memory
670 else { delete input; }
675 else if(format == "sabund"){
677 while (in.eof() != true) {
679 input = new SAbundVector(in);
680 thisLabel = input->getLabel();
682 //if you are at the last label
683 if (thisLabel == label) { break; }
684 //so you don't loose this memory
685 else { delete input; }
694 sabund = new SAbundVector();
695 *sabund = (input->getSAbundVector());
704 catch(exception& e) {
705 m->errorOut(e, "InputData", "getSAbundVector");
710 /***********************************************************************/
711 RAbundVector* InputData::getRAbundVector(){
714 if (format == "list") {
715 input = new ListVector(fileHandle);
717 else if (format == "shared") {
718 input = new SharedListVector(fileHandle);
720 else if(format == "rabund"){
721 input = new RAbundVector(fileHandle);
723 else if(format == "order"){
724 input = new OrderVector(fileHandle);
726 else if(format == "sabund"){
727 input = new SAbundVector(fileHandle);
730 m->gobble(fileHandle);
732 rabund = new RAbundVector();
733 *rabund = (input->getRAbundVector());
741 catch(exception& e) {
742 m->errorOut(e, "InputData", "getRAbundVector");
746 /***********************************************************************/
747 RAbundVector* InputData::getRAbundVector(string label){
752 m->openInputFile(filename, in);
755 if (format == "list") {
757 while (in.eof() != true) {
759 input = new ListVector(in);
760 thisLabel = input->getLabel();
762 //if you are at the last label
763 if (thisLabel == label) { break; }
764 //so you don't loose this memory
765 else { delete input; }
769 else if (format == "shared") {
771 while (in.eof() != true) {
773 input = new SharedListVector(in);
774 thisLabel = input->getLabel();
776 //if you are at the last label
777 if (thisLabel == label) { break; }
778 //so you don't loose this memory
779 else { delete input; }
784 else if(format == "rabund"){
786 while (in.eof() != true) {
788 input = new RAbundVector(in);
789 thisLabel = input->getLabel();
791 //if you are at the last label
792 if (thisLabel == label) { break; }
793 //so you don't loose this memory
794 else { delete input; }
799 else if(format == "order"){
801 while (in.eof() != true) {
803 input = new OrderVector(in);
804 thisLabel = input->getLabel();
806 //if you are at the last label
807 if (thisLabel == label) { break; }
808 //so you don't loose this memory
809 else { delete input; }
814 else if(format == "sabund"){
816 while (in.eof() != true) {
818 input = new SAbundVector(in);
819 thisLabel = input->getLabel();
821 //if you are at the last label
822 if (thisLabel == label) { break; }
823 //so you don't loose this memory
824 else { delete input; }
833 rabund = new RAbundVector();
834 *rabund = (input->getRAbundVector());
842 catch(exception& e) {
843 m->errorOut(e, "InputData", "getRAbundVector");
848 /***********************************************************************/