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. */
55 /***********************************************************************/
57 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
60 #include <sys/resource.h>
61 #include <sys/types.h>
66 #include <readline/readline.h>
67 #include <readline/history.h>
71 #include <conio.h> //allows unbuffered screen capture from stdin
72 #include <direct.h> //get cwd
82 #define exp(x) (exp((double) x))
83 #define sqrt(x) (sqrt((double) x))
84 #define log10(x) (log10((double) x))
85 #define log2(x) (log10(x)/log10(2))
86 #define isnan(x) ((x) != (x))
87 #define isinf(x) (fabs(x) == std::numeric_limits<double>::infinity())
90 typedef unsigned long ull;
100 IntNode(int lv, int rv, IntNode* l, IntNode* r) : lvalue(lv), rvalue(rv), left(l), right(r) {};
115 prob = 0; reverseProb = 0;
117 diffPair(float p, float rp) {
123 /************************************************************/
127 int smallChild; //used to make linkTable work with list and rabund. represents bin number of this cluster node
128 clusterNode(int num, int par, int kid) : numSeq(num), parent(par), smallChild(kid) {};
130 /************************************************************/
136 seqDist(int s1, int s2, double d) : seq1(s1), seq2(s2), dist(d) {}
139 /************************************************************/
140 struct distlinePair {
145 /************************************************************/
146 struct seqPriorityNode {
151 seqPriorityNode(int n, string s, string nm) : numIdentical(n), seq(s), name(nm) {}
152 ~seqPriorityNode() {}
154 /***************************************************************/
155 struct spearmanRank {
159 spearmanRank(string n, float s) : name(n), score(s) {}
161 //********************************************************************************************************************
162 //sorts highest to lowest
163 inline bool compareSpearman(spearmanRank left, spearmanRank right){
164 return (left.score > right.score);
166 //********************************************************************************************************************
167 //sorts highest to lowest
168 inline bool compareSeqPriorityNodes(seqPriorityNode left, seqPriorityNode right){
169 return (left.numIdentical > right.numIdentical);
171 //********************************************************************************************************************
172 //sorts lowest to highest
173 inline bool compareSpearmanReverse(spearmanRank left, spearmanRank right){
174 return (left.score < right.score);
176 /************************************************************/
177 //sorts lowest to highest
178 inline bool compareDistLinePairs(distlinePair left, distlinePair right){
179 return (left.end < right.end);
181 //********************************************************************************************************************
182 //sorts lowest to highest
183 inline bool compareSequenceDistance(seqDist left, seqDist right){
184 return (left.dist < right.dist);
186 /***********************************************************************/
188 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
189 // works for now, but there should be a way to do it without killing the whole program
191 class BadConversion : public runtime_error {
193 BadConversion(const string& s) : runtime_error(s){ }
196 //**********************************************************************************************************************
198 void convert(const string& s, T& x, bool failIfLeftoverChars = true){
202 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
203 throw BadConversion(s);
206 //**********************************************************************************************************************
207 template <typename T> int sgn(T val){ return (val > T(0)) - (val < T(0)); }
208 //**********************************************************************************************************************
211 bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
215 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
223 //**********************************************************************************************************************
226 bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
230 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
237 //**********************************************************************************************************************
239 string toString(const T&x){
247 //**********************************************************************************************************************
250 string toHex(const T&x){
259 //**********************************************************************************************************************
262 string toString(const T&x, int i){
267 output << fixed << x;
272 //**********************************************************************************************************************
275 T fromString(const string& s){
276 istringstream stream (s);
282 //**********************************************************************************************************************