X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=cbf44ed11a96a03c251fcc3025b185c2020c2830;hb=c53c53b0280452e1c3a087fbf807b2e508cd66c4;hp=e5513ab99610f79762f0809c886cf326ad2cda5e;hpb=fd282e6b4be2560f5b1bd154a9e8d24b798eefaf;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index e5513ab..cbf44ed 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -3,20 +3,21 @@ * Dotur * * Created by Sarah Westcott on 11/18/08. - * Copyright 2008 __MyCompanyName__. All rights reserved. + * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. * */ #include "inputdata.h" #include "ordervector.hpp" #include "listvector.hpp" -#include "utilities.hpp" +#include "rabundvector.hpp" /***********************************************************************/ InputData::InputData(string fName, string f) : format(f){ openInputFile(fName, fileHandle); + filename = fName; } @@ -24,7 +25,7 @@ InputData::InputData(string fName, string f) : format(f){ InputData::~InputData(){ - + fileHandle.close(); // delete output; } @@ -33,6 +34,7 @@ InputData::~InputData(){ InputData::InputData(string fName, string orderFileName, string f) : format(f){ try { + ifstream ofHandle; openInputFile(orderFileName, ofHandle); string name; @@ -50,13 +52,9 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ openInputFile(fName, fileHandle); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "InputData", "InputData"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -71,25 +69,60 @@ ListVector* InputData::getListVector(){ return list; } else{ - return 0; + return NULL; } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "InputData", "getListVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} + +/***********************************************************************/ + +ListVector* InputData::getListVector(string label){ + try { + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + + if (format == "list") { + + while (in.eof() != true) { + + list = new ListVector(in); + thisLabel = list->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete list; } + gobble(in); + } + } + + in.close(); + return list; + } + else{ + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getListVector"); exit(1); - } + } } + /***********************************************************************/ SharedListVector* InputData::getSharedListVector(){ try { if(fileHandle){ - if (format == "shared"){ + if (format == "shared") { SharedList = new SharedListVector(fileHandle); } @@ -97,29 +130,127 @@ SharedListVector* InputData::getSharedListVector(){ return SharedList; } else{ - return 0; + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getSharedListVector"); + exit(1); + } +} +/***********************************************************************/ + +SharedListVector* InputData::getSharedListVector(string label){ + try { + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + + if (format == "shared") { + + while (in.eof() != true) { + + SharedList = new SharedListVector(in); + thisLabel = SharedList->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete SharedList; } + gobble(in); + } + + } + + in.close(); + return SharedList; + + }else{ + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getSharedListVector"); + exit(1); + } +} + + + +/***********************************************************************/ + +SharedOrderVector* InputData::getSharedOrderVector(){ + try { + if(fileHandle){ + if (format == "sharedfile") { + SharedOrder = new SharedOrderVector(fileHandle); + } + + gobble(fileHandle); + return SharedOrder; + + }else{ + return NULL; } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "InputData", "getSharedOrderVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} + +/***********************************************************************/ + +SharedOrderVector* InputData::getSharedOrderVector(string label){ + try { + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + + if (format == "sharedfile") { + + while (in.eof() != true) { + + SharedOrder = new SharedOrderVector(in); + thisLabel = SharedOrder->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete SharedOrder; } + gobble(in); + } + + } + + in.close(); + return SharedOrder; + + }else{ + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getSharedOrderVector"); exit(1); - } + } } + /***********************************************************************/ OrderVector* InputData::getOrderVector(){ try { if(fileHandle){ - if(format == "list") { + if((format == "list") || (format == "listorder")) { input = new ListVector(fileHandle); } - else if(format == "shared") { + else if (format == "shared") { input = new SharedListVector(fileHandle); } else if(format == "rabund"){ @@ -131,30 +262,215 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - else if(format == "listorder"){ - input = new ListVector(fileHandle); - } - + gobble(fileHandle); output = new OrderVector(); *output = (input->getOrderVector()); - //delete input; + + return output; + } + else{ + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getOrderVector"); + exit(1); + } +} + +/***********************************************************************/ +OrderVector* InputData::getOrderVector(string label){ + try { + + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + if((format == "list") || (format == "listorder")) { + + while (in.eof() != true) { + + input = new ListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + } + else if (format == "shared") { + + while (in.eof() != true) { + + input = new SharedListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "rabund"){ + + while (in.eof() != true) { + + input = new RAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "order"){ + + while (in.eof() != true) { + + input = new OrderVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "sabund"){ + + while (in.eof() != true) { + + input = new SAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + + } + + } + + in.close(); + + output = new OrderVector(); + *output = (input->getOrderVector()); + return output; + } else{ - return 0; + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getOrderVector"); + exit(1); + } +} + +/***********************************************************************/ +//this is used when you don't need the order vector +vector InputData::getSharedRAbundVectors(){ + try { + if(fileHandle){ + if (format == "sharedfile") { + SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle); + if (SharedRAbund != NULL) { + return SharedRAbund->getSharedRAbundVectors(); + } + }else if (format == "shared") { + SharedList = new SharedListVector(fileHandle); + if (SharedList != NULL) { + return SharedList->getSharedRAbundVector(); + } + } + gobble(fileHandle); } + + //this is created to signal to calling function that the input file is at eof + vector null; null.push_back(NULL); + return null; + } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "InputData", "getSharedRAbundVectors"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +/***********************************************************************/ +vector InputData::getSharedRAbundVectors(string label){ + try { + ifstream in; + string thisLabel; + + openInputFile(filename, in); + + if(in){ + if (format == "sharedfile") { + while (in.eof() != true) { + + SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in); + if (SharedRAbund != NULL) { + thisLabel = SharedRAbund->getLabel(); + //if you are at the last label + if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); } + else { + //so you don't loose this memory + vector lookup = SharedRAbund->getSharedRAbundVectors(); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete SharedRAbund; + } + }else{ break; } + gobble(in); + + } + }else if (format == "shared") { + while (in.eof() != true) { + + SharedList = new SharedListVector(in); + if (SharedList != NULL) { + thisLabel = SharedList->getLabel(); + //if you are at the last label + if (thisLabel == label) { in.close(); return SharedList->getSharedRAbundVector(); } + else { + //so you don't loose this memory + delete SharedList; + } + }else{ break; } + gobble(in); + + } + + } + } + + //this is created to signal to calling function that the input file is at eof + vector null; null.push_back(NULL); + in.close(); + return null; + + } + catch(exception& e) { + errorOut(e, "InputData", "getSharedRAbundVectors"); exit(1); - } + } } + /***********************************************************************/ SAbundVector* InputData::getSAbundVector(){ @@ -163,7 +479,7 @@ SAbundVector* InputData::getSAbundVector(){ if (format == "list") { input = new ListVector(fileHandle); } - else if(format == "shared") { + else if (format == "shared") { input = new SharedListVector(fileHandle); } else if(format == "rabund"){ @@ -184,17 +500,256 @@ SAbundVector* InputData::getSAbundVector(){ return sabund; } else{ - return 0; + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getSAbundVector"); + exit(1); + } +} +/***********************************************************************/ +SAbundVector* InputData::getSAbundVector(string label){ + try { + + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + if (format == "list") { + + while (in.eof() != true) { + + input = new ListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + } + else if (format == "shared") { + + while (in.eof() != true) { + + input = new SharedListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "rabund"){ + + while (in.eof() != true) { + + input = new RAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "order"){ + + while (in.eof() != true) { + + input = new OrderVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "sabund"){ + + while (in.eof() != true) { + + input = new SAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + + } + + } + + in.close(); + + sabund = new SAbundVector(); + *sabund = (input->getSAbundVector()); + + return sabund; + + } + else{ + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getSAbundVector"); + exit(1); + } +} + +/***********************************************************************/ +RAbundVector* InputData::getRAbundVector(){ + try { + if(fileHandle){ + if (format == "list") { + input = new ListVector(fileHandle); + } + else if (format == "shared") { + input = new SharedListVector(fileHandle); + } + else if(format == "rabund"){ + input = new RAbundVector(fileHandle); + } + else if(format == "order"){ + input = new OrderVector(fileHandle); + } + else if(format == "sabund"){ + input = new SAbundVector(fileHandle); + } + + gobble(fileHandle); + + rabund = new RAbundVector(); + *rabund = (input->getRAbundVector()); + + return rabund; + } + else{ + return NULL; } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "InputData", "getRAbundVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +/***********************************************************************/ +RAbundVector* InputData::getRAbundVector(string label){ + try { + + ifstream in; + string thisLabel; + openInputFile(filename, in); + + if(in){ + if (format == "list") { + + while (in.eof() != true) { + + input = new ListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + } + else if (format == "shared") { + + while (in.eof() != true) { + + input = new SharedListVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "rabund"){ + + while (in.eof() != true) { + + input = new RAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "order"){ + + while (in.eof() != true) { + + input = new OrderVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + } + + } + else if(format == "sabund"){ + + while (in.eof() != true) { + + input = new SAbundVector(in); + thisLabel = input->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete input; } + gobble(in); + + } + + } + + in.close(); + + rabund = new RAbundVector(); + *rabund = (input->getRAbundVector()); + + return rabund; + } + else{ + return NULL; + } + } + catch(exception& e) { + errorOut(e, "InputData", "getRAbundVector"); exit(1); - } + } } /***********************************************************************/ + + +