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