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; }
113 catch(exception& e) {
114 errorOut(e, "InputData", "getListVector");
120 /***********************************************************************/
122 SharedListVector* InputData::getSharedListVector(){
125 if (format == "shared") {
126 SharedList = new SharedListVector(fileHandle);
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; }
174 catch(exception& e) {
175 errorOut(e, "InputData", "getSharedListVector");
182 /***********************************************************************/
184 SharedOrderVector* InputData::getSharedOrderVector(){
187 if (format == "sharedfile") {
188 SharedOrder = new SharedOrderVector(fileHandle);
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; }
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);
267 output = new OrderVector();
268 *output = (input->getOrderVector());
276 catch(exception& e) {
277 errorOut(e, "InputData", "getOrderVector");
282 /***********************************************************************/
283 OrderVector* InputData::getOrderVector(string label){
288 openInputFile(filename, in);
291 if((format == "list") || (format == "listorder")) {
293 while (in.eof() != true) {
295 input = new ListVector(in);
296 thisLabel = input->getLabel();
298 //if you are at the last label
299 if (thisLabel == label) { break; }
300 //so you don't loose this memory
301 else { delete input; }
305 else if (format == "shared") {
307 while (in.eof() != true) {
309 input = new SharedListVector(in);
310 thisLabel = input->getLabel();
312 //if you are at the last label
313 if (thisLabel == label) { break; }
314 //so you don't loose this memory
315 else { delete input; }
320 else if(format == "rabund"){
322 while (in.eof() != true) {
324 input = new RAbundVector(in);
325 thisLabel = input->getLabel();
327 //if you are at the last label
328 if (thisLabel == label) { break; }
329 //so you don't loose this memory
330 else { delete input; }
335 else if(format == "order"){
337 while (in.eof() != true) {
339 input = new OrderVector(in);
340 thisLabel = input->getLabel();
342 //if you are at the last label
343 if (thisLabel == label) { break; }
344 //so you don't loose this memory
345 else { delete input; }
350 else if(format == "sabund"){
352 while (in.eof() != true) {
354 input = new SAbundVector(in);
355 thisLabel = input->getLabel();
357 //if you are at the last label
358 if (thisLabel == label) { break; }
359 //so you don't loose this memory
360 else { delete input; }
369 output = new OrderVector();
370 *output = (input->getOrderVector());
379 catch(exception& e) {
380 errorOut(e, "InputData", "getOrderVector");
385 /***********************************************************************/
386 //this is used when you don't need the order vector
387 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
390 if (format == "sharedfile") {
391 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
392 if (SharedRAbund != NULL) {
393 return SharedRAbund->getSharedRAbundVectors();
395 }else if (format == "shared") {
396 SharedList = new SharedListVector(fileHandle);
397 if (SharedList != NULL) {
398 return SharedList->getSharedRAbundVector();
404 //this is created to signal to calling function that the input file is at eof
405 vector<SharedRAbundVector*> null; null.push_back(NULL);
409 catch(exception& e) {
410 errorOut(e, "InputData", "getSharedRAbundVectors");
414 /***********************************************************************/
415 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
420 openInputFile(filename, in);
423 if (format == "sharedfile") {
424 while (in.eof() != true) {
426 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
427 if (SharedRAbund != NULL) {
428 thisLabel = SharedRAbund->getLabel();
429 //if you are at the last label
430 if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); }
432 //so you don't loose this memory
433 vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors();
434 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
441 }else if (format == "shared") {
442 while (in.eof() != true) {
444 SharedList = new SharedListVector(in);
445 if (SharedList != NULL) {
446 thisLabel = SharedList->getLabel();
447 //if you are at the last label
448 if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); }
450 //so you don't loose this memory
461 //this is created to signal to calling function that the input file is at eof
462 vector<SharedRAbundVector*> null; null.push_back(NULL);
467 catch(exception& e) {
468 errorOut(e, "InputData", "getSharedRAbundVectors");
474 /***********************************************************************/
476 SAbundVector* InputData::getSAbundVector(){
479 if (format == "list") {
480 input = new ListVector(fileHandle);
482 else if (format == "shared") {
483 input = new SharedListVector(fileHandle);
485 else if(format == "rabund"){
486 input = new RAbundVector(fileHandle);
488 else if(format == "order"){
489 input = new OrderVector(fileHandle);
491 else if(format == "sabund"){
492 input = new SAbundVector(fileHandle);
497 sabund = new SAbundVector();
498 *sabund = (input->getSAbundVector());
506 catch(exception& e) {
507 errorOut(e, "InputData", "getSAbundVector");
511 /***********************************************************************/
512 SAbundVector* InputData::getSAbundVector(string label){
517 openInputFile(filename, in);
520 if (format == "list") {
522 while (in.eof() != true) {
524 input = new ListVector(in);
525 thisLabel = input->getLabel();
527 //if you are at the last label
528 if (thisLabel == label) { break; }
529 //so you don't loose this memory
530 else { delete input; }
534 else if (format == "shared") {
536 while (in.eof() != true) {
538 input = new SharedListVector(in);
539 thisLabel = input->getLabel();
541 //if you are at the last label
542 if (thisLabel == label) { break; }
543 //so you don't loose this memory
544 else { delete input; }
549 else if(format == "rabund"){
551 while (in.eof() != true) {
553 input = new RAbundVector(in);
554 thisLabel = input->getLabel();
556 //if you are at the last label
557 if (thisLabel == label) { break; }
558 //so you don't loose this memory
559 else { delete input; }
564 else if(format == "order"){
566 while (in.eof() != true) {
568 input = new OrderVector(in);
569 thisLabel = input->getLabel();
571 //if you are at the last label
572 if (thisLabel == label) { break; }
573 //so you don't loose this memory
574 else { delete input; }
579 else if(format == "sabund"){
581 while (in.eof() != true) {
583 input = new SAbundVector(in);
584 thisLabel = input->getLabel();
586 //if you are at the last label
587 if (thisLabel == label) { break; }
588 //so you don't loose this memory
589 else { delete input; }
598 sabund = new SAbundVector();
599 *sabund = (input->getSAbundVector());
608 catch(exception& e) {
609 errorOut(e, "InputData", "getSAbundVector");
614 /***********************************************************************/
615 RAbundVector* InputData::getRAbundVector(){
618 if (format == "list") {
619 input = new ListVector(fileHandle);
621 else if (format == "shared") {
622 input = new SharedListVector(fileHandle);
624 else if(format == "rabund"){
625 input = new RAbundVector(fileHandle);
627 else if(format == "order"){
628 input = new OrderVector(fileHandle);
630 else if(format == "sabund"){
631 input = new SAbundVector(fileHandle);
636 rabund = new RAbundVector();
637 *rabund = (input->getRAbundVector());
645 catch(exception& e) {
646 errorOut(e, "InputData", "getRAbundVector");
650 /***********************************************************************/
651 RAbundVector* InputData::getRAbundVector(string label){
656 openInputFile(filename, in);
659 if (format == "list") {
661 while (in.eof() != true) {
663 input = new ListVector(in);
664 thisLabel = input->getLabel();
666 //if you are at the last label
667 if (thisLabel == label) { break; }
668 //so you don't loose this memory
669 else { delete input; }
673 else if (format == "shared") {
675 while (in.eof() != true) {
677 input = new SharedListVector(in);
678 thisLabel = input->getLabel();
680 //if you are at the last label
681 if (thisLabel == label) { break; }
682 //so you don't loose this memory
683 else { delete input; }
688 else if(format == "rabund"){
690 while (in.eof() != true) {
692 input = new RAbundVector(in);
693 thisLabel = input->getLabel();
695 //if you are at the last label
696 if (thisLabel == label) { break; }
697 //so you don't loose this memory
698 else { delete input; }
703 else if(format == "order"){
705 while (in.eof() != true) {
707 input = new OrderVector(in);
708 thisLabel = input->getLabel();
710 //if you are at the last label
711 if (thisLabel == label) { break; }
712 //so you don't loose this memory
713 else { delete input; }
718 else if(format == "sabund"){
720 while (in.eof() != true) {
722 input = new SAbundVector(in);
723 thisLabel = input->getLabel();
725 //if you are at the last label
726 if (thisLabel == label) { break; }
727 //so you don't loose this memory
728 else { delete input; }
737 rabund = new RAbundVector();
738 *rabund = (input->getRAbundVector());
746 catch(exception& e) {
747 errorOut(e, "InputData", "getRAbundVector");
752 /***********************************************************************/