]> git.donarmstrong.com Git - mothur.git/blobdiff - inputdata.cpp
fixing minor bugs
[mothur.git] / inputdata.cpp
index 2ecebe34bd0d38ce54006c25cf4ebf4449970892..b237bb4fc55b0bacafa3815f9619f0345bd31492 100644 (file)
@@ -3,14 +3,14 @@
  *  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"
 
 /***********************************************************************/
 
@@ -24,7 +24,7 @@ InputData::InputData(string fName, string f) : format(f){
 
 
 InputData::~InputData(){
-       
+       fileHandle.close();
 //     delete output;
        
 }
@@ -33,6 +33,7 @@ InputData::~InputData(){
 
 InputData::InputData(string fName, string orderFileName, string f) : format(f){
        try {
+               
                ifstream ofHandle;
                openInputFile(orderFileName, ofHandle);
                string name;
@@ -63,7 +64,7 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){
 ListVector* InputData::getListVector(){
        try {
                if(fileHandle){
-                       if((format == "list") || (format == "shared")){
+                       if(format == "list") {
                                list = new ListVector(fileHandle);
                        }
                                        
@@ -84,6 +85,58 @@ ListVector* InputData::getListVector(){
        }       
 }
 
+/***********************************************************************/
+
+SharedListVector* InputData::getSharedListVector(){
+       try {
+               if(fileHandle){
+                       if (format == "shared")  {
+                               SharedList = new SharedListVector(fileHandle);
+                       }
+                                       
+                       gobble(fileHandle);
+                       return SharedList;
+               }
+               else{
+                       return 0;
+               }
+       }
+       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";
+               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";
+               exit(1);
+       }       
+}
+
+/***********************************************************************/
+
+SharedOrderVector* InputData::getSharedOrderVector(){
+       try {
+               if(fileHandle){
+                       if (format == "sharedfile")  {
+                               SharedOrder = new SharedOrderVector(fileHandle);
+                       }
+                               
+                       gobble(fileHandle);
+                       return SharedOrder;
+                       
+               }else{
+                       return 0;
+               }
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
 
 
 /***********************************************************************/
@@ -91,9 +144,12 @@ ListVector* InputData::getListVector(){
 OrderVector* InputData::getOrderVector(){
        try {
                if(fileHandle){
-                       if((format == "list") || (format == "shared")){
+                       if(format == "list") {
                                input = new ListVector(fileHandle);
                        }
+                       else if (format == "shared")  {
+                               input = new SharedListVector(fileHandle);
+                       }
                        else if(format == "rabund"){
                                input = new RAbundVector(fileHandle);
                        }
@@ -110,7 +166,7 @@ OrderVector* InputData::getOrderVector(){
                        gobble(fileHandle);
                        output = new OrderVector();
                        *output = (input->getOrderVector());
-                       //delete input;
+                       
                        return output;
                }
                else{
@@ -126,15 +182,52 @@ OrderVector* InputData::getOrderVector(){
                exit(1);
        }       
 }
+/***********************************************************************/
+//this is used when you don't need the order vector
+vector<SharedRAbundVector*> 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<SharedRAbundVector*> null;  null.push_back(NULL);
+               return null;
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
 
 /***********************************************************************/
 
 SAbundVector* InputData::getSAbundVector(){
        try {
                if(fileHandle){
-                       if((format == "list") || (format == "shared")){
+                       if (format == "list") {
                                input = new ListVector(fileHandle);
                        }
+                       else if (format == "shared")  {
+                               input = new SharedListVector(fileHandle);
+                       }
                        else if(format == "rabund"){
                                input = new RAbundVector(fileHandle);
                        }
@@ -167,3 +260,46 @@ SAbundVector* InputData::getSAbundVector(){
 }
 
 /***********************************************************************/
+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 getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+/***********************************************************************/
+
+
+