]> git.donarmstrong.com Git - mothur.git/blob - mothur.h
added summary file to classify.otu
[mothur.git] / mothur.h
1 #ifndef MOTHUR_H
2 #define MOTHUR_H
3
4
5
6 /*
7  *  mothur.h
8  *  Mothur
9  *
10  *  Created by Sarah Westcott on 2/19/09.
11  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12  *
13  */
14
15 /* This file contains all the standard incudes we use in the project as well as some common utilities. */
16
17 //#include <cstddef>
18
19 //io libraries
20 #include <iostream>
21 #include <iomanip>
22 #include <fstream>
23 #include <sstream>
24 #include <signal.h>
25
26
27 //exception
28 #include <stdexcept>
29 #include <exception>
30 #include <cstdlib> 
31
32
33 //containers
34 #include <vector>
35 #include <set>
36 #include <map>
37 #include <string>
38 #include <list>
39 #include <string.h>
40
41 //math
42 #include <cmath>
43 #include <math.h>
44 #include <algorithm>
45
46 //misc
47 #include <cerrno>
48 #include <ctime>
49 #include <limits>
50
51 #ifdef USE_MPI
52         #include "mpi.h"
53 #endif
54 /***********************************************************************/
55
56 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
57         #include <sys/wait.h>
58         #include <sys/time.h>
59         #include <sys/resource.h>
60         #include <sys/stat.h>
61         #include <unistd.h>
62         
63         #ifdef USE_READLINE
64                 #include <readline/readline.h>
65                 #include <readline/history.h>
66         #endif
67
68 #else
69         #include <conio.h> //allows unbuffered screen capture from stdin
70         #include <direct.h> //get cwd
71         #include <windows.h>
72         #include <psapi.h>
73
74 #endif
75
76 using namespace std;
77
78 #define exp(x) (exp((double) x))
79 #define sqrt(x) (sqrt((double) x))
80 #define log10(x) (log10((double) x))
81 #define log2(x) (log10(x)/log10(2))
82 #define isnan(x) ((x) != (x))
83 #define isinf(x) (fabs(x) == std::numeric_limits<double>::infinity())
84
85 typedef unsigned long ull;
86
87 struct IntNode {
88         int lvalue;
89         int rvalue;
90         int lcoef;
91         int rcoef;
92         IntNode* left;
93         IntNode* right;
94         
95         IntNode(int lv, int rv, IntNode* l, IntNode* r) : lvalue(lv), rvalue(rv), left(l), right(r) {};
96         IntNode() {};
97 };
98
99 struct ThreadNode {
100         int* pid;
101         IntNode* left;
102         IntNode* right;
103 };
104
105 /************************************************************/
106 struct clusterNode {
107         int numSeq;
108         int parent;
109         int smallChild; //used to make linkTable work with list and rabund. represents bin number of this cluster node
110         clusterNode(int num, int par, int kid) : numSeq(num), parent(par), smallChild(kid) {};
111 };
112 /************************************************************/
113 struct seqDist {
114         int seq1;
115         int seq2;
116         float dist;
117         seqDist() {}
118         seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
119         ~seqDist() {}
120 };
121 /************************************************************/
122 struct distlinePair {
123         int start;
124         int end;
125         
126 };
127 /************************************************************/
128 //sorts lowest to highest
129 inline bool compareDistLinePairs(distlinePair left, distlinePair right){
130         return (left.end < right.end);  
131
132 //********************************************************************************************************************
133 //sorts lowest to highest
134 inline bool compareSequenceDistance(seqDist left, seqDist right){
135         return (left.dist < right.dist);        
136
137 /***********************************************************************/
138
139 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
140 // works for now, but there should be a way to do it without killing the whole program
141
142 class BadConversion : public runtime_error {
143 public:
144         BadConversion(const string& s) : runtime_error(s){ }
145 };
146
147 //**********************************************************************************************************************
148 template<typename T>
149 void convert(const string& s, T& x, bool failIfLeftoverChars = true){
150         
151                 istringstream i(s);
152                 char c;
153                 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
154                         throw BadConversion(s);
155         
156 }
157
158 //**********************************************************************************************************************
159
160 template<typename T>
161 bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
162         
163                 istringstream i(s);
164                 char c;
165                 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
166                 {
167                         return false;
168                 } 
169                 return true;
170         
171 }
172
173 //**********************************************************************************************************************
174
175 template<typename T>
176 bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
177         
178                 istringstream i(s);
179                 char c;
180                 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
181                 {
182                         return false;
183                 } 
184                 return true;
185         
186 }
187 //**********************************************************************************************************************
188 template<typename T>
189 string toString(const T&x){
190         
191                 stringstream output;
192                 output << x;
193                 return output.str();
194         
195 }
196
197 //**********************************************************************************************************************
198
199 template<typename T>
200 string toHex(const T&x){
201         
202                 stringstream output;
203                 
204                 output << hex << x;
205
206                 return output.str();
207         
208 }
209 //**********************************************************************************************************************
210
211 template<typename T>
212 string toString(const T&x, int i){
213         
214                 stringstream output;
215                 
216                 output.precision(i);
217                 output << fixed << x;
218                 
219                 return output.str();
220         
221 }
222 //**********************************************************************************************************************
223
224 #endif
225