10 * Created by Sarah Westcott on 2/19/09.
11 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
15 /* This file contains all the standard incudes we use in the project as well as some common utilities. */
54 /***********************************************************************/
56 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
59 #include <sys/resource.h>
60 #include <sys/types.h>
65 #include <readline/readline.h>
66 #include <readline/history.h>
70 #include <conio.h> //allows unbuffered screen capture from stdin
71 #include <direct.h> //get cwd
81 #define exp(x) (exp((double) x))
82 #define sqrt(x) (sqrt((double) x))
83 #define log10(x) (log10((double) x))
84 #define log2(x) (log10(x)/log10(2))
85 #define isnan(x) ((x) != (x))
86 #define isinf(x) (fabs(x) == std::numeric_limits<double>::infinity())
89 typedef unsigned long ull;
99 IntNode(int lv, int rv, IntNode* l, IntNode* r) : lvalue(lv), rvalue(rv), left(l), right(r) {};
114 prob = 0; reverseProb = 0;
116 diffPair(float p, float rp) {
122 /************************************************************/
126 int smallChild; //used to make linkTable work with list and rabund. represents bin number of this cluster node
127 clusterNode(int num, int par, int kid) : numSeq(num), parent(par), smallChild(kid) {};
129 /************************************************************/
135 seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
138 /************************************************************/
139 struct distlinePair {
144 /************************************************************/
145 struct seqPriorityNode {
150 seqPriorityNode(int n, string s, string nm) : numIdentical(n), seq(s), name(nm) {}
151 ~seqPriorityNode() {}
153 /***************************************************************/
154 struct spearmanRank {
158 spearmanRank(string n, float s) : name(n), score(s) {}
160 //********************************************************************************************************************
161 //sorts highest to lowest
162 inline bool compareSpearman(spearmanRank left, spearmanRank right){
163 return (left.score > right.score);
165 //********************************************************************************************************************
166 //sorts highest to lowest
167 inline bool compareSeqPriorityNodes(seqPriorityNode left, seqPriorityNode right){
168 return (left.numIdentical > right.numIdentical);
170 //********************************************************************************************************************
171 //sorts lowest to highest
172 inline bool compareSpearmanReverse(spearmanRank left, spearmanRank right){
173 return (left.score < right.score);
175 /************************************************************/
176 //sorts lowest to highest
177 inline bool compareDistLinePairs(distlinePair left, distlinePair right){
178 return (left.end < right.end);
180 //********************************************************************************************************************
181 //sorts lowest to highest
182 inline bool compareSequenceDistance(seqDist left, seqDist right){
183 return (left.dist < right.dist);
185 /***********************************************************************/
187 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
188 // works for now, but there should be a way to do it without killing the whole program
190 class BadConversion : public runtime_error {
192 BadConversion(const string& s) : runtime_error(s){ }
195 //**********************************************************************************************************************
197 void convert(const string& s, T& x, bool failIfLeftoverChars = true){
201 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
202 throw BadConversion(s);
205 //**********************************************************************************************************************
206 template <typename T> int sgn(T val){ return (val > T(0)) - (val < T(0)); }
207 //**********************************************************************************************************************
210 bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
214 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
222 //**********************************************************************************************************************
225 bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
229 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
236 //**********************************************************************************************************************
238 string toString(const T&x){
246 //**********************************************************************************************************************
249 string toHex(const T&x){
258 //**********************************************************************************************************************
261 string toString(const T&x, int i){
266 output << fixed << x;
271 //**********************************************************************************************************************
274 T fromString(const string& s){
275 istringstream stream (s);
281 //**********************************************************************************************************************