]> git.donarmstrong.com Git - mothur.git/blob - readotu.cpp
0bcfd320cade47901ac89cbf9e86c7b8ad142b29
[mothur.git] / readotu.cpp
1 /*
2  *  readotu.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 4/21/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "readotu.h"
11
12 /***********************************************************************/
13
14 ReadOTUFile::ReadOTUFile(string pf): philFile(pf){
15         
16         openInputFile(philFile, fileHandle);
17 }
18
19 /***********************************************************************/
20 //This function reads the list, rabund or sabund files to be used by collect and rarefact command.
21 void ReadOTUFile::read(GlobalData* globaldata){
22         try {
23                 if (globaldata->getOrderFile() == "") {
24                         //you have two inputs because in the next if statement if you only have one then it moves ahead in the same file.  
25                         //So when you run the collect or summary commands you miss a line.
26                         input = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
27                         inputList = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
28                         inputSabund = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund or shared.
29                 }else {//there is an orderfile
30                         input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat());
31                 }
32                 
33                 //memory leak prevention
34                 //if (globaldata->ginput != NULL) { delete globaldata->ginput;  }
35                 globaldata->ginput = input;     //saving to be used by collector and rarefact commands.
36                 
37                 if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
38                         order = input->getOrderVector();
39                         //memory leak prevention
40                         //if (globaldata->gorder != NULL) { delete globaldata->gorder;  }
41                         globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
42                         sabund = inputSabund->getSAbundVector(); 
43                         globaldata->sabund = sabund; //saving to be used by summary command.
44                         list = inputList->getListVector();
45                         globaldata->gListVector = list;
46                 }else if (globaldata->getFormat() == "shared") {
47                         SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands.
48                         //memory leak prevention
49                         //if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList;  }
50                         globaldata->gSharedList = SharedList;
51                 }
52         }
53         catch(exception& e) {
54                 cout << "Standard Error: " << e.what() << " has occurred in the ReadOTUFile class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55                 exit(1);
56         }
57         catch(...) {
58                 cout << "An unknown error has occurred in the ReadOTUFile class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59                 exit(1);
60         }
61 }
62
63 /***********************************************************************/
64
65 ReadOTUFile::~ReadOTUFile(){
66 //      delete input;
67 //      delete order;
68 }
69
70 /***********************************************************************/
71