Simulating Mating Alliances as a Reproductive Tactic for Populations
 All Classes Functions Variables Friends
utils.h
1 #ifndef DEF_UTIL
2 #define DEF_UTIL
3 #include <iostream>
4 #include <stdio.h>
5 #include <string>
6 #include <vector>
7 #include <fstream>
8 #include "boost/random/binomial_distribution.hpp"
9 #include "boost/random/poisson_distribution.hpp"
10 #include "boost/random/variate_generator.hpp"
11 #include "boost/random/mersenne_twister.hpp"
12 #include <sstream>
13 #include <climits>
14 
15 // Try to sniff out whether or not a long is 64 bits, or 32. This is needed to decide whether to apply a "ULL" or "UL" suffix to 64-bit numeric literals.
16 //#ifdef __SIZEOF_LONG__
18 //#if __SIZEOF_LONG__ == 8
19 //#define LONG_IS_64_BITS
20 //#endif
21 //#endif
22 #if ULONG_MAX > 0xFFFFFFFFUL
23 #define LONG_IS_64_BITS
24 #endif
25 
26 // If compiling with g++ on a 32-bit machine, g++ demands that 64-bit unsigned constants have a special "ULL" ("unsigned long long") suffix.
27 // (Hopefully this nonstandard suffix works on other compilers.) But if we're compiling on a 64-bit machine, these constants need only a "UL" suffix.
28 // This macro attempts to figure out the right suffix, and glue it on. LONG_IS_64_BITS needs to be
29 // either set by the user or guessed from other predefined constants.
30 #ifdef LONG_IS_64_BITS
31 #define U64(x) x##UL
32 #else
33 #define U64(x) x##ULL
34 #endif
35 
36 #if defined(_MSC_VER) || defined(__BORLANDC__) // windobe version 64bits int
37 typedef unsigned __int64 ulong64;
38 typedef signed __int64 long64;
39 #define CRUMB 32 // number of base that can be coded in a number, 64 for uint128, 32 for ulong64
40 #define typeDNA __ulong64
41 #else //linux version 128 bits int
42 typedef unsigned long long ulong64;
43 typedef signed long long long64;
44 #define CRUMB 32 // number of base that can be coded in a number, 64 for uint128, 32 for ulong64
45 #define typeDNA ulong64
46 
47 #endif
48 
49 #define rand2 (int)((rand()/((double)RAND_MAX+1)*2))
50 
51 int rBinom(int, double );
52 int rPoisson(double);
53 int * poisson_array(int N,double lambda);
54 int myrand(int);
55 int logrand(int);
56 ptrdiff_t myrand(ptrdiff_t);
57 int dist_dna(int, int);
58 unsigned long long int dist_dna(unsigned long long int, unsigned long long int);
59 unsigned long long convertDnaToInt(std::string dna);
60 std::vector<unsigned long long> convertDnaToIntSplit(std::string dna);
61 #ifdef HAS_UINT128
62 __uint128_t dist_dna(__uint128_t a, __uint128_t b);// NOT WORKING
63 #endif // HAS_UINT128
64 double harmonic(int n);
65 int * poisson_array_smart(int Nparents, int Nchildren);
66 char convertToChar(unsigned number);
67 std::string convertIntToQuaternaryString(typeDNA dna,int nbcrumb = CRUMB);
68 double tajima_a1(int n); // warning in tajima D computaion call with n-1
69 double tajima_a2(int n); // warning in tajima D computaion call with n-1
70 double tajima_b1(int n);
71 double tajima_b2(int n);
72 double tajima_c1(int n);
73 double tajima_c2(int n);
74 unsigned long long dna_distance(unsigned long long c);
75 std::vector<std::string> split_string(std::string tosplit,std::string sep);
76 std::vector<typeDNA> dna_string_to_int(std::string);
77 double harm_square(int i);
78 std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
79 std::vector<std::string> split(const std::string &s, char delim);
80 bool isFloat(std::string myString);
81 bool isInt(std::string myString);
82 
83 template <class T>
84 inline std::string to_string (const T& t)
85 {
86 std::stringstream ss;
87 ss << t;
88 return ss.str();
89 }
90 
91 template<class T >
92 std::string convertToStr(T number)
93 {
94  switch(number){
95  case(0):
96  return "A";
97  case(1):
98  return "G";
99  case(2):
100  return "C";
101  case(3):
102  return "T";
103  default:
104  return "-";
105  }
106 }
107 
108 template<class T >
109 int convertToInt(T letter)
110 {
111  switch(letter){
112  case('A'):
113  return 0;
114  case('G'):
115  return 1;
116  case('C'):
117  return 2;
118  case('T'):
119  return 3;
120  default:
121  return 0;
122  }
123 }
124 
125 
126 
127 
128 #endif

Home