]> git.donarmstrong.com Git - mothur.git/blob - inputdata.cpp
fixed memory leak in parsimony calculator and added progress bars to parsimony and...
[mothur.git] / inputdata.cpp
1 /*
2  *  inputdata.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 11/18/08.
6  *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "inputdata.h"
11 #include "ordervector.hpp"
12 #include "listvector.hpp"
13 #include "utilities.hpp"
14
15 /***********************************************************************/
16
17 InputData::InputData(string fName, string f) : format(f){
18         
19         openInputFile(fName, fileHandle);
20         
21 }
22
23 /***********************************************************************/
24
25
26 InputData::~InputData(){
27         
28 //      delete output;
29         
30 }
31
32 /***********************************************************************/
33
34 InputData::InputData(string fName, string orderFileName, string f) : format(f){
35         try {
36                 
37                 ifstream ofHandle;
38                 openInputFile(orderFileName, ofHandle);
39                 string name;
40
41                 int count = 0;
42         
43                 while(ofHandle){
44                         ofHandle >> name;
45                         orderMap[name] = count;
46                         count++;
47                         gobble(ofHandle);
48                 }
49                 ofHandle.close();
50         
51                 openInputFile(fName, fileHandle);
52         }
53         catch(exception& e) {
54                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. 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 InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59                 exit(1);
60         }       
61 }
62 /***********************************************************************/
63
64 ListVector* InputData::getListVector(){
65         try {
66                 if(fileHandle){
67                         if(format == "list") {
68                                 list = new ListVector(fileHandle);
69                         }
70                                         
71                         gobble(fileHandle);
72                         return list;
73                 }
74                 else{
75                         return 0;
76                 }
77         }
78         catch(exception& e) {
79                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
80                 exit(1);
81         }
82         catch(...) {
83                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
84                 exit(1);
85         }       
86 }
87
88 /***********************************************************************/
89
90 SharedListVector* InputData::getSharedListVector(){
91         try {
92                 if(fileHandle){
93                         if (format == "shared")  {
94                                 SharedList = new SharedListVector(fileHandle);
95                         }
96                                         
97                         gobble(fileHandle);
98                         return SharedList;
99                 }
100                 else{
101                         return 0;
102                 }
103         }
104         catch(exception& e) {
105                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106                 exit(1);
107         }
108         catch(...) {
109                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110                 exit(1);
111         }       
112 }
113
114 /***********************************************************************/
115
116 SharedOrderVector* InputData::getSharedOrderVector(){
117         try {
118                 if(fileHandle){
119                         if (format == "sharedfile")  {
120                                 SharedOrder = new SharedOrderVector(fileHandle);
121                         }
122                                 
123                         gobble(fileHandle);
124                         return SharedOrder;
125                         
126                 }else{
127                         return 0;
128                 }
129         }
130         catch(exception& e) {
131                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132                 exit(1);
133         }
134         catch(...) {
135                 cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
136                 exit(1);
137         }       
138 }
139
140
141
142 /***********************************************************************/
143
144 OrderVector* InputData::getOrderVector(){
145         try {
146                 if(fileHandle){
147                         if(format == "list") {
148                                 input = new ListVector(fileHandle);
149                         }
150                         else if (format == "shared")  {
151                                 input = new SharedListVector(fileHandle);
152                         }
153                         else if(format == "rabund"){
154                                 input = new RAbundVector(fileHandle);
155                         }
156                         else if(format == "order"){             
157                                 input = new OrderVector(fileHandle);
158                         }
159                         else if(format == "sabund"){
160                                 input = new SAbundVector(fileHandle);
161                         }
162                         else if(format == "listorder"){                                 
163                                 input = new ListVector(fileHandle); 
164                         }
165                 
166                         gobble(fileHandle);
167                         output = new OrderVector();
168                         *output = (input->getOrderVector());
169                         
170                         return output;
171                 }
172                 else{
173                         return 0;
174                 }
175         }
176         catch(exception& e) {
177                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
178                 exit(1);
179         }
180         catch(...) {
181                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182                 exit(1);
183         }       
184 }
185
186 /***********************************************************************/
187
188 SAbundVector* InputData::getSAbundVector(){
189         try {
190                 if(fileHandle){
191                         if (format == "list") {
192                                 input = new ListVector(fileHandle);
193                         }
194                         else if (format == "shared")  {
195                                 input = new SharedListVector(fileHandle);
196                         }
197                         else if(format == "rabund"){
198                                 input = new RAbundVector(fileHandle);
199                         }
200                         else if(format == "order"){                     
201                                 input = new OrderVector(fileHandle);
202                         }
203                         else if(format == "sabund"){
204                                 input = new SAbundVector(fileHandle);
205                         }
206                                         
207                         gobble(fileHandle);
208
209                         sabund = new SAbundVector();
210                         *sabund = (input->getSAbundVector());
211
212                         return sabund;
213                 }
214                 else{
215                         return 0;
216                 }
217         }
218         catch(exception& e) {
219                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
220                 exit(1);
221         }
222         catch(...) {
223                 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
224                 exit(1);
225         }       
226 }
227
228 /***********************************************************************/