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>
64 #include <readline/readline.h>
65 #include <readline/history.h>
69 #include <conio.h> //allows unbuffered screen capture from stdin
70 #include <direct.h> //get cwd
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())
85 typedef unsigned long ull;
95 IntNode(int lv, int rv, IntNode* l, IntNode* r) : lvalue(lv), rvalue(rv), left(l), right(r) {};
105 /************************************************************/
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) {};
112 /************************************************************/
118 seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
121 /************************************************************/
122 struct distlinePair {
127 /***************************************************************/
128 struct spearmanRank {
132 spearmanRank(string n, float s) : name(n), score(s) {}
134 //********************************************************************************************************************
135 //sorts highest to lowest
136 inline bool compareSpearman(spearmanRank left, spearmanRank right){
137 return (left.score > right.score);
139 //********************************************************************************************************************
140 //sorts lowest to highest
141 inline bool compareSpearmanReverse(spearmanRank left, spearmanRank right){
142 return (left.score < right.score);
144 /************************************************************/
145 //sorts lowest to highest
146 inline bool compareDistLinePairs(distlinePair left, distlinePair right){
147 return (left.end < right.end);
149 //********************************************************************************************************************
150 //sorts lowest to highest
151 inline bool compareSequenceDistance(seqDist left, seqDist right){
152 return (left.dist < right.dist);
154 /***********************************************************************/
156 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
157 // works for now, but there should be a way to do it without killing the whole program
159 class BadConversion : public runtime_error {
161 BadConversion(const string& s) : runtime_error(s){ }
164 //**********************************************************************************************************************
166 void convert(const string& s, T& x, bool failIfLeftoverChars = true){
170 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
171 throw BadConversion(s);
175 //**********************************************************************************************************************
178 bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
182 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
190 //**********************************************************************************************************************
193 bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
197 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
204 //**********************************************************************************************************************
206 string toString(const T&x){
214 //**********************************************************************************************************************
217 string toHex(const T&x){
226 //**********************************************************************************************************************
229 string toString(const T&x, int i){
234 output << fixed << x;
239 //**********************************************************************************************************************