]> git.donarmstrong.com Git - mothur.git/blob - inputdata.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[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
14 /***********************************************************************/
15
16 InputData::InputData(string fName, string f) : format(f){
17         
18         openInputFile(fName, fileHandle);
19         
20 }
21
22 /***********************************************************************/
23
24
25 InputData::~InputData(){
26         
27 //      delete output;
28         
29 }
30
31 /***********************************************************************/
32
33 InputData::InputData(string fName, string orderFileName, string f) : format(f){
34         try {
35                 
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 SharedOrderVector* InputData::getSharedOrderVector(){
116         try {
117                 if(fileHandle){
118                         if (format == "sharedfile")  {
119                                 SharedOrder = new SharedOrderVector(fileHandle);
120                         }
121                                 
122                         gobble(fileHandle);
123                         return SharedOrder;
124                         
125                 }else{
126                         return 0;
127                 }
128         }
129         catch(exception& e) {
130                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131                 exit(1);
132         }
133         catch(...) {
134                 cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135                 exit(1);
136         }       
137 }
138
139
140
141 /***********************************************************************/
142
143 OrderVector* InputData::getOrderVector(){
144         try {
145                 if(fileHandle){
146                         if(format == "list") {
147                                 input = new ListVector(fileHandle);
148                         }
149                         else if (format == "shared")  {
150                                 input = new SharedListVector(fileHandle);
151                         }
152                         else if(format == "rabund"){
153                                 input = new RAbundVector(fileHandle);
154                         }
155                         else if(format == "order"){             
156                                 input = new OrderVector(fileHandle);
157                         }
158                         else if(format == "sabund"){
159                                 input = new SAbundVector(fileHandle);
160                         }
161                         else if(format == "listorder"){                                 
162                                 input = new ListVector(fileHandle); 
163                         }
164                 
165                         gobble(fileHandle);
166                         output = new OrderVector();
167                         *output = (input->getOrderVector());
168                         
169                         return output;
170                 }
171                 else{
172                         return 0;
173                 }
174         }
175         catch(exception& e) {
176                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
177                 exit(1);
178         }
179         catch(...) {
180                 cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
181                 exit(1);
182         }       
183 }
184
185 /***********************************************************************/
186
187 SAbundVector* InputData::getSAbundVector(){
188         try {
189                 if(fileHandle){
190                         if (format == "list") {
191                                 input = new ListVector(fileHandle);
192                         }
193                         else if (format == "shared")  {
194                                 input = new SharedListVector(fileHandle);
195                         }
196                         else if(format == "rabund"){
197                                 input = new RAbundVector(fileHandle);
198                         }
199                         else if(format == "order"){                     
200                                 input = new OrderVector(fileHandle);
201                         }
202                         else if(format == "sabund"){
203                                 input = new SAbundVector(fileHandle);
204                         }
205                                         
206                         gobble(fileHandle);
207
208                         sabund = new SAbundVector();
209                         *sabund = (input->getSAbundVector());
210
211                         return sabund;
212                 }
213                 else{
214                         return 0;
215                 }
216         }
217         catch(exception& e) {
218                 cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
219                 exit(1);
220         }
221         catch(...) {
222                 cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
223                 exit(1);
224         }       
225 }
226
227 /***********************************************************************/