]> git.donarmstrong.com Git - mothur.git/blob - inputdata.cpp
Initial revision
[mothur.git] / inputdata.cpp
1 /*
2  *  inputdata.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 11/18/08.
6  *  Copyright 2008 __MyCompanyName__. 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                 ifstream ofHandle;
37                 openInputFile(orderFileName, ofHandle);
38                 string name;
39
40                 int count = 0;
41         
42                 while(ofHandle){
43                         ofHandle >> name;
44                         orderMap[name] = count;
45                         count++;
46                         gobble(ofHandle);
47                 }
48                 ofHandle.close();
49         
50                 openInputFile(fName, fileHandle);
51         }
52         catch(exception& e) {
53                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54                 exit(1);
55         }
56         catch(...) {
57                 cout << "An unknown error has occurred in the InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58                 exit(1);
59         }       
60 }
61 /***********************************************************************/
62
63 ListVector* InputData::getListVector(){
64         try {
65                 if(fileHandle){
66                         if((format == "list") || (format == "shared")){
67                                 list = new ListVector(fileHandle);
68                         }
69                                         
70                         gobble(fileHandle);
71                         return list;
72                 }
73                 else{
74                         return 0;
75                 }
76         }
77         catch(exception& e) {
78                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
79                 exit(1);
80         }
81         catch(...) {
82                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
83                 exit(1);
84         }       
85 }
86
87
88
89 /***********************************************************************/
90
91 OrderVector* InputData::getOrderVector(){
92         try {
93                 if(fileHandle){
94                         if((format == "list") || (format == "shared")){
95                                 input = new ListVector(fileHandle);
96                         }
97                         else if(format == "rabund"){
98                                 input = new RAbundVector(fileHandle);
99                         }
100                         else if(format == "order"){             
101                                 input = new OrderVector(fileHandle);
102                         }
103                         else if(format == "sabund"){
104                                 input = new SAbundVector(fileHandle);
105                         }
106                         else if(format == "listorder"){                                 
107                                 input = new ListVector(fileHandle); 
108                         }
109                 
110                         gobble(fileHandle);
111                         output = new OrderVector();
112                         *output = (input->getOrderVector());
113                         //delete input;
114                         return output;
115                 }
116                 else{
117                         return 0;
118                 }
119         }
120         catch(exception& e) {
121                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122                 exit(1);
123         }
124         catch(...) {
125                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126                 exit(1);
127         }       
128 }
129
130 /***********************************************************************/
131
132 SAbundVector* InputData::getSAbundVector(){
133         try {
134                 if(fileHandle){
135                         if((format == "list") || (format == "shared")){
136                                 input = new ListVector(fileHandle);
137                         }
138                         else if(format == "rabund"){
139                                 input = new RAbundVector(fileHandle);
140                         }
141                         else if(format == "order"){                     
142                                 input = new OrderVector(fileHandle);
143                         }
144                         else if(format == "sabund"){
145                                 input = new SAbundVector(fileHandle);
146                         }
147                                         
148                         gobble(fileHandle);
149
150                         sabund = new SAbundVector();
151                         *sabund = (input->getSAbundVector());
152
153                         return sabund;
154                 }
155                 else{
156                         return 0;
157                 }
158         }
159         catch(exception& e) {
160                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
161                 exit(1);
162         }
163         catch(...) {
164                 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165                 exit(1);
166         }       
167 }
168
169 /***********************************************************************/