]> git.donarmstrong.com Git - mothur.git/blob - inputdata.cpp
fixed bug with getting sharedrabunds for venn, heatmap and tree.shared commands,...
[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 "rabundvector.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 //this is used when you don't need the order vector
187 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
188         try {
189                 if(fileHandle){
190                         if (format == "sharedfile")  {
191                                 SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
192                                 if (SharedRAbund != NULL) {
193                                         return SharedRAbund->getSharedRAbundVectors();
194                                 }
195                         }else if (format == "shared") {
196                                 SharedList = new SharedListVector(fileHandle);
197                                 if (SharedList != NULL) {
198                                         return SharedList->getSharedRAbundVector();
199                                 }
200                         }
201                         gobble(fileHandle);
202                 }
203                                 
204                 //this is created to signal to calling function that the input file is at eof
205                 vector<SharedRAbundVector*> null;  null.push_back(NULL);
206                 return null;
207                 
208         }
209         catch(exception& e) {
210                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
211                 exit(1);
212         }
213         catch(...) {
214                 cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
215                 exit(1);
216         }       
217 }
218
219
220 /***********************************************************************/
221
222 SAbundVector* InputData::getSAbundVector(){
223         try {
224                 if(fileHandle){
225                         if (format == "list") {
226                                 input = new ListVector(fileHandle);
227                         }
228                         else if (format == "shared")  {
229                                 input = new SharedListVector(fileHandle);
230                         }
231                         else if(format == "rabund"){
232                                 input = new RAbundVector(fileHandle);
233                         }
234                         else if(format == "order"){                     
235                                 input = new OrderVector(fileHandle);
236                         }
237                         else if(format == "sabund"){
238                                 input = new SAbundVector(fileHandle);
239                         }
240                                         
241                         gobble(fileHandle);
242
243                         sabund = new SAbundVector();
244                         *sabund = (input->getSAbundVector());
245
246                         return sabund;
247                 }
248                 else{
249                         return 0;
250                 }
251         }
252         catch(exception& e) {
253                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
254                 exit(1);
255         }
256         catch(...) {
257                 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
258                 exit(1);
259         }       
260 }
261
262 /***********************************************************************/
263 RAbundVector* InputData::getRAbundVector(){
264         try {
265                 if(fileHandle){
266                         if (format == "list") {
267                                 input = new ListVector(fileHandle);
268                         }
269                         else if (format == "shared")  {
270                                 input = new SharedListVector(fileHandle);
271                         }
272                         else if(format == "rabund"){
273                                 input = new RAbundVector(fileHandle);
274                         }
275                         else if(format == "order"){                     
276                                 input = new OrderVector(fileHandle);
277                         }
278                         else if(format == "sabund"){
279                                 input = new SAbundVector(fileHandle);
280                         }
281                                         
282                         gobble(fileHandle);
283
284                         rabund = new RAbundVector();
285                         *rabund = (input->getRAbundVector());
286
287                         return rabund;
288                 }
289                 else{
290                         return NULL;
291                 }
292         }
293         catch(exception& e) {
294                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
295                 exit(1);
296         }
297         catch(...) {
298                 cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
299                 exit(1);
300         }       
301 }
302 /***********************************************************************/
303
304
305