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. */
53 /***********************************************************************/
55 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
58 #include <sys/resource.h>
63 #include <readline/readline.h>
64 #include <readline/history.h>
68 #include <conio.h> //allows unbuffered screen capture from stdin
69 #include <direct.h> //get cwd
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())
84 typedef unsigned long ull;
94 IntNode(int lv, int rv, IntNode* l, IntNode* r) : lvalue(lv), rvalue(rv), left(l), right(r) {};
104 /************************************************************/
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) {};
111 /************************************************************/
117 seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
120 /************************************************************/
121 struct distlinePair {
126 /************************************************************/
127 //sorts lowest to highest
128 inline bool compareDistLinePairs(distlinePair left, distlinePair right){
129 return (left.end < right.end);
131 //********************************************************************************************************************
132 //sorts lowest to highest
133 inline bool compareSequenceDistance(seqDist left, seqDist right){
134 return (left.dist < right.dist);
136 /***********************************************************************/
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
141 class BadConversion : public runtime_error {
143 BadConversion(const string& s) : runtime_error(s){ }
146 //**********************************************************************************************************************
148 void convert(const string& s, T& x, bool failIfLeftoverChars = true){
152 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
153 throw BadConversion(s);
157 //**********************************************************************************************************************
160 bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
164 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
172 //**********************************************************************************************************************
175 bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
179 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
186 //**********************************************************************************************************************
188 string toString(const T&x){
196 //**********************************************************************************************************************
199 string toHex(const T&x){
208 //**********************************************************************************************************************
211 string toString(const T&x, int i){
216 output << fixed << x;
221 //**********************************************************************************************************************