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
79 #define exp(x) (exp((double) x))
80 #define sqrt(x) (sqrt((double) x))
81 #define log10(x) (log10((double) x))
82 #define log2(x) (log10(x)/log10(2))
83 #define isnan(x) ((x) != (x))
84 #define isinf(x) (fabs(x) == std::numeric_limits<double>::infinity())
86 typedef unsigned long ull;
96 IntNode(int lv, int rv, IntNode* l, IntNode* r) : lvalue(lv), rvalue(rv), left(l), right(r) {};
106 /************************************************************/
110 int smallChild; //used to make linkTable work with list and rabund. represents bin number of this cluster node
111 clusterNode(int num, int par, int kid) : numSeq(num), parent(par), smallChild(kid) {};
113 /************************************************************/
119 seqDist(int s1, int s2, float d) : seq1(s1), seq2(s2), dist(d) {}
122 /************************************************************/
123 struct distlinePair {
128 /***************************************************************/
129 struct spearmanRank {
133 spearmanRank(string n, float s) : name(n), score(s) {}
135 //********************************************************************************************************************
136 //sorts highest to lowest
137 inline bool compareSpearman(spearmanRank left, spearmanRank right){
138 return (left.score > right.score);
140 //********************************************************************************************************************
141 //sorts lowest to highest
142 inline bool compareSpearmanReverse(spearmanRank left, spearmanRank right){
143 return (left.score < right.score);
145 /************************************************************/
146 //sorts lowest to highest
147 inline bool compareDistLinePairs(distlinePair left, distlinePair right){
148 return (left.end < right.end);
150 //********************************************************************************************************************
151 //sorts lowest to highest
152 inline bool compareSequenceDistance(seqDist left, seqDist right){
153 return (left.dist < right.dist);
155 /***********************************************************************/
157 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
158 // works for now, but there should be a way to do it without killing the whole program
160 class BadConversion : public runtime_error {
162 BadConversion(const string& s) : runtime_error(s){ }
165 //**********************************************************************************************************************
167 void convert(const string& s, T& x, bool failIfLeftoverChars = true){
171 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
172 throw BadConversion(s);
176 //**********************************************************************************************************************
179 bool convertTestFloat(const string& s, T& x, bool failIfLeftoverChars = true){
183 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
191 //**********************************************************************************************************************
194 bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
198 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
205 //**********************************************************************************************************************
207 string toString(const T&x){
215 //**********************************************************************************************************************
218 string toHex(const T&x){
227 //**********************************************************************************************************************
230 string toString(const T&x, int i){
235 output << fixed << x;
240 //**********************************************************************************************************************