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){
19 openInputFile(fName, fileHandle);
24 /***********************************************************************/
27 InputData::~InputData(){
33 /***********************************************************************/
35 InputData::InputData(string fName, string orderFileName, string f) : format(f){
39 openInputFile(orderFileName, ofHandle);
46 orderMap[name] = count;
52 openInputFile(fName, fileHandle);
55 errorOut(e, "InputData", "InputData");
59 /***********************************************************************/
61 ListVector* InputData::getListVector(){
64 if(format == "list") {
65 list = new ListVector(fileHandle);
76 errorOut(e, "InputData", "getListVector");
81 /***********************************************************************/
83 ListVector* InputData::getListVector(string label){
87 openInputFile(filename, in);
91 if (format == "list") {
93 while (in.eof() != true) {
95 list = new ListVector(in);
96 thisLabel = list->getLabel();
98 //if you are at the last label
99 if (thisLabel == label) { break; }
100 //so you don't loose this memory
101 else { delete list; }
104 }else{ list = NULL; }
113 catch(exception& e) {
114 errorOut(e, "InputData", "getListVector");
120 /***********************************************************************/
122 SharedListVector* InputData::getSharedListVector(){
125 if (format == "shared") {
126 SharedList = new SharedListVector(fileHandle);
127 }else{ SharedList = NULL; }
136 catch(exception& e) {
137 errorOut(e, "InputData", "getSharedListVector");
141 /***********************************************************************/
143 SharedListVector* InputData::getSharedListVector(string label){
147 openInputFile(filename, in);
151 if (format == "shared") {
153 while (in.eof() != true) {
155 SharedList = new SharedListVector(in);
156 thisLabel = SharedList->getLabel();
158 //if you are at the last label
159 if (thisLabel == label) { break; }
160 //so you don't loose this memory
161 else { delete SharedList; }
165 }else{ SharedList = NULL; }
174 catch(exception& e) {
175 errorOut(e, "InputData", "getSharedListVector");
182 /***********************************************************************/
184 SharedOrderVector* InputData::getSharedOrderVector(){
187 if (format == "sharedfile") {
188 SharedOrder = new SharedOrderVector(fileHandle);
189 }else{ SharedOrder = NULL; }
198 catch(exception& e) {
199 errorOut(e, "InputData", "getSharedOrderVector");
204 /***********************************************************************/
206 SharedOrderVector* InputData::getSharedOrderVector(string label){
210 openInputFile(filename, in);
214 if (format == "sharedfile") {
216 while (in.eof() != true) {
218 SharedOrder = new SharedOrderVector(in);
219 thisLabel = SharedOrder->getLabel();
221 //if you are at the last label
222 if (thisLabel == label) { break; }
223 //so you don't loose this memory
224 else { delete SharedOrder; }
228 }else{ SharedOrder = NULL; }
237 catch(exception& e) {
238 errorOut(e, "InputData", "getSharedOrderVector");
245 /***********************************************************************/
247 OrderVector* InputData::getOrderVector(){
250 if((format == "list") || (format == "listorder")) {
251 input = new ListVector(fileHandle);
253 else if (format == "shared") {
254 input = new SharedListVector(fileHandle);
256 else if(format == "rabund"){
257 input = new RAbundVector(fileHandle);
259 else if(format == "order"){
260 input = new OrderVector(fileHandle);
262 else if(format == "sabund"){
263 input = new SAbundVector(fileHandle);
268 output = new OrderVector();
269 *output = (input->getOrderVector());
277 catch(exception& e) {
278 errorOut(e, "InputData", "getOrderVector");
283 /***********************************************************************/
284 OrderVector* InputData::getOrderVector(string label){
289 openInputFile(filename, in);
292 if((format == "list") || (format == "listorder")) {
294 while (in.eof() != true) {
296 input = new ListVector(in);
297 thisLabel = input->getLabel();
299 //if you are at the last label
300 if (thisLabel == label) { break; }
301 //so you don't loose this memory
302 else { delete input; }
306 else if (format == "shared") {
308 while (in.eof() != true) {
310 input = new SharedListVector(in);
311 thisLabel = input->getLabel();
313 //if you are at the last label
314 if (thisLabel == label) { break; }
315 //so you don't loose this memory
316 else { delete input; }
321 else if(format == "rabund"){
323 while (in.eof() != true) {
325 input = new RAbundVector(in);
326 thisLabel = input->getLabel();
328 //if you are at the last label
329 if (thisLabel == label) { break; }
330 //so you don't loose this memory
331 else { delete input; }
336 else if(format == "order"){
338 while (in.eof() != true) {
340 input = new OrderVector(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 == "sabund"){
353 while (in.eof() != true) {
355 input = new SAbundVector(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; }
370 output = new OrderVector();
371 *output = (input->getOrderVector());
380 catch(exception& e) {
381 errorOut(e, "InputData", "getOrderVector");
386 /***********************************************************************/
387 //this is used when you don't need the order vector
388 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
391 if (format == "sharedfile") {
392 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
393 if (SharedRAbund != NULL) {
394 return SharedRAbund->getSharedRAbundVectors();
396 }else if (format == "shared") {
397 SharedList = new SharedListVector(fileHandle);
398 if (SharedList != NULL) {
399 return SharedList->getSharedRAbundVector();
405 //this is created to signal to calling function that the input file is at eof
406 vector<SharedRAbundVector*> null; null.push_back(NULL);
410 catch(exception& e) {
411 errorOut(e, "InputData", "getSharedRAbundVectors");
415 /***********************************************************************/
416 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
421 openInputFile(filename, in);
424 if (format == "sharedfile") {
425 while (in.eof() != true) {
427 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
428 if (SharedRAbund != NULL) {
429 thisLabel = SharedRAbund->getLabel();
430 //if you are at the last label
431 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
433 //so you don't loose this memory
434 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
435 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
442 }else if (format == "shared") {
443 while (in.eof() != true) {
445 SharedList = new SharedListVector(in);
446 if (SharedList != NULL) {
447 thisLabel = SharedList->getLabel();
448 //if you are at the last label
449 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
451 //so you don't loose this memory
462 //this is created to signal to calling function that the input file is at eof
463 vector<SharedRAbundVector*> null; null.push_back(NULL);
468 catch(exception& e) {
469 errorOut(e, "InputData", "getSharedRAbundVectors");
475 /***********************************************************************/
477 SAbundVector* InputData::getSAbundVector(){
480 if (format == "list") {
481 input = new ListVector(fileHandle);
483 else if (format == "shared") {
484 input = new SharedListVector(fileHandle);
486 else if(format == "rabund"){
487 input = new RAbundVector(fileHandle);
489 else if(format == "order"){
490 input = new OrderVector(fileHandle);
492 else if(format == "sabund"){
493 input = new SAbundVector(fileHandle);
498 sabund = new SAbundVector();
499 *sabund = (input->getSAbundVector());
507 catch(exception& e) {
508 errorOut(e, "InputData", "getSAbundVector");
512 /***********************************************************************/
513 SAbundVector* InputData::getSAbundVector(string label){
518 openInputFile(filename, in);
521 if (format == "list") {
523 while (in.eof() != true) {
525 input = new ListVector(in);
526 thisLabel = input->getLabel();
528 //if you are at the last label
529 if (thisLabel == label) { break; }
530 //so you don't loose this memory
531 else { delete input; }
535 else if (format == "shared") {
537 while (in.eof() != true) {
539 input = new SharedListVector(in);
540 thisLabel = input->getLabel();
542 //if you are at the last label
543 if (thisLabel == label) { break; }
544 //so you don't loose this memory
545 else { delete input; }
550 else if(format == "rabund"){
552 while (in.eof() != true) {
554 input = new RAbundVector(in);
555 thisLabel = input->getLabel();
557 //if you are at the last label
558 if (thisLabel == label) { break; }
559 //so you don't loose this memory
560 else { delete input; }
565 else if(format == "order"){
567 while (in.eof() != true) {
569 input = new OrderVector(in);
570 thisLabel = input->getLabel();
572 //if you are at the last label
573 if (thisLabel == label) { break; }
574 //so you don't loose this memory
575 else { delete input; }
580 else if(format == "sabund"){
582 while (in.eof() != true) {
584 input = new SAbundVector(in);
585 thisLabel = input->getLabel();
587 //if you are at the last label
588 if (thisLabel == label) { break; }
589 //so you don't loose this memory
590 else { delete input; }
599 sabund = new SAbundVector();
600 *sabund = (input->getSAbundVector());
609 catch(exception& e) {
610 errorOut(e, "InputData", "getSAbundVector");
615 /***********************************************************************/
616 RAbundVector* InputData::getRAbundVector(){
619 if (format == "list") {
620 input = new ListVector(fileHandle);
622 else if (format == "shared") {
623 input = new SharedListVector(fileHandle);
625 else if(format == "rabund"){
626 input = new RAbundVector(fileHandle);
628 else if(format == "order"){
629 input = new OrderVector(fileHandle);
631 else if(format == "sabund"){
632 input = new SAbundVector(fileHandle);
637 rabund = new RAbundVector();
638 *rabund = (input->getRAbundVector());
646 catch(exception& e) {
647 errorOut(e, "InputData", "getRAbundVector");
651 /***********************************************************************/
652 RAbundVector* InputData::getRAbundVector(string label){
657 openInputFile(filename, in);
660 if (format == "list") {
662 while (in.eof() != true) {
664 input = new ListVector(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; }
674 else if (format == "shared") {
676 while (in.eof() != true) {
678 input = new SharedListVector(in);
679 thisLabel = input->getLabel();
681 //if you are at the last label
682 if (thisLabel == label) { break; }
683 //so you don't loose this memory
684 else { delete input; }
689 else if(format == "rabund"){
691 while (in.eof() != true) {
693 input = new RAbundVector(in);
694 thisLabel = input->getLabel();
696 //if you are at the last label
697 if (thisLabel == label) { break; }
698 //so you don't loose this memory
699 else { delete input; }
704 else if(format == "order"){
706 while (in.eof() != true) {
708 input = new OrderVector(in);
709 thisLabel = input->getLabel();
711 //if you are at the last label
712 if (thisLabel == label) { break; }
713 //so you don't loose this memory
714 else { delete input; }
719 else if(format == "sabund"){
721 while (in.eof() != true) {
723 input = new SAbundVector(in);
724 thisLabel = input->getLabel();
726 //if you are at the last label
727 if (thisLabel == label) { break; }
728 //so you don't loose this memory
729 else { delete input; }
738 rabund = new RAbundVector();
739 *rabund = (input->getRAbundVector());
747 catch(exception& e) {
748 errorOut(e, "InputData", "getRAbundVector");
753 /***********************************************************************/