]> git.donarmstrong.com Git - mothur.git/blob - readotu.cpp
fixed phylo.diversity
[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         m = MothurOut::getInstance();
16         //m->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
24                 if (globaldata->getOrderFile() == "") {
25                         //you have two inputs because in the next if statement if you only have one then it moves ahead in the same file.  
26                         //So when you run the collect or summary commands you miss a line.
27                         input = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
28                         inputList = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund.
29                         inputSabund = new InputData(philFile, globaldata->getFormat()); //format tells you whether philFile is list, rabund, sabund or shared.
30                         inputRabund = new InputData(philFile, globaldata->getFormat());
31                 }else {//there is an orderfile
32                         input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat());
33                 }
34         
35                 //memory leak prevention
36                 //if (globaldata->ginput != NULL) { delete globaldata->ginput;  }
37                 globaldata->ginput = input;     //saving to be used by collector and rarefact commands.
38
39                 if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
40
41 //cout << input << '\t' << globaldata << endl;
42                         order = input->getOrderVector();
43                         //memory leak prevention
44
45                         //if (globaldata->gorder != NULL) { delete globaldata->gorder;  }
46                         globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
47                         sabund = inputSabund->getSAbundVector(); 
48                         //if (globaldata->sabund != NULL) { delete globaldata->sabund;  }
49                         globaldata->sabund = sabund; //saving to be used by summary command.
50                         delete inputSabund;
51
52                         rabund = inputRabund->getRAbundVector(); 
53                         //if (globaldata->rabund != NULL) { delete globaldata->rabund;  }
54                         globaldata->rabund = rabund; //saving to be used by heatmap.bin command.
55                         delete inputRabund;
56
57                         list = inputList->getListVector();
58                         //if (globaldata->gListVector != NULL) { delete globaldata->gListVector;  }
59                         globaldata->gListVector = list;
60                         delete inputList;
61
62                 }else if (globaldata->getFormat() == "shared") {
63                         SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands.
64                         //memory leak prevention
65                         //if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList;  }
66                         globaldata->gSharedList = SharedList;
67                         delete inputSabund;
68                         delete inputRabund;
69                         delete inputList;
70                 }
71         }
72         catch(exception& e) {
73                 m->errorOut(e, "ReadOTUFile", "read");
74                 exit(1);
75         }
76 }
77
78 /***********************************************************************/
79
80 ReadOTUFile::~ReadOTUFile(){
81 //      delete input;
82 //      delete order;
83 }
84
85 /***********************************************************************/
86