]> git.donarmstrong.com Git - mothur.git/blob - inputdata.cpp
finishing the container classes, combining read.otu and read.list commands. some...
[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") {
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 SharedListVector* InputData::getSharedListVector(){
90         try {
91                 if(fileHandle){
92                         if (format == "shared"){
93                                 SharedList = new SharedListVector(fileHandle);
94                         }
95                                         
96                         gobble(fileHandle);
97                         return SharedList;
98                 }
99                 else{
100                         return 0;
101                 }
102         }
103         catch(exception& e) {
104                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
105                 exit(1);
106         }
107         catch(...) {
108                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
109                 exit(1);
110         }       
111 }
112
113
114 /***********************************************************************/
115
116 OrderVector* InputData::getOrderVector(){
117         try {
118                 if(fileHandle){
119                         if(format == "list") {
120                                 input = new ListVector(fileHandle);
121                         }
122                         else if(format == "shared") {
123                                 input = new SharedListVector(fileHandle);
124                         }
125                         else if(format == "rabund"){
126                                 input = new RAbundVector(fileHandle);
127                         }
128                         else if(format == "order"){             
129                                 input = new OrderVector(fileHandle);
130                         }
131                         else if(format == "sabund"){
132                                 input = new SAbundVector(fileHandle);
133                         }
134                         else if(format == "listorder"){                                 
135                                 input = new ListVector(fileHandle); 
136                         }
137                 
138                         gobble(fileHandle);
139                         output = new OrderVector();
140                         *output = (input->getOrderVector());
141                         //delete input;
142                         return output;
143                 }
144                 else{
145                         return 0;
146                 }
147         }
148         catch(exception& e) {
149                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
150                 exit(1);
151         }
152         catch(...) {
153                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
154                 exit(1);
155         }       
156 }
157
158 /***********************************************************************/
159
160 SAbundVector* InputData::getSAbundVector(){
161         try {
162                 if(fileHandle){
163                         if (format == "list") {
164                                 input = new ListVector(fileHandle);
165                         }
166                         else if(format == "shared") {
167                                 input = new SharedListVector(fileHandle);
168                         }
169                         else if(format == "rabund"){
170                                 input = new RAbundVector(fileHandle);
171                         }
172                         else if(format == "order"){                     
173                                 input = new OrderVector(fileHandle);
174                         }
175                         else if(format == "sabund"){
176                                 input = new SAbundVector(fileHandle);
177                         }
178                                         
179                         gobble(fileHandle);
180
181                         sabund = new SAbundVector();
182                         *sabund = (input->getSAbundVector());
183
184                         return sabund;
185                 }
186                 else{
187                         return 0;
188                 }
189         }
190         catch(exception& e) {
191                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
192                 exit(1);
193         }
194         catch(...) {
195                 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
196                 exit(1);
197         }       
198 }
199
200 /***********************************************************************/